From 77bea4cd9be2d4e3f1ff7d8d2c5a7bf109d30187 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Wed, 12 Sep 2007 21:32:01 +0200 Subject: [PATCH] Don't allow racket hit on "out"; non-permanent racket swing Don't allow the player to hit the ball with the racket when an "out" state has been reached. The ball will fly-by the racket even with the racket swung at the time of impact. Disallow keeping the "swing racket" button permanently pressed, but add a lock to disallow re-swinging the rack when the corresponding key has not been released yet. --- game.c | 19 ++++++++++++------- game.h | 3 ++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/game.c b/game.c index a84cd5a..41b78a0 100644 --- a/game.c +++ b/game.c @@ -34,8 +34,8 @@ void game( bool singleplayer) { GameState s = { { 0, 0, 0.0, 0.0, 0.0 }, { 0, 0, 0, 0, 0 }, - { GAME_X_MIN-RACKET_X_MID*2, GAME_Y_MID, 0, 0, 1, DESIRE_NORMAL, PLAYER_TYPE_HUMAN }, - { GAME_X_MAX+RACKET_X_MID*2, GAME_Y_MID, 0, 0, 0, DESIRE_NORMAL, PLAYER_TYPE_HUMAN }, + { GAME_X_MIN-RACKET_X_MID*2, GAME_Y_MID, 0, 0, 1, DESIRE_NORMAL, PLAYER_TYPE_HUMAN, false }, + { GAME_X_MAX+RACKET_X_MID*2, GAME_Y_MID, 0, 0, 0, DESIRE_NORMAL, PLAYER_TYPE_HUMAN, false }, 0, 0, 0, @@ -100,7 +100,7 @@ bool step( GameState* s) { if( IS_OUT_Y( s->ball.y)) { /* out - responsibilities stay the same */ - s->status = "out -- don't hit the ball!"; + s->status = "out!"; sound_out(); s->referee = REFEREE_OUT; } else { @@ -148,7 +148,7 @@ bool step( GameState* s) { } if( IS_OUT_X(s->ball.x)) { - if( s->ball.move_x <= 0 && IS_NEAR_X( s->player1.x, s->ball.x) && IS_NEAR_Y( s->player1.y, s->ball.y) && s->player1.state) { + if( s->ball.move_x <= 0 && IS_NEAR_X( s->player1.x, s->ball.x) && IS_NEAR_Y( s->player1.y, s->ball.y) && s->player1.state && s->referee != REFEREE_OUT) { s->ball.x = GAME_X_MIN; if( s->player1.state == PLAYER_STATE_MAX) { s->ball.move_x = PLAYER_POWERSHOT; @@ -160,7 +160,7 @@ bool step( GameState* s) { s->ball.jump += 1.0-2.0*(s->player1.state<5); sound_applause_stop(); sound_racket(); - } else if( s->ball.move_x >= 0 && IS_NEAR_X( s->player2.x, s->ball.x) && IS_NEAR_Y( s->player2.y, s->ball.y) && s->player2.state) { + } else if( s->ball.move_x >= 0 && IS_NEAR_X( s->player2.x, s->ball.x) && IS_NEAR_Y( s->player2.y, s->ball.y) && s->player2.state && s->referee != REFEREE_OUT) { s->ball.x = GAME_X_MAX; if( s->player2.state == PLAYER_STATE_MAX) { s->ball.move_x = -PLAYER_POWERSHOT; @@ -333,8 +333,13 @@ void input_human( Player* player, bool up, bool down, bool hit) { player->y += 6; } - if( hit && !player->state) { - player->state = PLAYER_STATE_MAX; + if( hit) { + if( !player->state && !player->state_locked) { + player->state = PLAYER_STATE_MAX; + player->state_locked = true; + } + } else { + player->state_locked = false; } } diff --git a/game.h b/game.h index cce70c8..5db226c 100644 --- a/game.h +++ b/game.h @@ -57,6 +57,7 @@ typedef struct { unsigned char desire; /* what the player aims to do (0=normal, 1=upper edge, 2=lower edge)*/ bool type; /* is this player ai-controlled or human? */ float ball_dest; /* prospective y-position of ball */ + bool state_locked; /* enabled when user keeps pressing the "hit" key */ } Player; enum { @@ -128,7 +129,7 @@ typedef struct { #define IS_NEAR_X(px,bx) (fabsf(px-bx)