frootloop69
Member
Hi all, hoping someone can help me out here.
I'm making a space invaders type game and I want to add per-pixel destructible bases - something similar to the original Space Invaders game.
Its mostly working, but I run into a strange problem. The bases seem to get destroyed fine up until the last few rows of pixels, and then no further.
I end up with a rectangle that the bullets collide against and are destroyed, but the base remains the same.
I've attached a screenshot to illustrate what I mean .
I'm using precise collision and collision masks for the bullet and the base.
Currently my code is as such:
Base object:
Bullet Object
Would appreciate any help or insights. I feel like I'm missing something simple or misunderstanding something fundamental.
Thanks you in advance for your time and expertise!
I'm making a space invaders type game and I want to add per-pixel destructible bases - something similar to the original Space Invaders game.
Its mostly working, but I run into a strange problem. The bases seem to get destroyed fine up until the last few rows of pixels, and then no further.
I end up with a rectangle that the bullets collide against and are destroyed, but the base remains the same.
I've attached a screenshot to illustrate what I mean .
I'm using precise collision and collision masks for the bullet and the base.
Currently my code is as such:
Base object:
Code:
//Create event
surfBase = noone;
sprite_index = sprite_duplicate(sprShield);
//Collide with bullet event
if !(surface_exists(surfBase))
{
surfBase = surface_create(sprite_width, sprite_height);
}
surface_set_target(surfBase); // surface as draw target
draw_clear_alpha(c_black,1); // clear the surface
draw_sprite(sprite_index,0,0,0); //draw the current base
gpu_set_blendmode(bm_subtract); // get ready to cut out
draw_set_color(c_black);
draw_sprite(other.sprite_index,0, other.x -x, other.y - y ); // cut out the colliding bullet
gpu_set_blendmode(bm_normal);
var oldspr = sprite_index;
sprite_index=sprite_create_from_surface(surfBase,0,0,sprite_width,sprite_height,false,false,0,0); //create a new sprite from the surface after we cut out the bullet shape
sprite_collision_mask(sprite_index, false,0,0,sprite_width,sprite_height,0,bboxkind_precise,0) // create a new precise collision mask
sprite_delete(oldspr); // delete the old sprite
surface_reset_target();
surface_free(surfBase)
Code:
//Create event
vspeed = -4.5;
cnt = 0;
//Collide with base event
cnt++; // increment every collision - we need the bullet to penetrate the base before being destroyed
if cnt >= 1
{
instance_destroy(self);
}
Thanks you in advance for your time and expertise!
Attachments
-
3.6 KB Views: 17
-
3.6 KB Views: 17
Last edited: