From: Ricardo Cruz Date: Thu, 5 Aug 2004 10:10:19 +0000 (+0000) Subject: Made the stomp cloud to have an independent movement from Tux by making it a GameObject. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c1f63ef63bb685e2379e280684049bf9bc733dd4;p=supertux.git Made the stomp cloud to have an independent movement from Tux by making it a GameObject. Next time, please don't implement it, unless you do it properly. SVN-Revision: 1705 --- diff --git a/src/gameobjs.cpp b/src/gameobjs.cpp index cb3984d4c..2bde3cbb8 100644 --- a/src/gameobjs.cpp +++ b/src/gameobjs.cpp @@ -181,7 +181,7 @@ Trampoline::write(LispWriter& writer) void Trampoline::draw(DrawingContext& context) { - img_trampoline[frame]->draw(context, Vector(base.x, base.y), LAYER_OBJECTS); + img_trampoline[frame]->draw(context, base, LAYER_OBJECTS); frame = 0; } @@ -336,7 +336,7 @@ FlyingPlatform::write(LispWriter& writer) void FlyingPlatform::draw(DrawingContext& context) { - img_flying_platform->draw(context, Vector(base.x, base.y), LAYER_OBJECTS); + img_flying_platform->draw(context, base, LAYER_OBJECTS); } void @@ -413,6 +413,29 @@ FlyingPlatform::collision(void *p_c_object, int c_object, CollisionType type) } } +Sprite *img_smoke_cloud; + +SmokeCloud::SmokeCloud(const Vector& pos) + : position(pos) +{ + timer.start(250); +} + +void +SmokeCloud::action(float elapsed_time) +{ + position.y -= 2 * elapsed_time; + + if(!timer.check()) + remove_me(); +} + +void +SmokeCloud::draw(DrawingContext& context) +{ + img_smoke_cloud->draw(context, position, LAYER_OBJECTS+1); +} + void load_object_gfx() { char sprite_name[16]; @@ -424,4 +447,6 @@ void load_object_gfx() } img_flying_platform = sprite_manager->load("flying_platform"); + + img_smoke_cloud = sprite_manager->load("stomp"); } diff --git a/src/gameobjs.h b/src/gameobjs.h index fd89dfdc1..9112cae0c 100644 --- a/src/gameobjs.h +++ b/src/gameobjs.h @@ -162,6 +162,21 @@ public: unsigned int frame; }; +extern Sprite *img_smoke_cloud; + +class SmokeCloud : public GameObject +{ +public: + SmokeCloud(const Vector& pos); + + virtual void action(float elapsed_time); + virtual void draw(DrawingContext& context); + +private: + Timer timer; + Vector position; +}; + void load_object_gfx(); #endif diff --git a/src/player.cpp b/src/player.cpp index 84d2f023f..c3170b3df 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -40,7 +40,6 @@ #define TILES_FOR_BUTTJUMP 3 // animation times (in ms): #define SHOOTING_TIME 320 -#define STOMP_TIME 250 // others stuff: #define AUTOSCROLL_DEAD_INTERVAL 300 @@ -118,7 +117,6 @@ Player::init() can_jump = true; butt_jump = false; - stomp_pos = Vector(0,0); frame_main = 0; frame_ = 0; @@ -510,12 +508,11 @@ Player::handle_vertical_input() // Do butt jump if (butt_jump && on_ground() && size == BIG) { - + // Add a smoke cloud if (duck) - stomp_pos = Vector(base.x - 32, base.y); + Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y)); else - stomp_pos = Vector(base.x - 32, base.y + 32); - stomp_timer.start(STOMP_TIME); + Sector::current()->add_smoke_cloud(Vector(base.x - 32, base.y + 32)); butt_jump = false; @@ -774,10 +771,6 @@ Player::draw(DrawingContext& context) sprite->grab_left->draw(context, pos, LAYER_OBJECTS + 1); } - // Draw stomp clouds when doing a butt jump - if (stomp_timer.check()) - sprite->stomp->draw(context, stomp_pos, LAYER_OBJECTS + 1); - // Draw blinking star overlay if (invincible_timer.started() && (invincible_timer.get_left() > TUX_INVINCIBLE_TIME_WARNING || global_frame_counter % 3)) diff --git a/src/player.h b/src/player.h index 6b1133e64..6555527d7 100644 --- a/src/player.h +++ b/src/player.h @@ -119,7 +119,6 @@ struct PlayerSprite Sprite* grab_right; Sprite* duck_right; Sprite* duck_left; - Sprite* stomp; }; extern PlayerSprite smalltux; @@ -163,11 +162,8 @@ public: Timer shooting_timer; // used to show the arm when Tux is shooting Timer dying_timer; Timer growing_timer; - Timer stomp_timer; Physic physic; - Vector stomp_pos; - public: Player(); virtual ~Player(); diff --git a/src/resources.cpp b/src/resources.cpp index 427a95017..1664f20e8 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -143,7 +143,6 @@ void loadshared() smalltux.skid_right = sprite_manager->load("smalltux-skid-right"); smalltux.grab_left = sprite_manager->load("smalltux-grab-left"); smalltux.grab_right = sprite_manager->load("smalltux-grab-right"); - smalltux.stomp = sprite_manager->load("stomp"); largetux.stand_left = sprite_manager->load("largetux-stand-left"); largetux.stand_right = sprite_manager->load("largetux-stand-right"); @@ -159,7 +158,6 @@ void loadshared() largetux.grab_right = sprite_manager->load("largetux-grab-right"); largetux.duck_left = sprite_manager->load("largetux-duck-left"); largetux.duck_right = sprite_manager->load("largetux-duck-right"); - largetux.stomp = sprite_manager->load("stomp"); firetux.stand_left = sprite_manager->load("firetux-stand-left"); firetux.stand_right = sprite_manager->load("firetux-stand-right"); @@ -175,7 +173,6 @@ void loadshared() firetux.grab_right = sprite_manager->load("firetux-grab-right"); firetux.duck_left = sprite_manager->load("firetux-duck-left"); firetux.duck_right = sprite_manager->load("firetux-duck-right"); - firetux.stomp = sprite_manager->load("stomp"); icetux.stand_left = sprite_manager->load("icetux-stand-left"); icetux.stand_right = sprite_manager->load("icetux-stand-right"); @@ -191,8 +188,6 @@ void loadshared() icetux.grab_right = sprite_manager->load("icetux-grab-right"); icetux.duck_left = sprite_manager->load("icetux-duck-left"); icetux.duck_right = sprite_manager->load("icetux-duck-right"); - icetux.stomp = sprite_manager->load("stomp"); - /* Water: */ img_water = new Surface(datadir + "/images/shared/water.png", false); diff --git a/src/sector.cpp b/src/sector.cpp index a108e3065..f534f41fd 100644 --- a/src/sector.cpp +++ b/src/sector.cpp @@ -423,6 +423,12 @@ Sector::update_game_objects() std::remove(flying_platforms.begin(), flying_platforms.end(), flying_platform), flying_platforms.end()); } + SmokeCloud* smoke_cloud = dynamic_cast (*i); + if(smoke_cloud) { + smoke_clouds.erase( + std::remove(smoke_clouds.begin(), smoke_clouds.end(), smoke_cloud), + smoke_clouds.end()); + } delete *i; i = gameobjects.erase(i); @@ -454,6 +460,10 @@ Sector::update_game_objects() = dynamic_cast (*i); if(interactive_object) interactive_objects.push_back(interactive_object); + SmokeCloud* smoke_cloud = dynamic_cast (*i); + if(smoke_cloud) + smoke_clouds.push_back(smoke_cloud); + gameobjects.push_back(*i); } @@ -674,6 +684,13 @@ Sector::add_bullet(const Vector& pos, float xm, Direction dir) return true; } +bool +Sector::add_smoke_cloud(const Vector& pos) +{ + add_object(new SmokeCloud(pos)); + return true; +} + /* Break a brick: */ bool Sector::trybreakbrick(const Vector& pos, bool small) diff --git a/src/sector.h b/src/sector.h index 5d9822bfd..1b186ef4f 100644 --- a/src/sector.h +++ b/src/sector.h @@ -45,6 +45,7 @@ class FlyingPlatform; class TileMap; class Upgrade; class Bullet; +class SmokeCloud; class BadGuy; class Tile; @@ -102,6 +103,7 @@ public: void add_upgrade(const Vector& pos, Direction dir, UpgradeKind kind); bool add_bullet(const Vector& pos, float xm, Direction dir); + bool add_smoke_cloud(const Vector& pos); /** Try to grab the coin at the given coordinates */ void trygrabdistro(const Vector& pos, int bounciness); @@ -154,6 +156,7 @@ private: std::vector upgrades; std::vector bullets; + std::vector smoke_clouds; public: // ugly typedef std::vector InteractiveObjects;