Turrets with tanks
Ever had trouble with tank games because they won't let there barrels spin??? well here is a code to make it work.
[code]obj=controller event=create
global.ta=ds_list_create()//Creates a list which will hold all the ID's
//of every tank so the turrets can identify which is theirs.
[/code]
[code]obj=tank's base event=create
ds_list_add(global.ta,id)//This adds the tanks unique ID to the list
position=ds_list_find_index(global.ta,id)//This gets the tank's position in
//that list.
turret=instance_create(x,y,Turret)//This code creates the turret and and gives
//us IT'S unique ID.
turret.owner=ds_list_find_value(global.ta,position)//This tells the unique
//turret that was just made
//exactly which tank
//created it.
[/code]
[code]obj=Tank event=step
image_angle=direction
[/code]
[code]obj=Turret event=step
x=owner.x //This tells the turret to be exactly where it's tank is.
y=owner.y
image_angle=direction//for appearance.
direction=point_direction(x,y,mouse_x,mouse_y)//again, for appearance.
[/code]
[code]obj=controller event=create
global.ta=ds_list_create()//Creates a list which will hold all the ID's
//of every tank so the turrets can identify which is theirs.
[/code]
[code]obj=tank's base event=create
ds_list_add(global.ta,id)//This adds the tanks unique ID to the list
position=ds_list_find_index(global.ta,id)//This gets the tank's position in
//that list.
turret=instance_create(x,y,Turret)//This code creates the turret and and gives
//us IT'S unique ID.
turret.owner=ds_list_find_value(global.ta,position)//This tells the unique
//turret that was just made
//exactly which tank
//created it.
[/code]
[code]obj=Tank event=step
image_angle=direction
[/code]
[code]obj=Turret event=step
x=owner.x //This tells the turret to be exactly where it's tank is.
y=owner.y
image_angle=direction//for appearance.
direction=point_direction(x,y,mouse_x,mouse_y)//again, for appearance.
[/code]
Labels: Advanced

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home