Skip to content

Commit

Permalink
Added pause on serve
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSofox committed Apr 12, 2020
1 parent 1b589ec commit 862c4fe
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ball.c
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#define SWING_COOLDOWN 0
#define SWING_TIME 10


#define SCORE_LIMIT 2

/*
Notes regarding SGDK API changes:
Expand Down
6 changes: 6 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct Ball{
struct Vector2 ppos;
struct Vector2f pos;
struct Vector2f vel;
int pauseTime;
int offside;
};

Expand Down

0 comments on commit 862c4fe

Please sign in to comment.