C
create_event@
Guest
Here's the skinny-
I've got an object that has five turrets, identified by the HP# variables (as set in the create code).
I've got a shot coming in to hit the ship
when it hits, it lowers the hp of the ship, then, using a calculated chance of destruction, checks that chance against each turret, and if the chance succeeds (or fails, depending how you, look at it), it kills the turret.
But it's not killing the turrets.
*whines* Why?
Information about object: shp
Sprite: ship
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Mask:
Create Event:
execute code:
///set vars - create hardpoints
destroy_chance=0
hp=30
HP1=instance_create(x-30,y-15,hdp)
HP2=instance_create(x-15,y-25,hdp)
HP3=instance_create(x,y-35,hdp)
HP4=instance_create(x+15,y-25,hdp)
HP5=instance_create(x+30,y-15,hdp)
Collision Event with object shot:
execute code:
///check for destruction of hardpoint
with (other) instance_destroy()
hp-=1
if hp>0
{
switch (destroy_chance=400*(hp/50))
{
case random(100)>destroy_chance:
if instance_exists(HP1) { with (HP1) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP2) { with (HP2) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP3) { with (HP3) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP4) { with (HP4) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP5) { with (HP5) instance_destroy(); break;}
}
}
if hp<=0
instance_destroy()
Key Press Event for Key:
create instance of object shot at position (random(room_width),random(room_height))
I'm probably using the wrong sort of code to optimally do this, but it should be working...from my eyeballs.
(this is just a test of my turret system, so the other objects have no code (except to start moving))
I've got an object that has five turrets, identified by the HP# variables (as set in the create code).
I've got a shot coming in to hit the ship
when it hits, it lowers the hp of the ship, then, using a calculated chance of destruction, checks that chance against each turret, and if the chance succeeds (or fails, depending how you, look at it), it kills the turret.
But it's not killing the turrets.
*whines* Why?
Information about object: shp
Sprite: ship
Solid: false
Visible: true
Depth: 0
Persistent: false
Parent:
Mask:
Create Event:
execute code:
///set vars - create hardpoints
destroy_chance=0
hp=30
HP1=instance_create(x-30,y-15,hdp)
HP2=instance_create(x-15,y-25,hdp)
HP3=instance_create(x,y-35,hdp)
HP4=instance_create(x+15,y-25,hdp)
HP5=instance_create(x+30,y-15,hdp)
Collision Event with object shot:
execute code:
///check for destruction of hardpoint
with (other) instance_destroy()
hp-=1
if hp>0
{
switch (destroy_chance=400*(hp/50))
{
case random(100)>destroy_chance:
if instance_exists(HP1) { with (HP1) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP2) { with (HP2) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP3) { with (HP3) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP4) { with (HP4) instance_destroy(); break;}
case random(100)>destroy_chance:
if instance_exists(HP5) { with (HP5) instance_destroy(); break;}
}
}
if hp<=0
instance_destroy()
Key Press Event for Key:
create instance of object shot at position (random(room_width),random(room_height))
I'm probably using the wrong sort of code to optimally do this, but it should be working...from my eyeballs.
(this is just a test of my turret system, so the other objects have no code (except to start moving))