From: Ingo Ruhnke Date: Sun, 11 Apr 2004 12:37:40 +0000 (+0000) Subject: - moved some more stuff into the world class X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=37a568a4a57516a0fea5a5972acd2310e49ff769;p=supertux.git - moved some more stuff into the world class - turned gameobjs into classes SVN-Revision: 469 --- diff --git a/src/badguy.cpp b/src/badguy.cpp index 723dd3042..f1c5df606 100644 --- a/src/badguy.cpp +++ b/src/badguy.cpp @@ -373,11 +373,11 @@ BadGuy::fall() void BadGuy::remove_me() { - for(std::vector::iterator i = world.bad_guys.begin(); - i != world.bad_guys.end(); ++i) + for(std::vector::iterator i = World::current()->bad_guys.begin(); + i != World::current()->bad_guys.end(); ++i) { if( & (*i) == this) { - world.bad_guys.erase(i); + World::current()->bad_guys.erase(i); return; } } @@ -785,7 +785,7 @@ BadGuy::squish_me(Player* player) { make_player_jump(player); - world.add_score(base.x - scroll_x, base.y, 50 * score_multiplier); + World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier); play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); score_multiplier++; @@ -799,10 +799,10 @@ BadGuy::squish(Player* player) { if(kind == BAD_MRBOMB) { // mrbomb transforms into a bomb now - world.add_bad_guy(base.x, base.y, BAD_BOMB); + World::current()->add_bad_guy(base.x, base.y, BAD_BOMB); make_player_jump(player); - world.add_score(base.x - scroll_x, base.y, 50 * score_multiplier); + World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier); play_sound(sounds[SND_SQUISH], SOUND_CENTER_SPEAKER); score_multiplier++; @@ -843,13 +843,13 @@ BadGuy::squish(Player* player) make_player_jump(player); - world.add_score(base.x - scroll_x, base.y, 25 * score_multiplier); + World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier); score_multiplier++; return; } else if(kind == BAD_FISH) { make_player_jump(player); - world.add_score(base.x - scroll_x, base.y, 25 * score_multiplier); + World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier); score_multiplier++; // simply remove the fish... @@ -887,10 +887,10 @@ BadGuy::kill_me() /* Gain some points: */ if (kind == BAD_BSOD) - world.add_score(base.x - scroll_x, base.y, + World::current()->add_score(base.x - scroll_x, base.y, 50 * score_multiplier); else - world.add_score(base.x - scroll_x, base.y, + World::current()->add_score(base.x - scroll_x, base.y, 25 * score_multiplier); /* Play death sound: */ diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index f16630579..0257db330 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -1,55 +1,80 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include "world.h" #include "tile.h" #include "gameloop.h" #include "gameobjs.h" -void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y) +void +bouncy_distro_type::init(float x, float y) { - pbouncy_distro->base.x = x; - pbouncy_distro->base.y = y; - pbouncy_distro->base.ym = -2; + base.x = x; + base.y = y; + base.ym = -2; } -void bouncy_distro_action(bouncy_distro_type* pbouncy_distro) +void +bouncy_distro_type::action() { - pbouncy_distro->base.y = pbouncy_distro->base.y + pbouncy_distro->base.ym * frame_ratio; + base.y = base.y + base.ym * frame_ratio; - pbouncy_distro->base.ym += 0.1 * frame_ratio; + base.ym += 0.1 * frame_ratio; - if (pbouncy_distro->base.ym >= 0) - world.bouncy_distros.erase(static_cast::iterator>(pbouncy_distro)); + if (base.ym >= 0) + world.bouncy_distros.erase(static_cast::iterator>(this)); } -void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro) +void +bouncy_distro_type::draw() { texture_draw(&img_distro[0], - pbouncy_distro->base.x - scroll_x, - pbouncy_distro->base.y); + base.x - scroll_x, + base.y); } -void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, - float x, float y, float xm, float ym) + +void +broken_brick_type::init(Tile* tile_, float x, float y, float xm, float ym) { - pbroken_brick->tile = tile; - pbroken_brick->base.x = x; - pbroken_brick->base.y = y; - pbroken_brick->base.xm = xm; - pbroken_brick->base.ym = ym; - - timer_init(&pbroken_brick->timer, true); - timer_start(&pbroken_brick->timer,200); + tile = tile_; + base.x = x; + base.y = y; + base.xm = xm; + base.ym = ym; + + timer_init(&timer, true); + timer_start(&timer,200); } -void broken_brick_action(broken_brick_type* pbroken_brick) +void +broken_brick_type::action() { - pbroken_brick->base.x = pbroken_brick->base.x + pbroken_brick->base.xm * frame_ratio; - pbroken_brick->base.y = pbroken_brick->base.y + pbroken_brick->base.ym * frame_ratio; + base.x = base.x + base.xm * frame_ratio; + base.y = base.y + base.ym * frame_ratio; - if (!timer_check(&pbroken_brick->timer)) - world.broken_bricks.erase(static_cast::iterator>(pbroken_brick)); + if (!timer_check(&timer)) + world.broken_bricks.erase(static_cast::iterator>(this)); } -void broken_brick_draw(broken_brick_type* pbroken_brick) +void +broken_brick_type::draw() { SDL_Rect src, dest; src.x = rand() % 16; @@ -57,63 +82,63 @@ void broken_brick_draw(broken_brick_type* pbroken_brick) src.w = 16; src.h = 16; - dest.x = (int)(pbroken_brick->base.x - scroll_x); - dest.y = (int)pbroken_brick->base.y; + dest.x = (int)(base.x - scroll_x); + dest.y = (int)base.y; dest.w = 16; dest.h = 16; - if (pbroken_brick->tile->images.size() > 0) - texture_draw_part(&pbroken_brick->tile->images[0], + if (tile->images.size() > 0) + texture_draw_part(&tile->images[0], src.x,src.y,dest.x,dest.y,dest.w,dest.h); } -void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y) +void +bouncy_brick_type::init(float x, float y) { - pbouncy_brick->base.x = x; - pbouncy_brick->base.y = y; - pbouncy_brick->offset = 0; - pbouncy_brick->offset_m = -BOUNCY_BRICK_SPEED; - pbouncy_brick->shape = GameSession::current()->get_level()->gettileid(x, y); + base.x = x; + base.y = y; + offset = 0; + offset_m = -BOUNCY_BRICK_SPEED; + shape = World::current()->get_level()->gettileid(x, y); } -void bouncy_brick_action(bouncy_brick_type* pbouncy_brick) +void +bouncy_brick_type::action() { - - pbouncy_brick->offset = (pbouncy_brick->offset + - pbouncy_brick->offset_m * frame_ratio); + offset = (offset + + offset_m * frame_ratio); /* Go back down? */ - - if (pbouncy_brick->offset < -BOUNCY_BRICK_MAX_OFFSET) - pbouncy_brick->offset_m = BOUNCY_BRICK_SPEED; + if (offset < -BOUNCY_BRICK_MAX_OFFSET) + offset_m = BOUNCY_BRICK_SPEED; /* Stop bouncing? */ - - if (pbouncy_brick->offset >= 0) - world.bouncy_bricks.erase(static_cast::iterator>(pbouncy_brick)); + if (offset >= 0) + world.bouncy_bricks.erase(static_cast::iterator>(this)); } -void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick) +void +bouncy_brick_type::draw() { int s; SDL_Rect dest; - if (pbouncy_brick->base.x >= scroll_x - 32 && - pbouncy_brick->base.x <= scroll_x + screen->w) + if (base.x >= scroll_x - 32 && + base.x <= scroll_x + screen->w) { - dest.x = (int)(pbouncy_brick->base.x - scroll_x); - dest.y = (int)pbouncy_brick->base.y; + dest.x = (int)(base.x - scroll_x); + dest.y = (int)base.y; dest.w = 32; dest.h = 32; - Level* plevel = GameSession::current()->get_level(); + Level* plevel = World::current()->get_level(); // FIXME: overdrawing hack to clean the tile from the screen to // paint it later at on offseted position if(plevel->bkgd_image[0] == '\0') { - fillrect(pbouncy_brick->base.x - scroll_x, pbouncy_brick->base.y, + fillrect(base.x - scroll_x, base.y, 32,32, plevel->bkgd_red, plevel->bkgd_green, plevel->bkgd_blue, 0); } @@ -124,34 +149,37 @@ void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick) dest.x, dest.y,dest.w,dest.h); } - Tile::draw(pbouncy_brick->base.x - scroll_x, - pbouncy_brick->base.y + pbouncy_brick->offset, - pbouncy_brick->shape); + Tile::draw(base.x - scroll_x, + base.y + offset, + shape); } } -void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s) +void +floating_score_type::init(float x, float y, int s) { - pfloating_score->base.x = x; - pfloating_score->base.y = y - 16; - timer_init(&pfloating_score->timer,true); - timer_start(&pfloating_score->timer,1000); - pfloating_score->value = s; + base.x = x; + base.y = y - 16; + timer_init(&timer,true); + timer_start(&timer,1000); + value = s; } -void floating_score_action(floating_score_type* pfloating_score) +void +floating_score_type::action() { - pfloating_score->base.y = pfloating_score->base.y - 2 * frame_ratio; + base.y = base.y - 2 * frame_ratio; - if(!timer_check(&pfloating_score->timer)) - world.floating_scores.erase(static_cast::iterator>(pfloating_score)); + if(!timer_check(&timer)) + world.floating_scores.erase(static_cast::iterator>(this)); } -void floating_score_draw(floating_score_type* pfloating_score) +void +floating_score_type::draw() { char str[10]; - sprintf(str, "%d", pfloating_score->value); - text_draw(&gold_text, str, (int)pfloating_score->base.x + 16 - strlen(str) * 8, (int)pfloating_score->base.y, 1); + sprintf(str, "%d", value); + text_draw(&gold_text, str, (int)base.x + 16 - strlen(str) * 8, (int)base.y, 1); } /* EOF */ diff --git a/src/gameobjs.h b/src/gameobjs.h index 2e24a34bf..c279e4c7e 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -1,3 +1,21 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SUPERTUX_GAMEOBJS_H #define SUPERTUX_GAMEOBJS_H @@ -15,15 +33,14 @@ class bouncy_distro_type { public: base_type base; + + void init(float x, float y); + void action(); + void draw(); }; extern texture_type img_distro[4]; -void bouncy_distro_init(bouncy_distro_type* pbouncy_distro, float x, float y); -void bouncy_distro_action(bouncy_distro_type* pbouncy_distro); -void bouncy_distro_draw(bouncy_distro_type* pbouncy_distro); -void bouncy_distro_collision(bouncy_distro_type* pbouncy_distro, int c_object); - #define BOUNCY_BRICK_MAX_OFFSET 8 #define BOUNCY_BRICK_SPEED 0.9 @@ -35,12 +52,11 @@ class broken_brick_type base_type base; timer_type timer; Tile* tile; -}; -void broken_brick_init(broken_brick_type* pbroken_brick, Tile* tile, - float x, float y, float xm, float ym); -void broken_brick_action(broken_brick_type* pbroken_brick); -void broken_brick_draw(broken_brick_type* pbroken_brick); + void init(Tile* tile, float x, float y, float xm, float ym); + void action(); + void draw(); +}; class bouncy_brick_type { @@ -49,11 +65,11 @@ class bouncy_brick_type float offset_m; int shape; base_type base; -}; -void bouncy_brick_init(bouncy_brick_type* pbouncy_brick, float x, float y); -void bouncy_brick_action(bouncy_brick_type* pbouncy_brick); -void bouncy_brick_draw(bouncy_brick_type* pbouncy_brick); + void init(float x, float y); + void action(); + void draw(); +}; class floating_score_type { @@ -61,12 +77,12 @@ class floating_score_type int value; timer_type timer; base_type base; + + void init(float x, float y, int s); + void action(); + void draw(); }; -void floating_score_init(floating_score_type* pfloating_score, float x, float y, int s); -void floating_score_action(floating_score_type* pfloating_score); -void floating_score_draw(floating_score_type* pfloating_score); - #endif /* Local Variables: */ diff --git a/src/player.cpp b/src/player.cpp index 529fe3e51..18b2b1c6b 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -208,26 +208,26 @@ Player::action() if (isbrick(base.x, base.y) || isfullbox(base.x, base.y)) { - trygrabdistro(base.x, base.y - 32,BOUNCE); - trybumpbadguy(base.x, base.y - 64); + World::current()->trygrabdistro(base.x, base.y - 32,BOUNCE); + World::current()->trybumpbadguy(base.x, base.y - 64); - trybreakbrick(base.x, base.y, size == SMALL); + World::current()->trybreakbrick(base.x, base.y, size == SMALL); bumpbrick(base.x, base.y); - tryemptybox(base.x, base.y, RIGHT); + World::current()->tryemptybox(base.x, base.y, RIGHT); } if (isbrick(base.x+ 31, base.y) || isfullbox(base.x+ 31, base.y)) { - trygrabdistro(base.x+ 31, base.y - 32,BOUNCE); - trybumpbadguy(base.x+ 31, base.y - 64); + World::current()->trygrabdistro(base.x+ 31, base.y - 32,BOUNCE); + World::current()->trybumpbadguy(base.x+ 31, base.y - 64); if(size == BIG) - trybreakbrick(base.x+ 31, base.y, size == SMALL); + World::current()->trybreakbrick(base.x+ 31, base.y, size == SMALL); bumpbrick(base.x+ 31, base.y); - tryemptybox(base.x+ 31, base.y, LEFT); + World::current()->tryemptybox(base.x+ 31, base.y, LEFT); } } @@ -478,7 +478,7 @@ Player::handle_input() if (input.fire == DOWN && input.old_fire == UP && got_coffee) { - world.add_bullet(base.x, base.y, physic.get_velocity_x(), dir); + World::current()->add_bullet(base.x, base.y, physic.get_velocity_x(), dir); } @@ -551,16 +551,16 @@ Player::grabdistros() /* Grab distros: */ if (!dying) { - trygrabdistro(base.x, base.y, NO_BOUNCE); - trygrabdistro(base.x+ 31, base.y, NO_BOUNCE); + World::current()->trygrabdistro(base.x, base.y, NO_BOUNCE); + World::current()->trygrabdistro(base.x+ 31, base.y, NO_BOUNCE); - trygrabdistro(base.x, base.y + base.height, NO_BOUNCE); - trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE); + World::current()->trygrabdistro(base.x, base.y + base.height, NO_BOUNCE); + World::current()->trygrabdistro(base.x+ 31, base.y + base.height, NO_BOUNCE); if(size == BIG) { - trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE); - trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE); + World::current()->trygrabdistro(base.x, base.y + base.height / 2, NO_BOUNCE); + World::current()->trygrabdistro(base.x+ 31, base.y + base.height / 2, NO_BOUNCE); } } @@ -827,9 +827,9 @@ Player::collision(void* p_c_object, int c_object) { pbad_c->dying = DYING_FALLING; play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER); - world.add_score(pbad_c->base.x - scroll_x, - pbad_c->base.y, - 25 * score_multiplier); + World::current()->add_score(pbad_c->base.x - scroll_x, + pbad_c->base.y, + 25 * score_multiplier); } } } diff --git a/src/resources.cpp b/src/resources.cpp index 7aee6bf83..4fe074040 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -364,4 +364,3 @@ void unloadshared(void) } /* EOF */ - diff --git a/src/world.cpp b/src/world.cpp index 96780b9e7..6c879f16b 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1,14 +1,21 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details // -// C Implementation: world -// -// Description: -// -// -// Author: Tobias Glaesser , (C) 2004 -// -// Copyright: See COPYING file that comes with this distribution -// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. // +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include @@ -168,7 +175,7 @@ World::draw() /* (Bouncy bricks): */ for (unsigned int i = 0; i < bouncy_bricks.size(); ++i) - bouncy_brick_draw(&bouncy_bricks[i]); + bouncy_bricks[i].draw(); for (unsigned int i = 0; i < bad_guys.size(); ++i) bad_guys[i].draw(); @@ -179,16 +186,16 @@ World::draw() bullet_draw(&bullets[i]); for (unsigned int i = 0; i < floating_scores.size(); ++i) - floating_score_draw(&floating_scores[i]); + floating_scores[i].draw(); for (unsigned int i = 0; i < upgrades.size(); ++i) upgrade_draw(&upgrades[i]); for (unsigned int i = 0; i < bouncy_distros.size(); ++i) - bouncy_distro_draw(&bouncy_distros[i]); + bouncy_distros[i].draw(); for (unsigned int i = 0; i < broken_bricks.size(); ++i) - broken_brick_draw(&broken_bricks[i]); + broken_bricks[i].draw(); /* Draw foreground: */ for (y = 0; y < 15; ++y) @@ -212,11 +219,11 @@ World::action() { /* Handle bouncy distros: */ for (unsigned int i = 0; i < bouncy_distros.size(); i++) - bouncy_distro_action(&bouncy_distros[i]); + bouncy_distros[i].action(); /* Handle broken bricks: */ for (unsigned int i = 0; i < broken_bricks.size(); i++) - broken_brick_action(&broken_bricks[i]); + broken_bricks[i].action(); /* Handle distro counting: */ if (counting_distros) @@ -229,10 +236,10 @@ World::action() // Handle all kinds of game objects for (unsigned int i = 0; i < bouncy_bricks.size(); i++) - bouncy_brick_action(&bouncy_bricks[i]); + bouncy_bricks[i].action(); for (unsigned int i = 0; i < floating_scores.size(); i++) - floating_score_action(&floating_scores[i]); + floating_scores[i].action(); for (unsigned int i = 0; i < bullets.size(); ++i) bullet_action(&bullets[i]); @@ -250,7 +257,7 @@ World::add_score(float x, float y, int s) score += s; floating_score_type new_floating_score; - floating_score_init(&new_floating_score,x,y,s); +new_floating_score.init(x,y,s); floating_scores.push_back(new_floating_score); } @@ -258,7 +265,7 @@ void World::add_bouncy_distro(float x, float y) { bouncy_distro_type new_bouncy_distro; - bouncy_distro_init(&new_bouncy_distro,x,y); + new_bouncy_distro.init(x,y); bouncy_distros.push_back(new_bouncy_distro); } @@ -276,7 +283,7 @@ void World::add_broken_brick_piece(Tile* tile, float x, float y, float xm, float ym) { broken_brick_type new_broken_brick; - broken_brick_init(&new_broken_brick, tile, x, y, xm, ym); + new_broken_brick.init(tile, x, y, xm, ym); broken_bricks.push_back(new_broken_brick); } @@ -284,7 +291,7 @@ void World::add_bouncy_brick(float x, float y) { bouncy_brick_type new_bouncy_brick; - bouncy_brick_init(&new_bouncy_brick,x,y); + new_bouncy_brick.init(x,y); bouncy_bricks.push_back(new_bouncy_brick); } @@ -316,9 +323,10 @@ World::add_bullet(float x, float y, float xm, int dir) } /* Break a brick: */ -void trybreakbrick(float x, float y, bool small) +void +World::trybreakbrick(float x, float y, bool small) { - Level* plevel = World::current()->get_level(); + Level* plevel = get_level(); Tile* tile = gettile(x, y); if (tile->brick) @@ -326,7 +334,7 @@ void trybreakbrick(float x, float y, bool small) if (tile->data > 0) { /* Get a distro from it: */ - world.add_bouncy_distro(((int)(x + 1) / 32) * 32, + add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32); if (!counting_distros) @@ -348,7 +356,7 @@ void trybreakbrick(float x, float y, bool small) plevel->change(x, y, TM_IA, tile->next_tile); /* Replace it with broken bits: */ - world.add_broken_brick(tile, + add_broken_brick(tile, ((int)(x + 1) / 32) * 32, (int)(y / 32) * 32); @@ -360,10 +368,9 @@ void trybreakbrick(float x, float y, bool small) } /* Empty a box: */ -void tryemptybox(float x, float y, int col_side) +void +World::tryemptybox(float x, float y, int col_side) { - Level* plevel = World::current()->get_level(); - Tile* tile = gettile(x,y); if (!tile->fullbox) return; @@ -376,45 +383,45 @@ void tryemptybox(float x, float y, int col_side) switch(tile->data) { - case 1: //'A': /* Box with a distro! */ - world.add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32 - 32); + 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++; break; - case 2: // 'B': /* Add an upgrade! */ + case 2: // Add an upgrade! if (tux.size == SMALL) /* Tux is small, add mints! */ - world.add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_MINTS); + add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_MINTS); else /* Tux is big, add coffee: */ - world.add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_COFFEE); + add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_COFFEE); play_sound(sounds[SND_UPGRADE], SOUND_CENTER_SPEAKER); break; - case 3:// '!': /* Add a golden herring */ - world.add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_HERRING); + case 3: // Add a golden herring + add_upgrade((int)((x + 1) / 32) * 32, (int)(y / 32) * 32 - 32, col_side, UPGRADE_HERRING); break; default: break; } /* Empty the box: */ - plevel->change(x, y, TM_IA, tile->next_tile); + level->change(x, y, TM_IA, tile->next_tile); } /* Try to grab a distro: */ -void trygrabdistro(float x, float y, int bounciness) +void +World::trygrabdistro(float x, float y, int bounciness) { - Level* plevel = World::current()->get_level(); Tile* tile = gettile(x, y); if (tile && tile->distro) { - plevel->change(x, y, TM_IA, tile->next_tile); + level->change(x, y, TM_IA, tile->next_tile); play_sound(sounds[SND_DISTRO], SOUND_CENTER_SPEAKER); if (bounciness == BOUNCE) { - world.add_bouncy_distro(((int)(x + 1) / 32) * 32, + add_bouncy_distro(((int)(x + 1) / 32) * 32, (int)(y / 32) * 32); } @@ -424,28 +431,29 @@ void trygrabdistro(float x, float y, int bounciness) } /* Try to bump a bad guy from below: */ -void trybumpbadguy(float x, float y) +void +World::trybumpbadguy(float x, float y) { /* Bad guys: */ - for (unsigned int i = 0; i < world.bad_guys.size(); i++) + for (unsigned int i = 0; i < bad_guys.size(); i++) { - if (world.bad_guys[i].base.x >= x - 32 && world.bad_guys[i].base.x <= x + 32 && - world.bad_guys[i].base.y >= y - 16 && world.bad_guys[i].base.y <= y + 16) + if (bad_guys[i].base.x >= x - 32 && bad_guys[i].base.x <= x + 32 && + bad_guys[i].base.y >= y - 16 && bad_guys[i].base.y <= y + 16) { - world.bad_guys[i].collision(&tux, CO_PLAYER, COLLISION_BUMP); + bad_guys[i].collision(&tux, CO_PLAYER, COLLISION_BUMP); } } /* Upgrades: */ - for (unsigned int i = 0; i < world.upgrades.size(); i++) + for (unsigned int i = 0; i < upgrades.size(); i++) { - if (world.upgrades[i].base.height == 32 && - world.upgrades[i].base.x >= x - 32 && world.upgrades[i].base.x <= x + 32 && - world.upgrades[i].base.y >= y - 16 && world.upgrades[i].base.y <= y + 16) + if (upgrades[i].base.height == 32 && + upgrades[i].base.x >= x - 32 && upgrades[i].base.x <= x + 32 && + upgrades[i].base.y >= y - 16 && upgrades[i].base.y <= y + 16) { - world.upgrades[i].base.xm = -world.upgrades[i].base.xm; - world.upgrades[i].base.ym = -8; + upgrades[i].base.xm = -upgrades[i].base.xm; + upgrades[i].base.ym = -8; play_sound(sounds[SND_BUMP_UPGRADE], SOUND_CENTER_SPEAKER); } } diff --git a/src/world.h b/src/world.h index e0137b949..c29e769a7 100644 --- a/src/world.h +++ b/src/world.h @@ -1,14 +1,21 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2004 SuperTux Development Team, see AUTHORS for details // -// Interface: world -// -// Description: -// -// -// Author: Tobias Glaesser , (C) 2003 -// -// Copyright: See COPYING file that comes with this distribution -// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. // +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifndef SUPERTUX_WORLD_H #define SUPERTUX_WORLD_H @@ -21,20 +28,6 @@ #include "particlesystem.h" #include "gameobjs.h" -/** Try to grab the coin at the given coordinates */ -void trygrabdistro(float x, float y, int bounciness); - -/** Try to break the brick at the given coordinates */ -void trybreakbrick(float x, float y, bool small); - -/** Try to get the content out of a bonus box, thus emptying it */ -void tryemptybox(float x, float y, int col_side); - -/** Try to bumb a badguy that might we walking above Tux, thus shaking - the tile which the badguy is walking on an killing him this way */ -void trybumpbadguy(float x, float y); - - /** The World class holds a level and all the game objects (badguys, bouncy distros, etc) that are needed to run a game. */ class World @@ -86,6 +79,19 @@ class World void add_bad_guy(float x, float y, BadGuyKind kind); void add_upgrade(float x, float y, int dir, int kind); void add_bullet(float x, float y, float xm, int dir); + + /** Try to grab the coin at the given coordinates */ + void trygrabdistro(float x, float y, int bounciness); + + /** Try to break the brick at the given coordinates */ + void trybreakbrick(float x, float y, bool small); + + /** Try to get the content out of a bonus box, thus emptying it */ + void tryemptybox(float x, float y, int col_side); + + /** Try to bumb a badguy that might we walking above Tux, thus shaking + the tile which the badguy is walking on an killing him this way */ + void trybumpbadguy(float x, float y); }; extern World world;