From affb433e3dbaf19a6c842a9fd2ad847106829bad Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Wed, 22 Oct 2008 20:10:30 +0200 Subject: [PATCH] First support for in-game weather (rainfall) Use the "r" key to increase the amount of rainfall during the game. --- game.c | 18 ++++++++++++++++++ game.h | 1 + 2 files changed, 19 insertions(+) diff --git a/game.c b/game.c index 6f861c1..292f67e 100644 --- a/game.c +++ b/game.c @@ -61,6 +61,7 @@ GameState *gamestate_new() { SOUND_MAX, 0.0, 0.0, + 0, 0 }; @@ -281,6 +282,9 @@ bool step( GameState* s) { } else if (keys[SDLK_F7]) { s->court_type--; } + if (keys['r']) { + s->rain += 10; + } if( s->court_type > GR_CTT_LAST) { s->court_type = GR_CTT_FIRST; } else if (s->court_type < GR_CTT_FIRST) { @@ -355,6 +359,7 @@ bool step( GameState* s) { } void render( GameState* s) { + int i, x, y; if (s->play_sound != SOUND_MAX) { play_sample(s->play_sound); s->play_sound = SOUND_MAX; @@ -404,6 +409,19 @@ void render( GameState* s) { font_draw_string( GR_DKC2_FONT, s->status, (WIDTH-font_get_string_width( GR_DKC2_FONT, s->status))/2, HEIGHT-50, s->time/30, ANIMATION_WAVE); + for (i=0; irain; i++) { + x = rand()%WIDTH; + y = rand()%HEIGHT; + draw_line_faded(x, y, x+10, y+30, 0, 0, 255, 100, 200, 255); + } + if (s->rain) { + /** + * Cheap-ish update of the whole screen. This can + * probably be optimized. + **/ + update_rect(0, 0, WIDTH, HEIGHT); + } + #ifdef DEBUG line_horiz( s->player1.y, 255, 0, 0); line_horiz( s->player2.y, 0, 0, 255); diff --git a/game.h b/game.h index 4303e09..2545762 100644 --- a/game.h +++ b/game.h @@ -114,6 +114,7 @@ typedef struct { float joystick_y; float joystick_x; unsigned char joystick_a; + unsigned int rain; } GameState; #define PI 3.1415 -- 2.11.4.GIT