Make player play automatically

This commit is contained in:
Hri7566 2024-01-25 04:10:44 -05:00
parent a4b37d49e9
commit 6df086ed5b
2 changed files with 9 additions and 2 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
/cong
/cong.exe

10
cong.c
View File

@ -37,6 +37,7 @@ int main(void) {
float dt = 0.0f;
char scoreText[2048];
char isPaused = 0;
char playerMoveDown = 1;
initPlayer(&player);
initBall(&ball);
@ -67,6 +68,11 @@ int main(void) {
if (ball.transform.position.y + ball.transform.size.y >= HEIGHT || ball.transform.position.y <= 0) {
ballVel.y = -ballVel.y;
if (playerMoveDown)
playerMoveDown = 0;
else
playerMoveDown = 1;
}
if (ball.transform.position.x + ball.transform.size.x >= wall.transform.position.x && ballVel.x > 0) {
@ -88,9 +94,9 @@ int main(void) {
}
// Player movement
if (IsKeyDown(KEY_W) && player.transform.position.y > 0) {
if (!playerMoveDown && player.transform.position.y > 0) {
player.transform.position.y -= playerSpeed * dt;
} else if (IsKeyDown(KEY_S) && player.transform.position.y + player.transform.size.y < HEIGHT) {
} else if (playerMoveDown && player.transform.position.y + player.transform.size.y < HEIGHT) {
player.transform.position.y += playerSpeed * dt;
}
}