#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
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<Player*> (&other);
if(player) {
- ringing = true;
+ activated = true;
// TODO play sound
sprite->set_action("ringing");
GameSession::current()->set_reset_point(Sector::current()->get_name(),
#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
#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
return FORCE_MOVE;
}
-void
-GrowUp::draw(DrawingContext& context)
-{
- sprite->draw(context, get_pos(), LAYER_OBJECTS);
-}
-
#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;
};
#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
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& )
{
#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;
};
#include <config.h>
#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
}
void
-Rock::draw(DrawingContext& context)
-{
- sprite->draw(context, get_pos(), LAYER_OBJECTS+1);
-}
-
-void
Rock::update(float elapsed_time)
{
if(!grabbed) {
#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"
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;
};
#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);
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)
{
if(!visible)
return;
- sprite->draw(context, get_pos(), z_pos);
+ sprite->draw(context, get_pos(), layer);
}
HitResponse
#include <string>
#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);
bool physic_enabled;
bool visible;
bool new_vel_set;
- int z_pos;
Vector new_vel;
Physic physic;
- Sprite* sprite;
};
#endif
#include "player.hpp"
#include "sector.hpp"
#include "resources.hpp"
-#include "sprite/sprite_manager.hpp"
#include "sprite/sprite.hpp"
#include "random_generator.hpp"
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
pos.x += systemRandom.rand(-3, 3);
}
- sprite->draw(context, pos, LAYER_TILES);
+ sprite->draw(context, pos, layer);
}
void
#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);
private:
Physic physic;
- Sprite* sprite;
Timer timer;
bool hit;
bool falling;
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
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)
{
#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;
};
#include "player.hpp"
#include "sector.hpp"
#include "resources.hpp"
-#include "sprite/sprite_manager.hpp"
#include "sprite/sprite.hpp"
#include "random_generator.hpp"
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
#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);
private:
Physic physic;
- Sprite* sprite;
Timer timer;
bool hit;
bool falling;