From 3d1d6192a1de067173141a5db4eeab97d026e524 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Tue, 4 Aug 2009 18:38:53 +0200 Subject: [PATCH] Move weather settings to Location from GameState Fog, rain and night mode really belong to a location and not the whole game state. --- game.c | 40 ++++++---------------------------------- game.h | 9 ++++----- locations.h | 35 ++++++++++++++++++++++++++++------- tennix.c | 12 ++++++------ 4 files changed, 44 insertions(+), 52 deletions(-) diff --git a/game.c b/game.c index 557ad13..d6d3a6e 100644 --- a/game.c +++ b/game.c @@ -52,10 +52,6 @@ GameState *gamestate_new() { 0, WINNER_NONE, SOUND_EVENT_NONE, /* sound events */ - 0, - 0, - false, - 0, SCORE_UNDECIDED, 0, EVENTCOUNTER_GAMESTATE_START, @@ -189,7 +185,7 @@ void gameloop(GameState *s) { Uint32 ft, frames; /* frame timer and frames */ #endif - if (s->rain > 0) { + if (s->location->rain > 0) { play_sample_background(SOUND_RAIN); } if (s->location->max_visitors > 100) { @@ -389,24 +385,6 @@ bool step( GameState* s) { SDL_PumpEvents(); keys = SDL_GetKeyState(NULL); - if( s->time%50==0) { - if (keys['r']) { - if (s->rain == 0) { - play_sample_background(SOUND_RAIN); - } - s->rain += 10; - } - if (keys['t']) { - s->fog++; - } - if (keys['1']) { - s->wind++; - } - if (keys['2']) { - s->wind--; - } - } - if(!(SDL_GetTicks() < fading_start+FADE_DURATION) && s->winner == WINNER_NONE) { for (p=1; p<=MAXPLAYERS; p++) { if( PLAYER(s, p).type == PLAYER_TYPE_HUMAN) { @@ -430,12 +408,6 @@ bool step( GameState* s) { limit_value( &PLAYER(s, 1).y, PLAYER_Y_MIN, PLAYER_Y_MAX); limit_value( &PLAYER(s, 2).y, PLAYER_Y_MIN, PLAYER_Y_MAX); - if (s->ball.move_x > 0 && s->wind > 0) { - s->ball.x += fabsf(s->wind)/2; - } else if (s->ball.move_x < 0 && s->wind < 0) { - s->ball.x -= fabsf(s->wind)/2; - } - s->ball.z += s->ball.move_z; if (!s->ball.inhibit_gravity) { s->ball.move_z += GRAVITY; @@ -596,12 +568,12 @@ void render(const GameState* s, RenderState* r) { font_draw_string(FONT_MEDIUM, r->text_status, (WIDTH-font_get_string_width(FONT_MEDIUM, r->text_status))/2, HEIGHT-50); - for (i=0; irain; i++) { + for (i=0; ilocation->rain; i++) { x = rand()%WIDTH; y = rand()%HEIGHT; - draw_line_faded(x, y, x+10+s->wind*5, y+30, 0, 0, 255, 100, 200, 255); + draw_line_faded(x, y, x+10, y+30, 0, 0, 255, 100, 200, 255); } - if (s->rain) { + if (s->location->rain) { /** * Cheap-ish update of the whole screen. This can * probably be optimized. @@ -621,7 +593,7 @@ void render(const GameState* s, RenderState* r) { line_horiz( GAME_Y_MIN, 100, 100, 100); line_horiz( GAME_Y_MAX, 100, 100, 100); #endif - switch (s->fog) { + switch (s->location->fog) { default: case 4: fill_image_offset(GR_FOG2, 0, 0, WIDTH, HEIGHT, -s->time/150, 0); @@ -634,7 +606,7 @@ void render(const GameState* s, RenderState* r) { case 0: break; } - if (s->night) { + if (s->location->night) { show_image(GR_NIGHT, 0, 0, 255); } diff --git a/game.h b/game.h index 793a786..f18b764 100644 --- a/game.h +++ b/game.h @@ -86,6 +86,9 @@ typedef struct { unsigned int worldmap_x; unsigned int worldmap_y; bool has_referee; + bool night; + unsigned int rain; + unsigned int fog; } Location; typedef struct { @@ -164,7 +167,7 @@ enum { }; typedef struct { - Location* location; + const Location* location; int current_location; /* index of loc. in global location table */ Ball ball; Player players[MAXPLAYERS]; @@ -174,10 +177,6 @@ typedef struct { unsigned int current_set; int winner; soundevent_t sound_events; - unsigned int rain; - unsigned int fog; - bool night; - int wind; int score_event; unsigned int score_time; eventcounter_t ec_game; diff --git a/locations.h b/locations.h index 7ef41eb..1786aa5 100644 --- a/locations.h +++ b/locations.h @@ -40,7 +40,10 @@ static Location locations[] = { 1, 422, 187, - true + true, + false, + 0, + 0, }, { /* French Open, http://en.wikipedia.org/wiki/French_Open */ @@ -54,7 +57,10 @@ static Location locations[] = { 1, 227, 51, - true + true, + false, + 10, + 0, }, { /* http://en.wikipedia.org/wiki/The_Championships,_Wimbledon */ @@ -68,7 +74,10 @@ static Location locations[] = { 1, 225, 46, - true + true, + false, + 50, + 1, }, { /* US Open, http://en.wikipedia.org/wiki/US_Open_(tennis) */ @@ -82,7 +91,10 @@ static Location locations[] = { 1, 125, 64, - true + true, + false, + 0, + 2, }, #ifdef NONFREE_LOCATIONS @@ -98,7 +110,10 @@ static Location locations[] = { 1, 218, 37, - false + false, + false, + 0, + 0, }, #if 0 /* We don't have permission for the following locations just yet... */ @@ -114,7 +129,10 @@ static Location locations[] = { 1, 243, 53, - true + true, + false, + 0, + 0, }, { /* http://en.wikipedia.org/wiki/Olympic_Green_Tennis_Centre */ @@ -128,7 +146,10 @@ static Location locations[] = { 1, 384, 64, - true + true, + false, + 0, + 0, }, #endif #endif diff --git a/tennix.c b/tennix.c index 65c0fe0..10cf5a5 100644 --- a/tennix.c +++ b/tennix.c @@ -404,12 +404,6 @@ int main( int argc, char** argv) { fprintf(stderr, "Game not yet prepared!\n"); exit(EXIT_FAILURE); } - /* Set the day/night status */ - if (night_start < night_end) { - prepared_game->night = (prepared_game->location->worldmap_x > night_start && prepared_game->location->worldmap_x < night_end); - } else { - prepared_game->night = (prepared_game->location->worldmap_x < night_end || prepared_game->location->worldmap_x > night_start); - } /* Cancel a possibly started game */ free(current_game); @@ -664,6 +658,12 @@ int main( int argc, char** argv) { default: if (!location_info_visible && highlight_location != -1) { prepared_game->current_location = highlight_location; + /* Set the day/night status */ + if (night_start < night_end) { + locations[prepared_game->current_location].night = (locations[prepared_game->current_location].worldmap_x > night_start && locations[prepared_game->current_location].worldmap_x < night_end); + } else { + locations[prepared_game->current_location].night = (locations[prepared_game->current_location].worldmap_x < night_end || locations[prepared_game->current_location].worldmap_x > night_start); + } prepared_game->location = &(locations[prepared_game->current_location]); location_info_xpos = MAX(0, MIN(WIDTH-320-50, mx-320/2)); location_info_ypos = MAX(0, MIN(HEIGHT-200-160, my-200/2)); -- 2.11.4.GIT