From: Christoph Sommer Date: Sat, 13 May 2006 16:12:37 +0000 (+0000) Subject: Some more objects now inherit from MovingSprite X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=15c5a91ee89272dfda3666e2fed67e06d650d0bf;p=supertux.git Some more objects now inherit from MovingSprite SVN-Revision: 3509 --- diff --git a/src/object/firefly.cpp b/src/object/firefly.cpp index c0875b577..dc9adff0b 100644 --- a/src/object/firefly.cpp +++ b/src/object/firefly.cpp @@ -29,18 +29,8 @@ #include "sector.hpp" Firefly::Firefly(const lisp::Lisp& lisp) - : ringing(false) + : MovingSprite(lisp, "images/objects/firefly/firefly.sprite", LAYER_TILES, COLGROUP_TOUCHABLE), activated(false) { - lisp.get("x", bbox.p1.x); - lisp.get("y", bbox.p1.y); - bbox.set_size(32, 32); - sprite = sprite_manager->create("images/objects/firefly/firefly.sprite"); - set_group(COLGROUP_TOUCHABLE); -} - -Firefly::~Firefly() -{ - delete sprite; } void @@ -49,29 +39,18 @@ Firefly::write(lisp::Writer& writer) writer.start_list("firefly"); writer.write_float("x", bbox.p1.x); writer.write_float("y", bbox.p1.y); - writer.end_list("Firefly"); -} - -void -Firefly::update(float ) -{ -} - -void -Firefly::draw(DrawingContext& context) -{ - sprite->draw(context, get_pos(), LAYER_TILES); + writer.end_list("firefly"); } HitResponse Firefly::collision(GameObject& other, const CollisionHit& ) { - if(ringing) + if(activated) return ABORT_MOVE; Player* player = dynamic_cast (&other); if(player) { - ringing = true; + activated = true; // TODO play sound sprite->set_action("ringing"); GameSession::current()->set_reset_point(Sector::current()->get_name(), diff --git a/src/object/firefly.hpp b/src/object/firefly.hpp index e6ea343e8..b167b3af7 100644 --- a/src/object/firefly.hpp +++ b/src/object/firefly.hpp @@ -21,28 +21,24 @@ #define __FIREFLY_H__ #include "lisp/lisp.hpp" -#include "moving_object.hpp" -#include "sprite/sprite.hpp" +#include "object/moving_sprite.hpp" #include "serializable.hpp" /** * A Firefly: When tux touches it, it begins buzzing and you will respawn at this * position. */ -class Firefly : public MovingObject, public Serializable +class Firefly : public MovingSprite, public Serializable { public: Firefly(const lisp::Lisp& lisp); - ~Firefly(); + virtual Firefly* clone() const { return new Firefly(*this); } void write(lisp::Writer& writer); - void update(float elapsed_time); - void draw(DrawingContext& context); HitResponse collision(GameObject& other, const CollisionHit& hit); private: - Sprite* sprite; - bool ringing; + bool activated; }; #endif diff --git a/src/object/growup.cpp b/src/object/growup.cpp index 6b9ac4e28..bdcb89404 100644 --- a/src/object/growup.cpp +++ b/src/object/growup.cpp @@ -26,21 +26,12 @@ #include "sector.hpp" #include "player.hpp" #include "audio/sound_manager.hpp" -#include "sprite/sprite_manager.hpp" GrowUp::GrowUp() + : MovingSprite(Vector(0,0), "images/powerups/egg/egg.sprite", LAYER_OBJECTS, COLGROUP_MOVING) { - bbox.set_size(32, 32); - - sprite = sprite_manager->create("images/powerups/egg/egg.sprite"); physic.enable_gravity(true); physic.set_velocity_x(100); - set_group(COLGROUP_MOVING); -} - -GrowUp::~GrowUp() -{ - delete sprite; } void @@ -74,9 +65,3 @@ GrowUp::collision(GameObject& other, const CollisionHit& hit) return FORCE_MOVE; } -void -GrowUp::draw(DrawingContext& context) -{ - sprite->draw(context, get_pos(), LAYER_OBJECTS); -} - diff --git a/src/object/growup.hpp b/src/object/growup.hpp index 65ca52c3c..240591493 100644 --- a/src/object/growup.hpp +++ b/src/object/growup.hpp @@ -20,22 +20,19 @@ #ifndef __GROWUP_H__ #define __GROWUP_H__ -#include "moving_object.hpp" -#include "sprite/sprite.hpp" +#include "object/moving_sprite.hpp" #include "physic.hpp" -class GrowUp : public MovingObject +class GrowUp : public MovingSprite { public: GrowUp(); - ~GrowUp(); + virtual GrowUp* clone() const { return new GrowUp(*this); } virtual void update(float elapsed_time); - virtual void draw(DrawingContext& context); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); private: - Sprite* sprite; Physic physic; }; diff --git a/src/object/oneup.cpp b/src/object/oneup.cpp index 1d23ae686..d449daf76 100644 --- a/src/object/oneup.cpp +++ b/src/object/oneup.cpp @@ -24,21 +24,12 @@ #include "player.hpp" #include "player_status.hpp" #include "sector.hpp" -#include "sprite/sprite_manager.hpp" #include "video/drawing_context.hpp" OneUp::OneUp(const Vector& pos) + : MovingSprite(pos, "images/powerups/1up/1up.sprite", LAYER_FLOATINGOBJECTS, COLGROUP_TOUCHABLE) { - bbox.set_pos(pos); - bbox.set_size(32, 32); - sprite = sprite_manager->create("images/powerups/1up/1up.sprite"); physic.set_velocity(100, 400); - set_group(COLGROUP_TOUCHABLE); -} - -OneUp::~OneUp() -{ - delete sprite; } void @@ -50,12 +41,6 @@ OneUp::update(float elapsed_time) movement = physic.get_movement(elapsed_time); } -void -OneUp::draw(DrawingContext& context) -{ - sprite->draw(context, get_pos(), LAYER_FLOATINGOBJECTS); -} - HitResponse OneUp::collision(GameObject& other, const CollisionHit& ) { diff --git a/src/object/oneup.hpp b/src/object/oneup.hpp index 772926880..7380be08d 100644 --- a/src/object/oneup.hpp +++ b/src/object/oneup.hpp @@ -20,22 +20,19 @@ #ifndef __ONEUP_H__ #define __ONEUP_H__ -#include "moving_object.hpp" -#include "sprite/sprite.hpp" +#include "object/moving_sprite.hpp" #include "physic.hpp" -class OneUp : public MovingObject +class OneUp : public MovingSprite { public: OneUp(const Vector& pos); - ~OneUp(); + virtual OneUp* clone() const { return new OneUp(*this); } virtual void update(float elapsed_time); - virtual void draw(DrawingContext& context); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); private: - Sprite* sprite; Physic physic; }; diff --git a/src/object/rock.cpp b/src/object/rock.cpp index 2df1586fa..6ba11fcfd 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -20,27 +20,16 @@ #include #include "rock.hpp" -#include "sprite/sprite.hpp" -#include "sprite/sprite_manager.hpp" #include "lisp/writer.hpp" #include "video/drawing_context.hpp" #include "resources.hpp" #include "object_factory.hpp" Rock::Rock(const lisp::Lisp& reader) + : MovingSprite(reader, "images/objects/rock/rock.sprite", LAYER_OBJECTS+1, COLGROUP_MOVING) { - reader.get("x", bbox.p1.x); - reader.get("y", bbox.p1.y); - bbox.set_size(31.8, 31.8); - sprite = sprite_manager->create("images/objects/rock/rock.sprite"); grabbed = false; flags |= FLAG_SOLID | FLAG_PORTABLE; - set_group(COLGROUP_MOVING); -} - -Rock::~Rock() -{ - delete sprite; } void @@ -55,12 +44,6 @@ Rock::write(lisp::Writer& writer) } void -Rock::draw(DrawingContext& context) -{ - sprite->draw(context, get_pos(), LAYER_OBJECTS+1); -} - -void Rock::update(float elapsed_time) { if(!grabbed) { diff --git a/src/object/rock.hpp b/src/object/rock.hpp index 30c75d26b..ad4bebc08 100644 --- a/src/object/rock.hpp +++ b/src/object/rock.hpp @@ -20,7 +20,7 @@ #ifndef __ROCK_H__ #define __ROCK_H__ -#include "moving_object.hpp" +#include "object/moving_sprite.hpp" #include "physic.hpp" #include "lisp/lisp.hpp" #include "portable.hpp" @@ -28,22 +28,20 @@ class Sprite; -class Rock : public MovingObject, public Portable, public Serializable +class Rock : public MovingSprite, public Portable, public Serializable { public: Rock(const lisp::Lisp& reader); - virtual ~Rock(); + virtual Rock* clone() const { return new Rock(*this); } HitResponse collision(GameObject& other, const CollisionHit& hit); void update(float elapsed_time); - void draw(DrawingContext& context); void write(lisp::Writer& writer); void grab(MovingObject& object, const Vector& pos, Direction dir); private: bool grabbed; - Sprite* sprite; Physic physic; }; diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index feace6c07..009b4a51e 100644 --- a/src/object/scripted_object.cpp +++ b/src/object/scripted_object.cpp @@ -24,28 +24,20 @@ #include "scripted_object.hpp" #include "video/drawing_context.hpp" -#include "sprite/sprite_manager.hpp" #include "scripting/squirrel_util.hpp" #include "resources.hpp" #include "object_factory.hpp" #include "math/vector.hpp" ScriptedObject::ScriptedObject(const lisp::Lisp& lisp) - : solid(true), physic_enabled(true), visible(true), new_vel_set(false), - z_pos(LAYER_OBJECTS) + : MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING), + solid(true), physic_enabled(true), visible(true), new_vel_set(false) { lisp.get("name", name); if(name == "") throw std::runtime_error("Scripted object must have a name specified"); - std::string spritename; - lisp.get("sprite", spritename); - if(spritename == "") - throw std::runtime_error("Scripted object must have a sprite name specified"); - sprite = sprite_manager->create(spritename); - - lisp.get("x", bbox.p1.x); - lisp.get("y", bbox.p1.y); + // FIXME: do we need this? bbox is already set via .sprite file float width = sprite->get_width(); float height = sprite->get_height(); lisp.get("width", width); @@ -55,16 +47,11 @@ ScriptedObject::ScriptedObject(const lisp::Lisp& lisp) lisp.get("solid", solid); lisp.get("physic-enabled", physic_enabled); lisp.get("visible", visible); - lisp.get("z-pos", z_pos); + lisp.get("z-pos", layer); if(solid) flags |= FLAG_SOLID; } -ScriptedObject::~ScriptedObject() -{ - delete sprite; -} - void ScriptedObject::expose(HSQUIRRELVM vm, SQInteger table_idx) { @@ -170,7 +157,7 @@ ScriptedObject::draw(DrawingContext& context) if(!visible) return; - sprite->draw(context, get_pos(), z_pos); + sprite->draw(context, get_pos(), layer); } HitResponse diff --git a/src/object/scripted_object.hpp b/src/object/scripted_object.hpp index 5bebd0c95..14e3b0394 100644 --- a/src/object/scripted_object.hpp +++ b/src/object/scripted_object.hpp @@ -22,18 +22,17 @@ #include #include "physic.hpp" -#include "sprite/sprite.hpp" #include "lisp/lisp.hpp" -#include "moving_object.hpp" +#include "object/moving_sprite.hpp" #include "script_interface.hpp" #include "scripting/scripted_object.hpp" -class ScriptedObject : public MovingObject, public Scripting::ScriptedObject, +class ScriptedObject : public MovingSprite, public Scripting::ScriptedObject, public ScriptInterface { public: ScriptedObject(const lisp::Lisp& lisp); - virtual ~ScriptedObject(); + virtual ScriptedObject* clone() const { return new ScriptedObject(*this); } virtual void expose(HSQUIRRELVM vm, SQInteger table_idx); virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx); @@ -65,10 +64,8 @@ private: bool physic_enabled; bool visible; bool new_vel_set; - int z_pos; Vector new_vel; Physic physic; - Sprite* sprite; }; #endif diff --git a/src/object/skull_tile.cpp b/src/object/skull_tile.cpp index 66e4c90ee..c4c36b146 100644 --- a/src/object/skull_tile.cpp +++ b/src/object/skull_tile.cpp @@ -25,7 +25,6 @@ #include "player.hpp" #include "sector.hpp" #include "resources.hpp" -#include "sprite/sprite_manager.hpp" #include "sprite/sprite.hpp" #include "random_generator.hpp" @@ -33,20 +32,9 @@ static const float CRACKTIME = 0.3; static const float FALLTIME = 0.8; SkullTile::SkullTile(const lisp::Lisp& lisp) - : hit(false), falling(false) + : MovingSprite(lisp, "images/objects/skull_tile/skull_tile.sprite", LAYER_TILES, COLGROUP_STATIC), hit(false), falling(false) { - lisp.get("x", bbox.p1.x); - lisp.get("y", bbox.p1.y); - bbox.set_size(32, 32); - sprite = sprite_manager->create("images/objects/skull_tile/skull_tile.sprite"); flags |= FLAG_SOLID; - - set_group(COLGROUP_STATIC); -} - -SkullTile::~SkullTile() -{ - delete sprite; } HitResponse @@ -71,7 +59,7 @@ SkullTile::draw(DrawingContext& context) pos.x += systemRandom.rand(-3, 3); } - sprite->draw(context, pos, LAYER_TILES); + sprite->draw(context, pos, layer); } void diff --git a/src/object/skull_tile.hpp b/src/object/skull_tile.hpp index 86afb1dcc..183ae34eb 100644 --- a/src/object/skull_tile.hpp +++ b/src/object/skull_tile.hpp @@ -20,20 +20,19 @@ #ifndef __SKULL_TILE_H__ #define __SKULL_TILE_H__ -#include "moving_object.hpp" +#include "object/moving_sprite.hpp" #include "lisp/lisp.hpp" #include "physic.hpp" #include "timer.hpp" -class Sprite; class Player; /** A tile that starts falling down if tux stands to long on it */ -class SkullTile : public MovingObject +class SkullTile : public MovingSprite { public: SkullTile(const lisp::Lisp& lisp); - ~SkullTile(); + virtual SkullTile* clone() const { return new SkullTile(*this); } HitResponse collision(GameObject& other, const CollisionHit& hit); void update(float elapsed_time); @@ -41,7 +40,6 @@ public: private: Physic physic; - Sprite* sprite; Timer timer; bool hit; bool falling; diff --git a/src/object/star.cpp b/src/object/star.cpp index 3776444ee..39724b8d7 100644 --- a/src/object/star.cpp +++ b/src/object/star.cpp @@ -31,18 +31,9 @@ static const float SPEED = 150; static const float JUMPSPEED = 300; Star::Star(const Vector& pos) + : MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING) { - bbox.set_pos(pos); - bbox.set_size(32, 32); - sprite = sprite_manager->create("images/powerups/star/star.sprite"); physic.set_velocity(SPEED, INITIALJUMP); - - set_group(COLGROUP_MOVING); -} - -Star::~Star() -{ - delete sprite; } void @@ -51,12 +42,6 @@ Star::update(float elapsed_time) movement = physic.get_movement(elapsed_time); } -void -Star::draw(DrawingContext& context) -{ - sprite->draw(context, get_pos(), LAYER_OBJECTS); -} - HitResponse Star::collision(GameObject& other, const CollisionHit& hit) { diff --git a/src/object/star.hpp b/src/object/star.hpp index 5cd409f42..d0eed7c53 100644 --- a/src/object/star.hpp +++ b/src/object/star.hpp @@ -20,22 +20,19 @@ #ifndef __STAR_H__ #define __STAR_H__ -#include "moving_object.hpp" -#include "sprite/sprite.hpp" +#include "object/moving_sprite.hpp" #include "physic.hpp" -class Star : public MovingObject +class Star : public MovingSprite { public: Star(const Vector& pos); - ~Star(); + virtual Star* clone() const { return new Star(*this); } virtual void update(float elapsed_time); - virtual void draw(DrawingContext& context); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); private: - Sprite* sprite; Physic physic; }; diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index a7ac4f909..8a61d09c4 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -25,7 +25,6 @@ #include "player.hpp" #include "sector.hpp" #include "resources.hpp" -#include "sprite/sprite_manager.hpp" #include "sprite/sprite.hpp" #include "random_generator.hpp" @@ -33,19 +32,9 @@ static const float CRACKTIME = 0.3; static const float FALLTIME = 0.8; UnstableTile::UnstableTile(const lisp::Lisp& lisp) - : hit(false), falling(false) + : MovingSprite(lisp, "images/objects/unstable_tile/unstable_tile.sprite", LAYER_TILES, COLGROUP_STATIC), hit(false), falling(false) { - lisp.get("x", bbox.p1.x); - lisp.get("y", bbox.p1.y); - bbox.set_size(32, 32); - sprite = sprite_manager->create("images/objects/unstable_tile/unstable_tile.sprite"); flags |= FLAG_SOLID; - set_group(COLGROUP_STATIC); -} - -UnstableTile::~UnstableTile() -{ - delete sprite; } HitResponse diff --git a/src/object/unstable_tile.hpp b/src/object/unstable_tile.hpp index 6b91b5c9e..0e8cb3221 100644 --- a/src/object/unstable_tile.hpp +++ b/src/object/unstable_tile.hpp @@ -20,20 +20,19 @@ #ifndef __UNSTABLE_TILE_H__ #define __UNSTABLE_TILE_H__ -#include "moving_object.hpp" +#include "object/moving_sprite.hpp" #include "lisp/lisp.hpp" #include "physic.hpp" #include "timer.hpp" -class Sprite; class Player; /** A tile that starts falling down if tux stands to long on it */ -class UnstableTile : public MovingObject +class UnstableTile : public MovingSprite { public: UnstableTile(const lisp::Lisp& lisp); - ~UnstableTile(); + virtual UnstableTile* clone() const { return new UnstableTile(*this); } HitResponse collision(GameObject& other, const CollisionHit& hit); void update(float elapsed_time); @@ -41,7 +40,6 @@ public: private: Physic physic; - Sprite* sprite; Timer timer; bool hit; bool falling;