Ship-Editor, failing to read out ds_list

I

iMilchshake

Guest
Hey :)!
So im currently programming a roguelike top-down space-shooter where you should be able to build your Ship by yourself. But something 💩💩💩💩s up at placing the blocks at the right location.

GIF:
https://gyazo.com/992827aa832d7081533dbd0ceade7819

Here's my code:

Create event (just for testing, later on the arrays will be written with informations automatically)
Code:
cockpit=instance_create(x,y,basicCP) //Cockpit Object
cockpit_x=0; //Cockpit offset
cockpit_y=0;
blocks = ds_list_create();
block_x = ds_list_create();
block_y = ds_list_create();

ds_list_insert(blocks,0,instance_create(x,y,armor))
ds_list_insert(block_x,0,0)
ds_list_insert(block_y,0,64)
ds_list_insert(blocks,1,instance_create(x,y,armor))
ds_list_insert(block_x,1,-32)
ds_list_insert(block_y,1,0)
ds_list_insert(blocks,2,instance_create(x,y,armor))
ds_list_insert(block_x,2,32)
ds_list_insert(block_y,2,0)
ds_list_insert(blocks,3,instance_create(x,y,armor))
ds_list_insert(block_x,3,32)
ds_list_insert(block_y,3,-32)
ds_list_insert(blocks,4,instance_create(x,y,armor))
ds_list_insert(block_x,4,-32)
ds_list_insert(block_y,4,-32)
so basically each block has one entry in each ds_list.
"block" is for saving their id's
block_x is for saving their x_offset
block_y is for saving their y_offset

now reading out goes as following:
Code:
dir=point_direction(x,y,mouse_x,mouse_y)
for (var a=0;a<ds_list_size(blocks);a+=1)
{
current_obj=ds_list_find_value(blocks,a)
current_obj.x=x+lengthdir_x(ds_list_find_value(block_x,a),dir)
current_obj.y=y+lengthdir_y(ds_list_find_value(block_y,a),dir)
current_obj.image_angle=dir
}

//Code for cockpit is basically the same
Where is my mistake? why are the blocks acting so weird? o_O
 

kamiyasi

Member
Why are you using lengthdir_x and lengthdir_y? I'm not sure how you're planning on the ship building setup translating to the final output positions, but it seems to me like using lengthdir wouldn't place the objects in places where you'd want them to be as the way you have it, they'd just be scattered about radially from their starting position, facing towards the mouse, not from their own origins but from the origin of the object that is positioning the current_objs.
 
Z

zircher

Guest
Give each block a different color and it might help you to analyze the problem better.
 
I

iMilchshake

Guest
but it seems to me like using lengthdir wouldn't place the objects in places where you'd want them to be as the way you have it.
Thx, you got me thinking :D! so basicly i had the idea to first calculate the y-offset and afterwards the x-offset(from the position already changed by the y-offset).
Looks like this now:
Code:
for (var a=0;a<ds_list_size(blocks);a+=1)
{
current_obj=ds_list_find_value(blocks,a)
safe_xpos=x+lengthdir_x(ds_list_find_value(block_y,a),dir)
safe_ypos=y+lengthdir_y(ds_list_find_value(block_y,a),dir)
current_obj.x=safe_xpos+lengthdir_x(ds_list_find_value(block_x,a),dir+90)
current_obj.y=safe_ypos+lengthdir_y(ds_list_find_value(block_x,a),dir+90)
current_obj.image_angle=dir
}
 
Top