Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// spawn_unit(unit_ID, side)
  2.  
  3. /*  This script acts as a CENTRALIZED method to spawn units.
  4.     The first number spawns a different unit type based on the number
  5.     0 = Soldier
  6.     1 = Militia
  7.     2
  8.     3
  9.     4
  10.     ...
  11.    
  12.     The second number defines what side it's on.
  13.     0 = player side (bottom)
  14.     1 = enemy side (top)
  15. */
  16.  
  17. var unit_ID = argument0;
  18. var side = argument1;
  19. var unit_type;
  20.  
  21. // Get the type of unit to be spawned
  22. switch(unit_ID)
  23. {
  24.   case 0: unit_type = obj_soldier; break;
  25.   //case 1: unit_type = obj_militia; break;
  26.   //case 2: unit_type = obj_cooldude; break;
  27.   //case 3: unit_type = ...
  28.  
  29.   default: game_error("Spawned a unit with an ID that doesn't exist (" + string(unit_ID) + ")");
  30. }
  31.  
  32. // Get the position that he's spawned at
  33. var X, Y;
  34. if(side == 0 || side == 1)
  35. {
  36.   var buffer = 50; // Just an arbitrary number to keep the units from spawning on the edge of the room.
  37.   X = random(room_width - (buffer*2)) + buffer;
  38.  
  39.   if(side == 0){Y = room_height + 32};
  40.   if(side == 1){Y = 0 - 32};
  41. }
  42. else
  43.   game_error("Spawned a unit to an invalid side (" + string(side) + ")");
  44.  
  45. // Now spawn the unit
  46. var unit = instance_create(X, Y, unit_type);
  47. unit.team = side;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement