So I am making a game for a school project. You might be familiar with this one. Its Arkanoid, or the game in which a ball is used to destroy bricks and is deflected on by a platform.
Currently I am stuck at a point. I have got an idea of how to move my platform using _getch(), but when I put in a ball it is also moving on a key press. I cant figure out on how to run it simultaneously with or without any key presses. Or if there is way to skip a key press every time until it is registered.
Here is my code so far. The movement of the ball is not complete it is just a prototype right now. Any help would be appreciated.
I am using a graphics library provided by my school but you can use the C++ graphics library.
#include <iostream>
#include "myconsole.h"
#include "mygraphics.h"
#include <conio.h>
#include <string>
using namespace std;
void rect() {
COLORREF White = RGB(255, 255, 255);
COLORREF Blue = RGB(135, 206, 235);
// x1 y x2 y
myRect(400, 475, 550, 480, Blue, Blue);
_getch();
}
void circle() {
COLORREF Red = RGB(255, 0, 0);
myEllipse(0, 50, 300, 350, Red, Red);
_getch();
}
void moverect() {
COLORREF White = RGB(255, 255, 255);
COLORREF Blue = RGB(135, 206, 235);
char _x;
const char _r = 'd';
const char _l = 'a';
int x1 = 400;
int x2 = 550;
int by1 = 455;
int by2 = 475;
int m = 48;
while (1) {
_x = _getch();
system("cls");
if (_x == _r) {
if (x2 < 970) {
x1 += 10;
x2 += 10;
for (int i = 0; i < 10; i++) {
myRect(x1++, 475, x2++, 480, Blue, Blue);
}
}
else
myRect(x1, 475, x2, 480, Blue, Blue);
}
else if (_x == _l) {
if (x1 > 0) {
x1 -= 10;
x2 -= 10;
for (int i = 0; i < 10; i++) {
myRect(x1--, 475, x2--, 480, Blue, Blue);
}
}
else
myRect(x1, 475, x2, 480, Blue, Blue);
}
myEllipse(463, by1 -= 10, 487, by2 -= 10, White, White);
}
}
int main() {
{
moverect();
return 0;
}
}