I am programming a Space Invaders clone in C++ on the console.
I have a spaceship class in which I create the shape on the console screen.
I use arrow keys to move it across the screen horizontally.
Here you have pictures, which show moving the spaceship to the right.
https://i.stack.imgur.com/Wmefx.jpg
This is my approach
class BaseSpaceShip{
protected:
private:
char ship[4][19] = {
" \xDB ",
" \xDB\xDB\xDB\xDB\xDB ",
" \xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB\xDB"
};
const int mapy = 4;
int x, y;
void Invalidate();
void cls();
public:
BaseSpaceShip();
~BaseSpaceShip();
void Init();
virtual void MoveShip(int dx, int dy);
};
BaseSpaceShip::BaseSpaceShip() {
x = 130;
y = 69;
Init();
}
BaseSpaceShip::~BaseSpaceShip() {
}
void BaseSpaceShip::Init() {
cls();
for (int i = 0; i < mapy; i++) {
gotoxy(x - i, y + i);
cout << ship[i] << endl;
}
}
void BaseSpaceShip::MoveShip(int dx , int dy) {
x+= dx;
y += dy;
Init();
}
Why does this bug occur and how do I solve it?
Furthermore I heard of the double buffering concept to remove the screen flickering when I move my spaceship, but how do I implement this?