Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// spawn_unit(unit_ID, side)
- /* This script acts as a CENTRALIZED method to spawn units.
- The first number spawns a different unit type based on the number
- 0 = Soldier
- 1 = Militia
- 2
- 3
- 4
- ...
- The second number defines what side it's on.
- 0 = player side (bottom)
- 1 = enemy side (top)
- */
- var unit_ID = argument0;
- var side = argument1;
- var unit_type;
- // Get the type of unit to be spawned
- switch(unit_ID)
- {
- case 0: unit_type = obj_soldier; break;
- //case 1: unit_type = obj_militia; break;
- //case 2: unit_type = obj_cooldude; break;
- //case 3: unit_type = ...
- default: game_error("Spawned a unit with an ID that doesn't exist (" + string(unit_ID) + ")");
- }
- // Get the position that he's spawned at
- var X, Y;
- if(side == 0 || side == 1)
- {
- var buffer = 50; // Just an arbitrary number to keep the units from spawning on the edge of the room.
- X = random(room_width - (buffer*2)) + buffer;
- if(side == 0){Y = room_height + 32};
- if(side == 1){Y = 0 - 32};
- }
- else
- game_error("Spawned a unit to an invalid side (" + string(side) + ")");
- // Now spawn the unit
- var unit = instance_create(X, Y, unit_type);
- unit.team = side;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement