Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @description scr_spawn_ship(x, y, blueprint, ship sprite)
- /// @param x
- /// @param y
- /// @param blueprint
- /// @param ship sprite
- //
- // Spawn ai controlled ship
- // this code doesn't allow for components to be customized
- // this code doesn't allow for home angle, max angle, current angle
- // the loop in this code only dynamically accounts for array length, not height
- //
- // x x-position to spawn ship center at
- // y y-position to spawn ship center at
- // blueprint blueprint to spawn
- // ss what sprite should be assigned to obj_ship
- //
- var xp, yp, bp, ss, n, m;
- xp = argument0; // x position to spawn at
- yp = argument1; // y position to spawn at
- bp = argument2; // blueprint to spawn
- ss = argument3; // ship sprite
- n = 0;
- m = 0;
- // inst will change for each iteration through blueprint
- var inst = noone;
- // ship is the first thing that will be spawned at n = 0
- owner = noone;
- // iterate through ship blueprint
- for (n = 0; n < array_height_2d(bp); n++) {
- inst = instance_create( xp + bp[n, BP_X_OFFSET], yp + bp[n, BP_Y_OFFSET], bp[n, BP_OBJECT] );
- // this is not a temp val as with statement must call it
- side = bp[n, BP_PLACEMENT];
- // get z axis location for component
- inst.z = bp[n, BP_Z];
- inst.depth = (-1) * inst.z;
- // owner not set yet
- if (owner == noone) {
- // assign obj_ship as owner for other components
- owner = inst;
- // set ship sprite to provided sprite
- inst.sprite_index = ss;
- // set x and y location for spawn
- xp = owner.x;
- yp = owner.y;
- }
- // with the spawned object
- with (inst) {
- // assign component owner
- owner = other.owner;
- // if buildable is a gun then add to the ship gun array
- // all ship components have a key set in their create event
- if (string_pos("gun", key)) {
- with(owner) {
- // inform gun about what number it is
- other.gun_number = gun_count;
- // add this gun to ships list of gun ids
- gun_array[gun_count] = other.id;
- // replace this with array_length at some point
- gun_count += 1;
- // assign gun it's slot location
- side = other.side;
- }
- // this will init. home / current / max angles, requires side to be set
- scr_weapon_angle_setup(side);
- // if buildable is an engine
- } else if (string_pos("engine", key)) {
- with(owner) {
- // inform engine about what number it is
- other.engine_number = engine_count;
- // add this engine to ships list of engine ids
- engine_array[engine_count] = other.id;
- // replace this with array_length at some point
- engine_count += 1;
- }
- }
- // set instances offset from center of ship
- X_offset = x - owner.x;
- Y_offset = y - owner.y;
- // create physics fixture if object is a component not base ship
- // consider changing this to just check for n > 1
- if !(string_pos("obj_ship", key)) scr_add_fixture(1, owner);
- }
- show_debug_message(object_get_name(inst.object_index) + " created with owner " + object_get_name(inst.owner.object_index) + " " + string(inst.owner));
- }
- return owner;
Add Comment
Please, Sign In to add comment