if(ice_state == state)
return;
- if(state == ICESTATE_FLAT)
- flags |= FLAG_PORTABLE;
- else
- flags &= ~FLAG_PORTABLE;
+ set_portable(state == ICESTATE_FLAT);
switch(state) {
case ICESTATE_NORMAL:
#include "game_object.hpp"
#include "object_remove_listener.hpp"
-GameObject::GameObject()
- : wants_to_die(false), remove_listeners(0), flags(0)
+
+GameObject::GameObject(std::string name)
+ : wants_to_die(false), remove_listeners(0), name(name)
+{
+}
+
+GameObject::GameObject(const lisp::Lisp& lisp)
+ : wants_to_die(false), remove_listeners(0), name("")
{
+ lisp.get("name" , name);
}
GameObject::~GameObject()
#include <string>
#include "refcounter.hpp"
+#include "lisp/lisp.hpp"
class DrawingContext;
class ObjectRemoveListener;
class GameObject : public RefCounter
{
public:
- GameObject();
+ GameObject(std::string name = "");
+ GameObject(const lisp::Lisp& lisp);
virtual ~GameObject();
/** This function is called once per frame and allows the object to update
remove_listeners = entry;
}
- // flags
- enum {
- /// the tile so you can stand on it
- FLAG_SOLID = (1 << 0),
- /// the object can be carried around (inherits from Portable)
- FLAG_PORTABLE = (1 << 1)
- };
-
- int get_flags() const
+ std::string get_name() const
{
- return flags;
+ return name;
}
+ // --- BEGIN METHODS TO EXPOSE TO SQUIRREL --- //
+ //void set_visible(bool visible);
+ //bool is_visible();
+ // --- END METHODS TO EXPOSE TO SQUIRREL --- //
private:
/** this flag indicates if the object should be removed at the end of the
RemoveListenerListEntry* remove_listeners;
protected:
- int flags;
+ std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
};
#endif /*SUPERTUX_GAMEOBJECT_H*/
#include "moving_object.hpp"
-MovingObject::MovingObject()
+MovingObject::MovingObject(std::string name) :
+ GameObject(name), bbox(0, 0, 0, 0), group(COLGROUP_MOVING), solid(false)
+{
+}
+
+MovingObject::MovingObject(const lisp::Lisp& lisp) :
+ GameObject(lisp), bbox(0, 0, 0, 0), group(COLGROUP_MOVING)
+{
+ lisp.get("x", bbox.p1.x);
+ lisp.get("y", bbox.p1.y);
+ lisp.get("w", bbox.p2.x);
+ lisp.get("h", bbox.p2.y);
+ lisp.get("solid", solid);
+ bbox.p2.x+=bbox.p1.x;
+ bbox.p2.y+=bbox.p1.y;
+}
+
+MovingObject::MovingObject(Rect bbox, CollisionGroup group, bool solid) :
+ bbox(bbox), group(group), solid(solid)
{
- group = COLGROUP_MOVING;
}
MovingObject::~MovingObject()
class MovingObject : public GameObject
{
public:
- MovingObject();
+ MovingObject(std::string name = "");
+ MovingObject(const lisp::Lisp& lisp);
virtual ~MovingObject();
/** this function is called when the object collided with something solid */
* using this function. There are no collision detection checks performed
* here so bad things could happen.
*/
- virtual void set_size(float w, float h)
+ /*virtual void set_size(float w, float h)
{
dest.set_size(w, h);
bbox.set_size(w, h);
- }
+ }*/
CollisionGroup get_group() const
{
this->group = group;
}
+ // --- BEGIN METHODS TO EXPOSE TO SQUIRREL --- //
+ void set_solid(bool solid)
+ {
+ this->solid = solid;
+ }
+ bool is_solid() const
+ {
+ return solid;
+ }
+ void move(float x, float y)
+ {
+ bbox.move(Vector(x, y));
+ }
+ void set_pos(float x, float y)
+ {
+ set_pos(Vector(x, y));
+ }
+ float get_pos_x() const
+ {
+ return bbox.get_left();
+ }
+ float get_pos_y() const
+ {
+ return bbox.get_top();
+ }
+ void set_size(float w, float h)
+ {
+ dest.set_size(w, h);
+ bbox.set_size(w, h);
+ }
+ float get_width() const
+ {
+ return bbox.get_width();
+ }
+ float get_height() const
+ {
+ return bbox.get_height();
+ }
+ void set_velocity(float x, float y)
+ {
+ movement = Vector(x, y);
+ }
+ float get_velocity_x() const
+ {
+ return movement.x;
+ }
+ float get_velocity_y() const
+ {
+ return movement.y;
+ }
+ // --- END METHODS TO EXPOSE TO SQUIRREL --- //
+
protected:
+ MovingObject(Rect bbox, CollisionGroup group, bool solid);
friend class Sector;
friend class CollisionGrid;
friend class Platform;
* during collision detection
*/
Rect dest;
+
+ bool solid; /**< true if this object should be considered when doing collision detection */
};
#endif
#include "log.hpp"
#include "scripting/squirrel_util.hpp"
-AmbientSound::AmbientSound(const lisp::Lisp& lisp)
+AmbientSound::AmbientSound(const lisp::Lisp& lisp) :
+ MovingObject(lisp), sample(""), sound_source(0), latency(0),
+ distance_factor(0), distance_bias(0), maximumvolume(1), currentvolume(0)
{
- name="";
- position.x = 0;
- position.y = 0;
-
- dimension.x = 0;
- dimension.y = 0;
-
- distance_factor = 0;
- distance_bias = 0;
- maximumvolume = 1;
- sample = "";
- currentvolume = 0;
-
- if (!(lisp.get("x", position.x)&&lisp.get("y", position.y))) {
- log_warning << "No Position in ambient_sound" << std::endl;
- }
-
- lisp.get("name" , name);
- lisp.get("width" , dimension.x);
- lisp.get("height", dimension.y);
-
lisp.get("distance_factor",distance_factor);
lisp.get("distance_bias" ,distance_bias );
lisp.get("sample" ,sample );
// set dimension to zero if smaller than 64, which is default size in flexlay
- if ((dimension.x <= 64) || (dimension.y <= 64)) {
- dimension.x = 0;
- dimension.y = 0;
+ if ((get_width() <= 64) || (get_height() <= 64)) {
+ set_size(0, 0);
}
// square all distances (saves us a sqrt later)
silence_distance = 1/distance_factor;
lisp.get("silence_distance",silence_distance);
-
- sound_source = 0; // not playing at the beginning
- latency=0;
}
-AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std::string file)
+AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std::string file) :
+ sample(file), sound_source(0), latency(0), distance_factor(factor*factor),
+ distance_bias(bias*bias), maximumvolume(vol), currentvolume(0)
{
- position.x=pos.x;
- position.y=pos.y;
-
- dimension.x=0;
- dimension.y=0;
-
- distance_factor=factor*factor;
- distance_bias=bias*bias;
- maximumvolume=vol;
- sample=file;
+ bbox.p1 = pos;
+ bbox.p2 = pos;
// set default silence_distance
silence_distance = 10e99;
else
silence_distance = 1/distance_factor;
-
- sound_source = 0; // not playing at the beginning
- latency=0;
}
AmbientSound::~AmbientSound() {
py=Sector::current()->player->get_pos().y;
// Relate to which point in the area
- rx=px<position.x?position.x:
- (px<position.x+dimension.x?px:position.x+dimension.x);
- ry=py<position.y?position.y:
- (py<position.y+dimension.y?py:position.y+dimension.y);
+ rx=px<bbox.p1.x?bbox.p1.x:
+ (px<bbox.p2.x?px:bbox.p2.x);
+ ry=py<bbox.p1.y?bbox.p1.y:
+ (py<bbox.p2.y?py:bbox.p2.y);
// calculate square of distance
float sqrdistance=(px-rx)*(px-rx)+(py-ry)*(py-ry);
sound_source->set_gain(currentvolume*maximumvolume);
if (sqrdistance>=silence_distance && currentvolume<1e-3)
- stop_playing();
+ stop_playing();
latency=0;
} else {
if (sqrdistance<silence_distance) {
- start_playing();
- latency=0;
+ start_playing();
+ latency=0;
}
else // set a reasonable latency
- latency=(int)(0.001/distance_factor);
+ latency=(int)(0.001/distance_factor);
//(int)(10*((sqrdistance-silence_distance)/silence_distance));
}
}
void
AmbientSound::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::AmbientSound* interface = static_cast<Scripting::AmbientSound*> (this);
- expose_object(vm, table_idx, interface, name, false);
+ if(name.empty()) return;
+ expose_object(vm, table_idx, dynamic_cast<Scripting::AmbientSound *>(this), name, false);
}
void
AmbientSound::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
+ if(name.empty()) return;
Scripting::unexpose_object(vm, table_idx, name);
}
-void
-AmbientSound::set_pos(float x, float y){
- position.x = x;
- position.y = y;
-}
-
-float
-AmbientSound::get_pos_x(){;
- return position.x;
-}
-
-float
-AmbientSound::get_pos_y(){
- return position.y;
-}
-
IMPLEMENT_FACTORY(AmbientSound, "ambient_sound");
#ifndef __AMBIENT_SOUND_H__
#define __AMBIENT_SOUND_H__
-#include "game_object.hpp"
+#include "moving_object.hpp"
#include "resources.hpp"
#include "player.hpp"
#include "script_interface.hpp"
class SoundSource;
-class AmbientSound : public GameObject, public ScriptInterface, public Scripting::AmbientSound
+class AmbientSound : public MovingObject, public ScriptInterface, public Scripting::AmbientSound
{
public:
AmbientSound(const lisp::Lisp& lisp);
AmbientSound(Vector pos, float factor, float bias, float vol, std::string file);
~AmbientSound();
- void set_pos(Vector newpos)
+ /*void set_pos(Vector newpos)
{
position=newpos;
}
- const Vector get_pos() const
+ const Vector &get_pos() const
{
- return position;
+ return get_pos();
+ }*/
+
+ // --- BEGIN METHODS TO EXPOSE TO SQUIRREL --- //
+ void set_pos(float x, float y)
+ {
+ MovingObject::set_pos(x, y);
+ }
+
+ float get_pos_x() const
+ {
+ return MovingObject::get_pos_x();
}
- // --- Scripting Interface ---
+ float get_pos_y() const
+ {
+ return MovingObject::get_pos_y();
+ }
+ // --- END METHODS TO EXPOSE TO SQUIRREL --- //
- void set_pos(float x, float y);
- float get_pos_x();
- float get_pos_y();
+ HitResponse collision(GameObject&, const CollisionHit&)
+ {
+ return ABORT_MOVE;
+ }
protected:
virtual void hit(Player& player);
virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
private:
- std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
- Vector position;
- Vector dimension;
-
std::string sample;
SoundSource* sound_source;
int latency;
{
bbox.set_size(32, 32.1);
set_group(COLGROUP_STATIC);
- flags |= FLAG_SOLID;
+ set_solid(true);
sound_manager->preload("sounds/upgrade.wav");
sound_manager->preload("sounds/brick.wav");
}
#include "path.hpp"
#include "path_walker.hpp"
-Camera::Camera(Sector* newsector)
- : sector(newsector), do_backscrolling(true), scrollchange(NONE)
+Camera::Camera(Sector* newsector, std::string name) :
+ GameObject(name), mode(NORMAL), sector(newsector), do_backscrolling(true),
+ scrollchange(NONE)
{
- mode = NORMAL;
}
Camera::~Camera()
void
Camera::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
+ if(name.empty()) return;
Scripting::Camera* interface = new Scripting::Camera(this);
- expose_object(vm, table_idx, interface, "Camera", true);
+ expose_object(vm, table_idx, interface, name, true);
}
void
Camera::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::unexpose_object(vm, table_idx, "Camera");
+ if(name.empty()) return;
+ Scripting::unexpose_object(vm, table_idx, name);
}
const Vector&
class Camera : public GameObject, public Serializable, public ScriptInterface
{
public:
- Camera(Sector* sector);
+ Camera(Sector* sector, std::string name = "");
virtual ~Camera();
/// parse camera mode from lisp file
#include "object_factory.hpp"
Candle::Candle(const lisp::Lisp& lisp)
- : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true), name("")
+ : MovingSprite(lisp, "images/objects/candle/candle.sprite", LAYER_BACKGROUNDTILES+1, COLGROUP_DISABLED), burning(true)
{
- lisp.get("name", name);
lisp.get("burning", burning);
if (burning) {
void
Candle::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name == "") return;
+ if (name.empty()) return;
Scripting::Candle* interface = new Scripting::Candle(this);
expose_object(vm, table_idx, interface, name, true);
}
void
Candle::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name == "") return;
+ if (name.empty()) return;
Scripting::unexpose_object(vm, table_idx, name);
}
private:
bool burning; /**< true if candle is currently lighted */
- std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
};
static const float BORDER_SIZE = 75;
-DisplayEffect::DisplayEffect()
- : screen_fade(NO_FADE), screen_fadetime(0), screen_fading(0),
- border_fade(NO_FADE), border_fadetime(0), border_size(0),
- black(false), borders(false)
+DisplayEffect::DisplayEffect(std::string name) :
+ GameObject(name), screen_fade(NO_FADE), screen_fadetime(0), screen_fading(0),
+ border_fade(NO_FADE), border_fadetime(0), border_size(0), black(false),
+ borders(false)
{
}
void
DisplayEffect::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::DisplayEffect* interface = static_cast<Scripting::DisplayEffect*> (this);
- expose_object(vm, table_idx, interface, "Effect", false);
+ if (name.empty()) return;
+ expose_object(vm, table_idx, dynamic_cast<Scripting::DisplayEffect *>(this), name, false);
}
void
DisplayEffect::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
- try {
- Scripting::unexpose_object(vm, table_idx, "Effect");
- } catch(...) {
- // for now...
- }
+ if (name.empty()) return;
+ Scripting::unexpose_object(vm, table_idx, name);
}
void
public ScriptInterface
{
public:
- DisplayEffect();
+ DisplayEffect(std::string name = "");
virtual ~DisplayEffect();
void expose(HSQUIRRELVM vm, SQInteger table_idx);
sprite->set_action("empty");
start_bounce();
- flags |= FLAG_SOLID;
+ set_solid(true);
set_group(COLGROUP_STATIC);
visible = true;
}
}
MovingSprite::MovingSprite(const lisp::Lisp& reader, const Vector& pos, int layer, CollisionGroup collision_group)
- : layer(layer)
+ : MovingObject(reader), layer(layer)
{
bbox.set_pos(pos);
if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set");
}
MovingSprite::MovingSprite(const lisp::Lisp& reader, const std::string& sprite_name, int layer, CollisionGroup collision_group)
- : sprite_name(sprite_name), layer(layer)
+ : MovingObject(reader), sprite_name(sprite_name), layer(layer)
{
if (!reader.get("x", bbox.p1.x)) throw std::runtime_error("no x position set");
if (!reader.get("y", bbox.p1.y)) throw std::runtime_error("no y position set");
}
MovingSprite::MovingSprite(const lisp::Lisp& reader, int layer, CollisionGroup collision_group)
- : layer(layer)
+ : MovingObject(reader), layer(layer)
{
if (!reader.get("x", bbox.p1.x)) throw std::runtime_error("no x position set");
if (!reader.get("y", bbox.p1.y)) throw std::runtime_error("no y position set");
#include "scripting/squirrel_util.hpp"
Platform::Platform(const lisp::Lisp& reader)
- : MovingSprite(reader, Vector(0,0), LAYER_OBJECTS, COLGROUP_STATIC), name(""), speed(Vector(0,0))
+ : MovingSprite(reader, Vector(0,0), LAYER_OBJECTS, COLGROUP_STATIC), speed(Vector(0,0))
{
bool running = true;
- reader.get("name", name);
reader.get("running", running);
const lisp::Lisp* pathLisp = reader.get_lisp("path");
if(pathLisp == NULL)
walker.reset(new PathWalker(path.get(), running));
bbox.set_pos(path->get_base());
- flags |= FLAG_SOLID;
+ set_solid(true);
}
Platform::Platform(const Platform& other)
- : MovingSprite(other), ScriptInterface(other), name(other.name), speed(other.speed)
+ : MovingSprite(other), ScriptInterface(other), speed(other.speed)
{
+ name = other.name;
path.reset(new Path(*other.path));
walker.reset(new PathWalker(*other.walker));
walker->path = &*path;
void
Platform::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name == "") return;
+ if (name.empty()) return;
Scripting::Platform* interface = new Scripting::Platform(this);
expose_object(vm, table_idx, interface, name, true);
}
void
Platform::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name == "") return;
+ if (name.empty()) return;
Scripting::unexpose_object(vm, table_idx, name);
}
}
private:
- std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
std::auto_ptr<Path> path;
std::auto_ptr<PathWalker> walker;
Vector speed;
feet->draw(context, pos, layer-2);
}
-Player::Player(PlayerStatus* _player_status)
- : player_status(_player_status), grabbed_object(NULL), ghost_mode(false)
+Player::Player(PlayerStatus* _player_status, std::string name) :
+ MovingObject(name), player_status(_player_status), grabbed_object(NULL),
+ ghost_mode(false)
{
controller = main_controller;
smalltux_gameover = sprite_manager->create("images/creatures/tux_small/smalltux-gameover.sprite");
void
Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::Player* interface = static_cast<Scripting::Player*> (this);
- Scripting::expose_object(vm, table_idx, interface, "Tux", false);
+ if (name.empty()) return;
+ Scripting::expose_object(vm, table_idx, dynamic_cast<Scripting::Player *>(this), name, false);
}
void
Player::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::unexpose_object(vm, table_idx, "Tux");
+ if (name.empty()) return;
+ Scripting::unexpose_object(vm, table_idx, name);
}
void
}
// if we hit something from the side that is portable, the ACTION button is pressed and we are not already holding anything: grab it
- if ((hit.left || hit.right) && (other.get_flags() & FLAG_PORTABLE) && controller->hold(Controller::ACTION) && (!grabbed_object)) {
- Portable* portable = dynamic_cast<Portable*> (&other);
- assert(portable != NULL);
- if(portable) {
- grabbed_object = portable;
- grabbed_object->grab(*this, get_pos(), dir);
- return CONTINUE;
- }
+ Portable* portable = dynamic_cast<Portable*> (&other);
+ if ((hit.left || hit.right) && (portable && portable->is_portable()) && controller->hold(Controller::ACTION) && (!grabbed_object)) {
+ grabbed_object = portable;
+ grabbed_object->grab(*this, get_pos(), dir);
+ return CONTINUE;
}
#ifdef DEBUG
Physic physic;
public:
- Player(PlayerStatus* player_status);
+ Player(PlayerStatus* player_status, std::string name = "");
virtual ~Player();
virtual void expose(HSQUIRRELVM vm, SQInteger table_idx);
class Portable
{
public:
+ Portable(bool portable = false) :
+ portable(portable)
+ {
+ }
virtual ~Portable()
{ }
virtual void ungrab(MovingObject& , Direction )
{}
+
+ // --- BEGIN METHODS TO EXPOSE TO SQUIRREL --- //
+ void set_portable(bool portable)
+ {
+ this->portable = portable;
+ }
+
+ bool is_portable() const
+ {
+ return portable;
+ }
+ // --- END METHODS TO EXPOSE TO SQUIRREL --- //
+
+private:
+ bool portable; /**< true if this object can currently be carried */
};
#endif
sound_manager->preload( ROCK_SOUND );
on_ground = false;
grabbed = false;
- flags |= FLAG_SOLID | FLAG_PORTABLE;
+ set_solid(true);
+ set_portable(true);
}
void
lisp.get("physic-enabled", physic_enabled);
lisp.get("visible", visible);
lisp.get("z-pos", layer);
- if(solid)
- flags |= FLAG_SOLID;
}
void
ScriptedObject::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::ScriptedObject* interface = static_cast<Scripting::ScriptedObject*> (this);
- expose_object(vm, table_idx, interface, name, false);
+ if (name.empty()) return;
+ expose_object(vm, table_idx, dynamic_cast<Scripting::ScriptedObject *>(this), name, false);
}
void
ScriptedObject::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
+ if (name.empty()) return;
Scripting::unexpose_object(vm, table_idx, name);
}
ScriptedObject::set_solid(bool solid)
{
this->solid = solid;
- if(solid)
- flags |= FLAG_SOLID;
- else
- flags ^= FLAG_SOLID;
}
bool
SkullTile::SkullTile(const lisp::Lisp& lisp)
: MovingSprite(lisp, "images/objects/skull_tile/skull_tile.sprite", LAYER_TILES, COLGROUP_STATIC), hit(false), falling(false)
{
- flags |= FLAG_SOLID;
+ set_solid(true);
}
HitResponse
if(timer.check()) {
falling = true;
physic.enable_gravity(true);
- flags &= ~FLAG_SOLID;
+ set_solid(false);
timer.stop();
} else if(!timer.started()) {
timer.start(FALLTIME);
#include "scripting/squirrel_util.hpp"
#include "log.hpp"
-TextObject::TextObject()
- : fading(0), fadetime(0), visible(false)
+TextObject::TextObject(std::string name) :
+ GameObject(name), fading(0), fadetime(0), visible(false)
{
font = blue_text;
centered = false;
void
TextObject::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::Text* interface = static_cast<Scripting::Text*> (this);
- Scripting::expose_object(vm, table_idx, interface, "Text", false);
+ if (name.empty()) return;
+ Scripting::expose_object(vm, table_idx, dynamic_cast<Scripting::Text *>(this), name, false);
}
void
TextObject::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
- Scripting::unexpose_object(vm, table_idx, "Text");
+ if (name.empty()) return;
+ Scripting::unexpose_object(vm, table_idx, name);
}
void
public ScriptInterface
{
public:
- TextObject();
+ TextObject(std::string name = "");
virtual ~TextObject();
void expose(HSQUIRRELVM vm, SQInteger table_idx);
}
Thunderstorm::Thunderstorm(const lisp::Lisp& reader)
- : name(""), running(true), interval(10.0f)
+ : GameObject(reader), running(true), interval(10.0f)
{
reader.get("name", name);
reader.get("running", running);
void electrify();
private:
- std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
bool running; /**< whether we currently automatically trigger lightnings */
float interval; /**< time between two lightnings */
drawing_effect(NO_EFFECT)
{
tilemanager = tile_manager;
-
- if(solid)
- flags |= FLAG_SOLID;
}
TileMap::TileMap(const lisp::Lisp& reader, TileManager* new_tile_manager)
- : solid(false), speed(1), width(-1), height(-1), z_pos(0), x_offset(0), y_offset(0),
+ : GameObject(reader), solid(false), speed(1), width(-1), height(-1), z_pos(0), x_offset(0), y_offset(0),
drawing_effect(NO_EFFECT)
{
tilemanager = new_tile_manager;
if(tilemanager == 0)
tilemanager = tile_manager;
- reader.get("name", name);
reader.get("z-pos", z_pos);
reader.get("solid", solid);
reader.get("speed", speed);
log_warning << "Speed of solid tilemap is not 1. fixing" << std::endl;
speed = 1;
}
- if(solid)
- flags |= FLAG_SOLID;
reader.get("width", width);
reader.get("height", height);
}
TileMap::TileMap(std::string name, int z_pos, bool solid, size_t width, size_t height)
- : name(name), solid(solid), speed(1), width(0), height(0), z_pos(z_pos),
+ : GameObject(name), solid(solid), speed(1), width(0), height(0), z_pos(z_pos),
x_offset(0), y_offset(0), drawing_effect(NO_EFFECT)
{
tilemanager = tile_manager;
resize(width, height);
-
- if(solid)
- flags |= FLAG_SOLID;
}
TileMap::~TileMap()
z_pos = new_z_pos;
solid = newsolid;
- if(solid)
- flags |= FLAG_SOLID;
// make sure all tiles are loaded
for(Tiles::iterator i = tiles.begin(); i != tiles.end(); ++i)
private:
TileManager* tilemanager;
- std::string name;
bool solid;
float speed;
int width, height;
: MovingSprite(lisp, "images/objects/trampoline/trampoline.sprite" )
{
sound_manager->preload( TRAMPOLINE_SOUND );
- flags |= FLAG_PORTABLE;
physic.set_velocity(0, 0);
physic.enable_gravity(true);
on_ground = false;
//Check if this trampoline is not portable
if( lisp.get( "portable", portable ) ){
if( !portable ){
- flags ^= FLAG_PORTABLE;
//we need another sprite
sprite_name = "images/objects/trampoline/trampoline_fix.sprite";
sprite = sprite_manager->create( sprite_name );
sprite->set_action("normal");
}
}
+ set_portable(portable);
}
void
case STATE_CRUMBLING:
if (sprite->animation_done()) {
- state = STATE_DISINTEGRATING;
- sprite->set_action("disintegrating", 1);
- flags &= ~FLAG_SOLID;
+ state = STATE_DISINTEGRATING;
+ sprite->set_action("disintegrating", 1);
+ set_solid(false);
set_group(COLGROUP_DISABLED);
- physic.enable_gravity(true);
+ physic.enable_gravity(true);
}
break;
: MovingSprite(lisp, "images/objects/strawbox/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL)
{
sprite->set_action("normal");
- flags |= FLAG_SOLID;
+ set_solid(true);
}
HitResponse
case STATE_NORMAL:
if (dynamic_cast<Bullet*>(&other)) {
- startBurning();
- return FORCE_MOVE;
+ startBurning();
+ return FORCE_MOVE;
}
return FORCE_MOVE;
break;
case STATE_BURNING:
if (sprite->animation_done()) {
- state = STATE_DISINTEGRATING;
- sprite->set_action("disintegrating", 1);
- spreadHit();
- flags &= ~FLAG_SOLID;
+ state = STATE_DISINTEGRATING;
+ sprite->set_action("disintegrating", 1);
+ spreadHit();
+ set_solid(false);
set_group(COLGROUP_DISABLED);
}
break;
case STATE_DISINTEGRATING:
if (sprite->animation_done()) {
- remove_me();
- return;
+ remove_me();
+ return;
}
break;
#include "scripting/wind.hpp"
#include "scripting/squirrel_util.hpp"
-Wind::Wind(const lisp::Lisp& reader) : name(""), blowing(true), acceleration(100), elapsed_time(0)
+Wind::Wind(const lisp::Lisp& reader) :
+ MovingObject(reader), blowing(true), acceleration(100),
+ elapsed_time(0)
{
reader.get("x", bbox.p1.x);
reader.get("y", bbox.p1.y);
reader.get("height", h);
bbox.set_size(w, h);
- reader.get("name", name);
reader.get("blowing", blowing);
float speed_x = 0, speed_y = 0;
virtual void unexpose(HSQUIRRELVM vm, SQInteger table_idx);
private:
- std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
-
bool blowing; /**< true if wind is currently switched on */
Vector speed;
float acceleration;
#endif
virtual void set_pos(float x, float y) = 0;
- virtual float get_pos_x() = 0;
- virtual float get_pos_y() = 0;
+ virtual float get_pos_x() const = 0;
+ virtual float get_pos_y() const = 0;
};
}
: level(parent), currentmusic(LEVEL_MUSIC), gravity(10),
player(0), camera(0)
{
- add_object(new Player(player_status));
- add_object(new DisplayEffect());
- add_object(new TextObject());
+ add_object(new Player(player_status, "Tux"));
+ add_object(new DisplayEffect("Effect"));
+ add_object(new TextObject("Text"));
// create a new squirrel table for the sector
using namespace Scripting;
Sector::parse_object(const std::string& name, const lisp::Lisp& reader)
{
if(name == "camera") {
- Camera* camera = new Camera(this);
+ Camera* camera = new Camera(this, "Camera");
camera->parse(reader);
return camera;
} else if(name == "particles-snow") {
if(!camera) {
log_warning << "sector '" << name << "' does not contain a camera." << std::endl;
update_game_objects();
- add_object(new Camera(this));
+ add_object(new Camera(this, "Camera"));
}
update_game_objects();
}
// add a camera
- Camera* camera = new Camera(this);
+ Camera* camera = new Camera(this, "Camera");
add_object(camera);
update_game_objects();
{
LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
- : solved(false), auto_path(true), basedir(basedir), picture_cached(false), picture(0)
+ : GameObject(*lisp), solved(false), auto_path(true), basedir(basedir), picture_cached(false), picture(0)
{
lisp->get("x", pos.x);
lisp->get("y", pos.y);
sprite.reset(sprite_manager->create(spritefile));
lisp->get("extro-script", extro_script);
- lisp->get("name", name);
if (!PHYSFS_exists((basedir + name).c_str()))
{
virtual void update(float elapsed_time);
Vector pos;
- std::string name;
std::string title;
bool solved;
try {
lisp::Parser parser;
- std::auto_ptr<lisp::Lisp> root (parser.parse(levels_path + level.name));
+ std::auto_ptr<lisp::Lisp> root (parser.parse(levels_path + level.get_name()));
const lisp::Lisp* level_lisp = root->get_lisp("supertux-level");
if(!level_lisp)
try {
Vector shrinkpos = Vector(level->pos.x*32 + 16 - camera_offset.x,
level->pos.y*32 + 16 - camera_offset.y);
- std::string levelfile = levels_path + level->name;
+ std::string levelfile = levels_path + level->get_name();
main_loop->push_screen(new GameSession(levelfile, &level->statistics),
new ShrinkFade(shrinkpos, 0.5));
} catch(std::exception& e) {
LevelTile* level = *i;
if (level->solved) {
- sq_pushstring(vm, level->name.c_str(), -1);
+ sq_pushstring(vm, level->get_name().c_str(), -1);
sq_newtable(vm);
store_bool(vm, "solved", true);
for(LevelTiles::iterator i = levels.begin(); i != levels.end(); ++i) {
LevelTile* level = *i;
- sq_pushstring(vm, level->name.c_str(), -1);
+ sq_pushstring(vm, level->get_name().c_str(), -1);
if(SQ_SUCCEEDED(sq_get(vm, -2))) {
level->solved = read_bool(vm, "solved");
level->sprite->set_action(level->solved ? "solved" : "default");