From: Ingo Ruhnke Date: Sun, 11 Apr 2004 15:07:29 +0000 (+0000) Subject: - moved some global variables into a seperate class X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9a0ad01116256e9cf7a0a340a1bb5f83e2a6ba44;p=supertux.git - moved some global variables into a seperate class SVN-Revision: 476 --- diff --git a/src/badguy.cpp b/src/badguy.cpp index 36eb7a3fa..82529e97f 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -791,9 +791,10 @@ BadGuy::squish_me(Player* player) { make_player_jump(player); - World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier); + World::current()->add_score(base.x - scroll_x, + base.y, 50 * player_status.score_multiplier); play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); - score_multiplier++; + player_status.score_multiplier++; dying = DYING_SQUISHED; timer_start(&timer, 2000); @@ -808,9 +809,9 @@ BadGuy::squish(Player* player) World::current()->add_bad_guy(base.x, base.y, BAD_BOMB); make_player_jump(player); - World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier); + World::current()->add_score(base.x - scroll_x, base.y, 50 * player_status.score_multiplier); play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); - score_multiplier++; + player_status.score_multiplier++; remove_me(); return; @@ -849,14 +850,14 @@ BadGuy::squish(Player* player) make_player_jump(player); - World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier); - score_multiplier++; + World::current()->add_score(base.x - scroll_x, base.y, 25 * player_status.score_multiplier); + player_status.score_multiplier++; return; } else if(kind == BAD_FISH) { make_player_jump(player); - World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier); - score_multiplier++; + World::current()->add_score(base.x - scroll_x, base.y, 25 * player_status.score_multiplier); + player_status.score_multiplier++; // simply remove the fish... remove_me(); @@ -894,10 +895,10 @@ BadGuy::kill_me() /* Gain some points: */ if (kind == BAD_BSOD) World::current()->add_score(base.x - scroll_x, base.y, - 50 * score_multiplier); + 50 * player_status.score_multiplier); else World::current()->add_score(base.x - scroll_x, base.y, - 25 * score_multiplier); + 25 * player_status.score_multiplier); /* Play death sound: */ play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 5016baecc..fdae0a629 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -249,11 +249,11 @@ GameSession::process_events() break; case SDLK_END: if(debug_mode) - distros += 50; + player_status.distros += 50; break; case SDLK_SPACE: if(debug_mode) - next_level = 1; + player_status.next_level = 1; break; case SDLK_DELETE: if(debug_mode) @@ -269,7 +269,7 @@ GameSession::process_events() break; case SDLK_s: if(debug_mode) - score += 1000; + player_status.score += 1000; case SDLK_f: if(debug_fps) debug_fps = false; @@ -342,16 +342,16 @@ GameSession::action() { Player& tux = *world->get_tux(); - if (tux.is_dead() || next_level) + if (tux.is_dead() || player_status.next_level) { /* Tux either died, or reached the end of a level! */ halt_music(); - if (next_level) + if (player_status.next_level) { /* End of a level! */ levelnb++; - next_level = 0; + player_status.next_level = 0; if(st_gl_mode != ST_GL_TEST) { drawresultscreen(); @@ -381,8 +381,8 @@ GameSession::action() if(st_gl_mode != ST_GL_TEST) { - if (score > hs_score) - save_hs(score); + if (player_status.score > hs_score) + save_hs(player_status.score); } world->get_level()->free_gfx(); @@ -660,7 +660,7 @@ GameSession::drawstatus() Player& tux = *world->get_tux(); char str[60]; - sprintf(str, "%d", score); + sprintf(str, "%d", player_status.score); text_draw(&white_text, "SCORE", 0, 0, 1); text_draw(&gold_text, str, 96, 0, 1); @@ -682,7 +682,7 @@ GameSession::drawstatus() text_draw(&gold_text, str, 304, 0, 1); } - sprintf(str, "%d", distros); + sprintf(str, "%d", player_status.distros); text_draw(&white_text, "DISTROS", screen->h, 0, 1); text_draw(&gold_text, str, 608, 0, 1); @@ -710,10 +710,10 @@ GameSession::drawendscreen() text_drawf(&blue_text, "GAMEOVER", 0, 200, A_HMIDDLE, A_TOP, 1); - sprintf(str, "SCORE: %d", score); + sprintf(str, "SCORE: %d", player_status.score); text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1); - sprintf(str, "DISTROS: %d", distros); + sprintf(str, "DISTROS: %d", player_status.distros); text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); @@ -731,10 +731,10 @@ GameSession::drawresultscreen(void) text_drawf(&blue_text, "Result:", 0, 200, A_HMIDDLE, A_TOP, 1); - sprintf(str, "SCORE: %d", score); + sprintf(str, "SCORE: %d", player_status.score); text_drawf(&gold_text, str, 0, 224, A_HMIDDLE, A_TOP, 1); - sprintf(str, "DISTROS: %d", distros); + sprintf(str, "DISTROS: %d", player_status.distros); text_drawf(&gold_text, str, 0, 256, A_HMIDDLE, A_TOP, 1); flipscreen(); diff --git a/src/player.cpp b/src/player.cpp index 5ff28ce06..1fbe91ccb 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -201,7 +201,7 @@ Player::action() physic.enable_gravity(false); /* Reset score multiplier (for multi-hits): */ - score_multiplier = 1; + player_status.score_multiplier = 1; } if(jumped_in_solid) @@ -289,7 +289,7 @@ Player::action() if (base.x >= World::current()->get_level()->endpos && World::current()->get_level()->endpos != 0) { - next_level = 1; + player_status.next_level = 1; } } @@ -830,7 +830,7 @@ Player::collision(void* p_c_object, int c_object) play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); World::current()->add_score(pbad_c->base.x - scroll_x, pbad_c->base.y, - 25 * score_multiplier); + 25 * player_status.score_multiplier); } } } @@ -845,7 +845,7 @@ Player::collision(void* p_c_object, int c_object) pbad_c->kill_me(); } } - score_multiplier++; + player_status.score_multiplier++; } break; default: diff --git a/src/resources.cpp b/src/resources.cpp index 41e1773dd..b02fe49ad 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -17,7 +17,6 @@ texture_type img_box_full; texture_type img_box_empty; texture_type img_mints; texture_type img_coffee; -texture_type img_super_bkgd; texture_type img_red_glow; /* Load graphics/sounds shared between all levels: */ @@ -284,12 +283,6 @@ void loadshared() USE_ALPHA); - /* Super background: */ - - texture_load(&img_super_bkgd, datadir + "/images/shared/super-bkgd.png", - IGNORE_ALPHA); - - /* Sound effects: */ /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound" diff --git a/src/scene.cpp b/src/scene.cpp index 82826d5df..d916e505e 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -13,11 +13,7 @@ #include #include "scene.h" -int score; -int distros; -int next_level; -int score_multiplier; -timer_type super_bkgd_timer; +PlayerStatus player_status; // FIXME: Move this into a view class float scroll_x; diff --git a/src/scene.h b/src/scene.h index daaa4e645..435dc2dc0 100644 --- a/src/scene.h +++ b/src/scene.h @@ -19,10 +19,15 @@ #define FRAME_RATE 10 // 100 Frames per second (10ms) // Player stats -extern int score; -extern int distros; -extern int next_level; -extern int score_multiplier; +struct PlayerStatus +{ + int score; + int distros; + int next_level; + int score_multiplier; +}; + +extern PlayerStatus player_status; extern timer_type super_bkgd_timer; extern float scroll_x; diff --git a/src/special.cpp b/src/special.cpp index ff1db1343..218751ec8 100644 --- a/src/special.cpp +++ b/src/special.cpp @@ -261,19 +261,16 @@ Upgrade::collision(void* p_c_object, int c_object) pplayer->base.y += 32; pplayer->duck = true; } - timer_start(&super_bkgd_timer, 350); } else if (kind == UPGRADE_COFFEE) { play_sound(sounds[SND_COFFEE], SOUND_CENTER_SPEAKER); pplayer->got_coffee = true; - timer_start(&super_bkgd_timer, 250); } else if (kind == UPGRADE_HERRING) { play_sound(sounds[SND_HERRING], SOUND_CENTER_SPEAKER); timer_start(&pplayer->invincible_timer,TUX_INVINCIBLE_TIME); - timer_start(&super_bkgd_timer, 250); /* play the herring song ^^ */ if (get_current_music() != HURRYUP_MUSIC) { diff --git a/src/world.cpp b/src/world.cpp index d4188cd6d..57d1b8a50 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -56,8 +56,7 @@ World::set_defaults() // Set defaults: scroll_x = 0; - score_multiplier = 1; - timer_init(&super_bkgd_timer, true); + player_status.score_multiplier = 1; counting_distros = false; distro_counter = 0; @@ -128,24 +127,18 @@ World::draw() { int y,x; - /* Draw screen: */ - if(timer_check(&super_bkgd_timer)) - texture_draw(&img_super_bkgd, 0, 0); + /* Draw the real background */ + if(get_level()->bkgd_image[0] != '\0') + { + int s = (int)scroll_x / 30; + texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h); + texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h); + } else { - /* Draw the real background */ - if(get_level()->bkgd_image[0] != '\0') - { - int s = (int)scroll_x / 30; - texture_draw_part(&level->img_bkgd, s, 0,0,0,level->img_bkgd.w - s, level->img_bkgd.h); - texture_draw_part(&level->img_bkgd, 0, 0,screen->w - s ,0,s,level->img_bkgd.h); - } - else - { - clearscreen(level->bkgd_red, level->bkgd_green, level->bkgd_blue); - } + clearscreen(level->bkgd_red, level->bkgd_green, level->bkgd_blue); } - + /* Draw particle systems (background) */ std::vector::iterator p; for(p = particle_systems.begin(); p != particle_systems.end(); ++p) @@ -346,7 +339,7 @@ World::collision_handler() void World::add_score(float x, float y, int s) { - score += s; + player_status.score += s; FloatingScore new_floating_score; new_floating_score.init(x,y,s); @@ -439,8 +432,8 @@ World::trybreakbrick(float x, float y, bool small) plevel->change(x, y, TM_IA, tile->next_tile); play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); - score = score + SCORE_DISTRO; - distros++; + player_status.score = player_status.score + SCORE_DISTRO; + player_status.distros++; } else if (!small) { @@ -454,7 +447,7 @@ World::trybreakbrick(float x, float y, bool small) /* Get some score: */ play_sound(sounds[SND_BRICK], SOUND_CENTER_SPEAKER); - score = score + SCORE_BRICK; + player_status.score = player_status.score + SCORE_BRICK; } } } @@ -478,8 +471,8 @@ World::tryemptybox(float x, float y, int col_side) case 1: // Box with a distro! add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32 - 32); play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); - score = score + SCORE_DISTRO; - distros++; + player_status.score = player_status.score + SCORE_DISTRO; + player_status.distros++; break; case 2: // Add an upgrade! @@ -517,8 +510,8 @@ World::trygrabdistro(float x, float y, int bounciness) (int)(y / 32) * 32); } - score = score + SCORE_DISTRO; - distros++; + player_status.score = player_status.score + SCORE_DISTRO; + player_status.distros++; } }