Trying to make a copy of space invaders, it’s purely for fun but now i’ve used quite a while trying to make the shoot function work proberly. The problem is that my “bullet” disapears after i move my player, due to the fact that i called it’s x to be the players x, but i can’t figure out how to make it not update all the time, cause i’m calling the shoot function in draw() everytime i press UP. Hope you guys can help me out here, thx in advance.
Rune
class Shoot{
int scl = 15;
int bulletSpeed = -10;
int bulletX;
int bulletY;
Shoot(){
bulletY = 900;
}
void shoot(){
edge();
bulletX = p.x;
fill(255);
bulletY = bulletY + bulletSpeed;
ellipse(bulletX, bulletY, scl, scl);
}
void edge(){
if (bulletY < 0+(scl*1.25)){
bulletY = 900;
}
}
}
So i cant quite figure out how to make sure that when i shoot it’s only the current x value of my player. It still seems like it’s only running the function as long as it is getting the input “UP”
This line would belong into the constructor Shoot (if you use Shoot upon firing, like ....new Shoot(...);)
The function shoot is your display method of the class (you display the bullet with it). Therefore this is called throughout and should not receive the player position anymore.
The function / method shoot be called throughout from draw(). Not only when you shoot but throughout, because you want to see the bullet after firing it.
To get more help, post your entire code or show how you fire and call shoot.
Shoot sh = s.get(0);
sh.shoot();>
that’s the way i call the shoot function, dont mind the fact that’s it’s only possible for me to call 1 object currently i’ll fix that afterwards. But declaring the x value in the constructor brings me to the problem of x just being the center of the screen where the player spawns