From 862c4fef28e854e6974252ba43278a93b9b0bc73 Mon Sep 17 00:00:00 2001 From: Sofox Date: Sun, 12 Apr 2020 23:31:52 +0100 Subject: [PATCH] Added pause on serve --- ball.c | 7 +++++++ constants.h | 3 +++ main.c | 6 ++++++ structs.h | 1 + 4 files changed, 17 insertions(+) diff --git a/ball.c b/ball.c index e07e33a..0fcd2a3 100644 --- a/ball.c +++ b/ball.c @@ -15,6 +15,7 @@ struct Ball initBall(int serve){ ball.vel.x = 1*serve; ball.vel.y = 0; ball.offside = 0; + ball.pauseTime = 120; return ball; } struct Vector2f hitBall(struct Ball ball, struct Player player){ @@ -27,6 +28,12 @@ struct Vector2f hitBall(struct Ball ball, struct Player player){ } struct Ball updateBall(struct Ball ball, struct Player player1, struct Player player2){ + if(ball.pauseTime>0){ + ball.pauseTime-=1; + ball.ppos.x = ball.pos.x; + ball.ppos.y = ball.pos.y; + return ball; + } if (ball.vel.x<0 && check_ball_hit(ball, player1)){ ball.vel = hitBall(ball, player1); } diff --git a/constants.h b/constants.h index 52d3714..7a6bab1 100644 --- a/constants.h +++ b/constants.h @@ -15,6 +15,9 @@ #define SWING_COOLDOWN 0 #define SWING_TIME 10 + +#define SCORE_LIMIT 2 + /* Notes regarding SGDK API changes: diff --git a/main.c b/main.c index 9e50359..48e2cb7 100644 --- a/main.c +++ b/main.c @@ -197,9 +197,15 @@ int main(){ gameState.p2s+=1; gameState.serve = 1; } + ball = initBall(gameState.serve); //int t = true ? 1:3; } + if(ball.pauseTime>0){ + VDP_drawText("Ready?", 17, 12); + } else { + VDP_fillTileMapRect(BG_A, TILE_ATTR_FULL(PAL3,0,FALSE,FALSE,1),17,12,6,1); + } SPR_setHFlip (ballSprite, ball.vel.x>0); SPR_setPosition(ballSprite, ball.ppos.x,ball.ppos.y); diff --git a/structs.h b/structs.h index cc8b04e..8b2208a 100644 --- a/structs.h +++ b/structs.h @@ -30,6 +30,7 @@ struct Ball{ struct Vector2 ppos; struct Vector2f pos; struct Vector2f vel; + int pauseTime; int offside; };