I am working on a Pong game that also uses a gun to shoot out the rear wall of the playing box, so that the ball may escape. I'm using Dev-C++ and the Allegro library.
There are two slight problems...
1) The "bullet" fired from the gun hits its target, but doesn't disappear. Each last round fired hangs around until a next round is fired. At that point, they can be erased by the ball bouncing around. Also, the last round's bullet's remaining carcass will hang around into the next round of the game.
2) I'd like to slow down the bullet's speed, because it's pretty much instantaneous target detonation right now. I'd like to actually see the projectile traveling, but I'm not sure of the best way to do that.
Below is the chunk of code I have for the gun's actions.
Let me know if you need any other info, and thanks for any help.
void shootGun() {
char hit = FALSE;
bullet_x = paddle_x+30;
bullet_y = paddle_y-3;
bullet_tempX = bullet_x;
bullet_tempY = bullet_y;
while (!hit) {
--bullet_y;
if (getpixel(screen, bullet_x, bullet_y-3)!=BLACK) {
hit = TRUE;
explodeMe(bullet_x, bullet_y-10);
//eatN(bullet_x, bullet_y-10);
//circle(screen, bullet_x, bullet_y, 2, BLACK);
rectfill(screen, 171, 211, 459, 479, BLACK);
}
}
}
void loadGun() {
acquire_screen();
circle(screen, bullet_x, bullet_y, 2, YELLOW);
circle(screen, bullet_tempX, bullet_tempY, 2, BLACK);
//draw_sprite(screen, buffer, 0, 0);
release_screen();
bool fire = TRUE;
if (key[KEY_SPACE]) {
shootGun();
}
}