Hello masters,
I'm teaching C++ in my technical school, and I wanted to introduce my class in games world with some simple experiences.
We are making a very simple arcade game, where a ship (^) fires some shots (* . ! A) and so on.
We made it with simple functions, and it worked, but cannot fire more than a projectile simultaneously. So, I decided to buid a class.
But, the main problem is that I have to create one shot when I press the keyboard (and this worked), but it have to keep moving even after I release it. And, when I press again, I want to have another shot created (and moving). How to do this?
If helps to understand, follow the class:
Code:
class cannon
{
protected:
typedef struct fire
{
char bullet;
int x;
int y;
};
void setArms(void)
{
arms[0].bullet='*';
arms[1].bullet='!';
}
public:
fire arms[2];
void shoot(int i)
{
clock_t runTime;
runTime = clock();
gotoxy(arms[i].x,(int)(arms[i].y-runTime/30));
printf("%c", arms[i].bullet);
gotoxy(arms[i].x,(int)(arms[i].y-runTime/30-1));
printf(" ");
};
cannon(int x,int y, int i)
{
setArms();
arms[i].x = x;
arms[i].y = y;
shoot(i);
};
};