[Super-tux-commit] supertux/src badguy.cpp,1.64,1.65 badguy.h,1.36,1.37 button.cpp,1.17,1.18 button.
Brought to you by:
wkendrick
From: Tobias Gl??er <to...@us...> - 2004-05-02 21:28:42
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14773/src Modified Files: badguy.cpp badguy.h button.cpp button.h gameobjs.h leveleditor.cpp player.h special.h title.cpp type.h world.cpp Log Message: leveleditor related improvements Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player.h,v retrieving revision 1.48 retrieving revision 1.49 diff -u -d -r1.48 -r1.49 --- player.h 30 Apr 2004 09:48:34 -0000 1.48 +++ player.h 2 May 2004 21:28:32 -0000 1.49 @@ -104,7 +104,7 @@ extern PlayerSprite largetux; extern PlayerSprite firetux; -class Player +class Player : public GameObject { public: enum HurtMode { KILL, SHRINK }; @@ -123,8 +123,6 @@ int frame_; int frame_main; - base_type base; - base_type old_base; base_type previous_base; Timer invincible_timer; Timer skidding_timer; @@ -151,6 +149,8 @@ bool under_solid(); void grow(); + std::string type() { return "Player";}; + private: void handle_horizontal_input(); void handle_vertical_input(); Index: type.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/type.h,v retrieving revision 1.14 retrieving revision 1.15 diff -u -d -r1.14 -r1.15 --- type.h 20 Apr 2004 11:09:34 -0000 1.14 +++ type.h 2 May 2004 21:28:32 -0000 1.15 @@ -21,6 +21,7 @@ #ifndef SUPERTUX_TYPE_H #define SUPERTUX_TYPE_H +#include <string> #include "SDL.h" /* 'Base' type for game objects */ @@ -36,6 +37,41 @@ }; +/* Base class for all dynamic game object. */ +class GameObject +{ + +friend bool operator<(const GameObject& lhs, const GameObject& rhs) +{ + if( lhs.base.x < rhs.base.x ) + return true; + else if( lhs.base.x == rhs.base.x && lhs.base.y < rhs.base.y) + return true; + else + return false; +} + +friend bool operator>(const GameObject& lhs, const GameObject& rhs) +{ + if( lhs.base.x > rhs.base.x ) + return true; + else if( lhs.base.x == rhs.base.x && lhs.base.y > rhs.base.y) + return true; + else + return false; +} + +public: +GameObject() {}; +virtual ~GameObject() {}; +virtual void action(double frame_ratio) = 0; +virtual void draw() = 0; +virtual std::string type() = 0; + +base_type base; +base_type old_base; +}; + struct string_list_type { int num_items; Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameobjs.h,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- gameobjs.h 20 Apr 2004 11:09:33 -0000 1.8 +++ gameobjs.h 2 May 2004 21:28:32 -0000 1.9 @@ -31,14 +31,14 @@ #define NO_BOUNCE 0 #define BOUNCE 1 -class BouncyDistro +class BouncyDistro : public GameObject { public: - base_type base; void init(float x, float y); void action(double frame_ratio); void draw(); + std::string type() { return "BouncyDistro"; }; }; extern Surface* img_distro[4]; @@ -48,41 +48,41 @@ class Tile; -class BrokenBrick +class BrokenBrick : public GameObject { public: - base_type base; Timer timer; Tile* tile; void init(Tile* tile, float x, float y, float xm, float ym); void action(double frame_ratio); void draw(); + std::string type() { return "BrokenBrick"; }; }; -class BouncyBrick +class BouncyBrick : public GameObject { public: float offset; float offset_m; int shape; - base_type base; void init(float x, float y); void action(double frame_ratio); void draw(); + std::string type() { return "BouncyBrick"; }; }; -class FloatingScore +class FloatingScore : public GameObject { public: int value; Timer timer; - base_type base; void init(float x, float y, int s); void action(double frame_ratio); void draw(); + std::string type() { return "FloatingScore"; }; }; #endif Index: special.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/special.h,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- special.h 26 Apr 2004 21:09:31 -0000 1.19 +++ special.h 2 May 2004 21:28:32 -0000 1.20 @@ -40,19 +40,20 @@ void load_special_gfx(); void free_special_gfx(); -class Upgrade +class Upgrade : public GameObject { public: UpgradeKind kind; Direction dir; - base_type base; - base_type old_base; Physic physic; void init(float x, float y, Direction dir, UpgradeKind kind); void action(double frame_ratio); void draw(); void collision(void* p_c_object, int c_object, CollisionType type); + std::string type() { return "Upgrade"; }; + + ~Upgrade() {}; private: /** removes the Upgrade from the global upgrade list. Note that after this @@ -64,7 +65,7 @@ void bump(Player* player); }; -class Bullet +class Bullet : public GameObject { public: int life_count; @@ -75,6 +76,7 @@ void action(double frame_ratio); void draw(); void collision(int c_object); + std::string type() { return "Bullet"; }; private: /** removes the Upgrade from the global upgrade list. Note that after this Index: button.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/button.cpp,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- button.cpp 25 Apr 2004 21:55:23 -0000 1.17 +++ button.cpp 2 May 2004 21:28:32 -0000 1.18 @@ -75,6 +75,7 @@ state = BUTTON_NONE; show_info = false; bkgd = NULL; + game_object = NULL; } void Button::change_icon(std::string icon_file, int /*mw*/, int /*mh*/) @@ -109,6 +110,11 @@ bkgd->draw(rect.x,rect.y); } icon->draw(rect.x,rect.y); + if(game_object != NULL) + { + game_object->draw(); + } + if(show_info) { char str[80]; @@ -131,6 +137,7 @@ Button::~Button() { delete icon; + delete game_object; } void Button::event(SDL_Event &event) Index: leveleditor.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/leveleditor.cpp,v retrieving revision 1.74 retrieving revision 1.75 diff -u -d -r1.74 -r1.75 --- leveleditor.cpp 2 May 2004 16:08:22 -0000 1.74 +++ leveleditor.cpp 2 May 2004 21:28:32 -0000 1.75 @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux // Copyright (C) 2003 Ricardo Cruz <ri...@ae...> // Copyright (C) 2003 Tobias Glaesser <tob...@gm...> @@ -13,7 +13,7 @@ // 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. -// [...1765 lines suppressed...] { le_current_level->save("test", le_level); - + GameSession session("test",le_level, ST_GL_TEST); session.run(); player_status.reset(); @@ -1283,8 +1421,8 @@ done_ = 0; while(done_ == 0) - { - done_ = wait_for_event(event); - SDL_Delay(50); - } + { + done_ = wait_for_event(event); + SDL_Delay(50); + } } Index: badguy.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.h,v retrieving revision 1.36 retrieving revision 1.37 diff -u -d -r1.36 -r1.37 --- badguy.h 28 Apr 2004 18:45:24 -0000 1.36 +++ badguy.h 2 May 2004 21:28:32 -0000 1.37 @@ -45,7 +45,8 @@ BAD_BOUNCINGSNOWBALL, BAD_FLYINGSNOWBALL, BAD_SPIKY, - BAD_SNOWBALL + BAD_SNOWBALL, + NUM_BadGuyKinds }; BadGuyKind badguykind_from_string(const std::string& str); @@ -53,24 +54,10 @@ void load_badguy_gfx(); void free_badguy_gfx(); -struct BadGuyData -{ - BadGuyKind kind; - int x; - int y; - bool stay_on_platform; - - BadGuyData(BadGuyKind kind_, int x_, int y_, bool stay_on_platform_) - : kind(kind_), x(x_), y(y_), stay_on_platform(stay_on_platform_) {} - - BadGuyData() - : kind(BAD_SNOWBALL), x(0), y(0), stay_on_platform(false) {} -}; - class Player; /* Badguy type: */ -class BadGuy +class BadGuy : public GameObject { public: /* Enemy modes: */ @@ -95,7 +82,6 @@ }; public: DyingType dying; - base_type base; BadGuyKind kind; BadGuyMode mode; @@ -110,7 +96,6 @@ bool removable; bool seen; int squishcount; /// number of times this enemy was squiched - base_type old_base; Timer timer; Physic physic; @@ -122,8 +107,9 @@ public: BadGuy(float x, float y, BadGuyKind kind, bool stay_on_platform); - void action(float frame_ratio); + void action(double frame_ratio); void draw(); + std::string type() { return "BadGuy"; }; void collision(void* p_c_object, int c_object, CollisionType type = COLLISION_NORMAL); @@ -141,17 +127,17 @@ bool is_removable() const { return removable; } private: - void action_mriceblock(float frame_ratio); - void action_jumpy(float frame_ratio); - void action_bomb(float frame_ratio); - void action_mrbomb(float frame_ratio); - void action_stalactite(float frame_ratio); - void action_flame(float frame_ratio); - void action_fish(float frame_ratio); - void action_bouncingsnowball(float frame_ratio); - void action_flyingsnowball(float frame_ratio); - void action_spiky(float frame_ratio); - void action_snowball(float frame_ratio); + void action_mriceblock(double frame_ratio); + void action_jumpy(double frame_ratio); + void action_bomb(double frame_ratio); + void action_mrbomb(double frame_ratio); + void action_stalactite(double frame_ratio); + void action_flame(double frame_ratio); + void action_fish(double frame_ratio); + void action_bouncingsnowball(double frame_ratio); + void action_flyingsnowball(double frame_ratio); + void action_spiky(double frame_ratio); + void action_snowball(double frame_ratio); /** handles falling down. disables gravity calculation when we're back on * ground */ @@ -174,6 +160,21 @@ void set_sprite(Sprite* left, Sprite* right); }; +struct BadGuyData +{ + BadGuyKind kind; + int x; + int y; + bool stay_on_platform; + + BadGuyData(BadGuy* pbadguy) : kind(pbadguy->kind), x((int)pbadguy->base.x), y((int)pbadguy->base.y), stay_on_platform(pbadguy->stay_on_platform) {}; + BadGuyData(BadGuyKind kind_, int x_, int y_, bool stay_on_platform_) + : kind(kind_), x(x_), y(y_), stay_on_platform(stay_on_platform_) {} + + BadGuyData() + : kind(BAD_SNOWBALL), x(0), y(0), stay_on_platform(false) {} +}; + #endif /*SUPERTUX_BADGUY_H*/ /* Local Variables: */ Index: badguy.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/badguy.cpp,v retrieving revision 1.64 retrieving revision 1.65 diff -u -d -r1.64 -r1.65 --- badguy.cpp 1 May 2004 15:46:08 -0000 1.64 +++ badguy.cpp 2 May 2004 21:28:32 -0000 1.65 @@ -203,7 +203,7 @@ } void -BadGuy::action_mriceblock(float frame_ratio) +BadGuy::action_mriceblock(double frame_ratio) { Player& tux = *World::current()->get_tux(); @@ -374,7 +374,7 @@ } void -BadGuy::action_jumpy(float frame_ratio) +BadGuy::action_jumpy(double frame_ratio) { if (fabsf(physic.get_velocity_y()) < 2.5f) set_sprite(img_jumpy_left_middle, img_jumpy_left_middle); @@ -414,7 +414,7 @@ } void -BadGuy::action_mrbomb(float frame_ratio) +BadGuy::action_mrbomb(double frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(true); @@ -427,7 +427,7 @@ } void -BadGuy::action_bomb(float frame_ratio) +BadGuy::action_bomb(double frame_ratio) { static const int TICKINGTIME = 1000; static const int EXPLODETIME = 1000; @@ -464,7 +464,7 @@ } void -BadGuy::action_stalactite(float frame_ratio) +BadGuy::action_stalactite(double frame_ratio) { Player& tux = *World::current()->get_tux(); @@ -506,7 +506,7 @@ } void -BadGuy::action_flame(float frame_ratio) +BadGuy::action_flame(double frame_ratio) { static const float radius = 100; static const float speed = 0.02; @@ -517,7 +517,7 @@ } void -BadGuy::action_fish(float frame_ratio) +BadGuy::action_fish(double frame_ratio) { static const float JUMPV = 6; static const int WAITTIME = 1000; @@ -550,7 +550,7 @@ } void -BadGuy::action_bouncingsnowball(float frame_ratio) +BadGuy::action_bouncingsnowball(double frame_ratio) { static const float JUMPV = 4.5; @@ -584,7 +584,7 @@ } void -BadGuy::action_flyingsnowball(float frame_ratio) +BadGuy::action_flyingsnowball(double frame_ratio) { static const float FLYINGSPEED = 1; static const int DIRCHANGETIME = 1000; @@ -624,7 +624,7 @@ } void -BadGuy::action_spiky(float frame_ratio) +BadGuy::action_spiky(double frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(); @@ -645,7 +645,7 @@ } void -BadGuy::action_snowball(float frame_ratio) +BadGuy::action_snowball(double frame_ratio) { if (dying == DYING_NOT) check_horizontal_bump(); @@ -658,7 +658,7 @@ } void -BadGuy::action(float frame_ratio) +BadGuy::action(double frame_ratio) { // Remove if it's far off the screen: if (base.x < scroll_x - OFFSCREEN_DISTANCE) @@ -725,6 +725,8 @@ case BAD_SNOWBALL: action_snowball(frame_ratio); break; + default: + break; } } Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.72 retrieving revision 1.73 diff -u -d -r1.72 -r1.73 --- title.cpp 2 May 2004 16:08:22 -0000 1.72 +++ title.cpp 2 May 2004 21:28:32 -0000 1.73 @@ -294,13 +294,6 @@ if (Menu::current() == main_menu) logo->draw( 160, 30); - white_small_text->draw(" SuperTux " VERSION "\n" - "Copyright (c) 2003 SuperTux Devel Team\n" - "This game comes with ABSOLUTELY NO WARRANTY. This is free software, and you\n" - "are welcome to redistribute it under certain conditions; see the file COPYING\n" - "for details.\n", - 0, 420, 0); - /* Don't draw menu, if quit is true */ Menu* menu = Menu::current(); if(menu) Index: world.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/world.cpp,v retrieving revision 1.49 retrieving revision 1.50 diff -u -d -r1.49 -r1.50 --- world.cpp 2 May 2004 15:51:12 -0000 1.49 +++ world.cpp 2 May 2004 21:28:32 -0000 1.50 @@ -297,7 +297,7 @@ /* ++i handled at end of the loop */) { if ((*i)->is_removable()) { delete *i; - i = bad_guys.erase(i); + i = bad_guys.erase(i); } else { ++i; } Index: button.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/button.h,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- button.h 20 Apr 2004 11:09:33 -0000 1.15 +++ button.h 2 May 2004 21:28:32 -0000 1.16 @@ -1,5 +1,5 @@ // $Id$ -// +// // SuperTux // Copyright (C) 2004 Tobias Glaesser <tob...@gm...> // @@ -12,7 +12,7 @@ // 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 @@ -34,49 +34,51 @@ class ButtonPanel; class Button - { - friend class ButtonPanel; +{ + friend class ButtonPanel; - public: - Button(std::string icon_file, std::string info, SDLKey shortcut, int x, int y, int mw = -1, int h = -1); - ~Button(); - void event(SDL_Event& event); - void draw(); - int get_state(); - void change_icon(std::string icon_file, int mw, int mh); - int get_tag() - { - return tag; - } +public: + Button(std::string icon_file, std::string info, SDLKey shortcut, int x, int y, int mw = -1, int h = -1); + ~Button(); + void event(SDL_Event& event); + void draw(); + int get_state(); + void change_icon(std::string icon_file, int mw, int mh); + SDL_Rect get_pos() { return rect; } + int get_tag(){return tag; } + void set_game_object(GameObject* game_object_) { game_object = game_object_; } + GameObject* get_game_object() { return game_object; }; - private: - static Timer popup_timer; - Surface* icon; - Surface* bkgd; - std::string info; - SDLKey shortcut; - SDL_Rect rect; - bool show_info; - ButtonState state; - int tag; - }; +private: + static Timer popup_timer; + GameObject* game_object; + Surface* icon; + Surface* bkgd; + std::string info; + SDLKey shortcut; + SDL_Rect rect; + bool show_info; + ButtonState state; + int tag; +}; class ButtonPanel - { - public: - ButtonPanel(int x, int y, int w, int h); - ~ButtonPanel(); - void draw(); - Button* event(SDL_Event &event); - void additem(Button* pbutton, int tag); - Button* button_panel_event(SDL_Event& event); - void set_button_size(int w, int h) { bw = w; bh = h; } +{ +public: + ButtonPanel(int x, int y, int w, int h); + ~ButtonPanel(); + void draw(); + Button* event(SDL_Event &event); + void additem(Button* pbutton, int tag); + Button* button_panel_event(SDL_Event& event); + void set_button_size(int w, int h) { bw = w; bh = h; } + Button* manipulate_button(int i) { if(item.size()-1 < i) { return item[item.size()-1]; } else { return item[i]; } }; - private: - int bw, bh; - bool hidden; - SDL_Rect rect; - std::vector<Button*> item; - }; +private: + int bw, bh; + bool hidden; + SDL_Rect rect; + std::vector<Button*> item; +}; #endif /*SUPERTUX_BUTTON_H*/ |