hogwater
Member
Topic. Here I'm checking a ds_list to see if it contains an object. I'm only using a list because I don't know how to do this with an array.
Step:
How can I do this with an array instead?
Also, this code is working just great, but if anyone has a way to simplify it I'm all ears. This code goes in a "thrown sword" object, and when it hits a wall it destroys itself and creates a sword platform. It positions itself differently depending on if it hits a "topper" collision object or not.
Step:
Code:
//if we hit a wall
var block_hit = instance_place(x + hspd,y,obj_collision_solid_parent);
if (block_hit) && (can_do)
{
while (!place_meeting(x + 1,y,block_hit))
{
x += sign(hspd);
}
hspd = 0;
//create sword platform
var temp_offset = 50; //remove this once final sprites are made at proper size
var is_topper = ds_list_find_index(global.collision_toppers,block_hit.object_index)
if (global.sword_stuck_facing_right) && (is_topper != -1)
{
var sword_plat = instance_create_layer(block_hit.bbox_left-sprite_xoffset+temp_offset,block_hit.bbox_top,"player",obj_harry_sword_stuck);
}
else if (!global.sword_stuck_facing_right) && (is_topper != -1)
{
var sword_plat = instance_create_layer(block_hit.bbox_right-sprite_xoffset-temp_offset,block_hit.bbox_top,"player",obj_harry_sword_stuck);
}
else if (global.sword_stuck_facing_right) && (is_topper == -1)
{
var sword_plat = instance_create_layer(block_hit.bbox_left-sprite_xoffset+temp_offset,y,"player",obj_harry_sword_stuck);
}
else if (!global.sword_stuck_facing_right) && (is_topper == -1)
{
var sword_plat = instance_create_layer(block_hit.bbox_right-sprite_xoffset-temp_offset,y,"player",obj_harry_sword_stuck);
}
Also, this code is working just great, but if anyone has a way to simplify it I'm all ears. This code goes in a "thrown sword" object, and when it hits a wall it destroys itself and creates a sword platform. It positions itself differently depending on if it hits a "topper" collision object or not.