if(ice_state == state)
return;
- set_portable(state == ICESTATE_FLAT);
-
switch(state) {
case ICESTATE_NORMAL:
WalkingBadguy::activate();
set_group(COLGROUP_MOVING);
}
+bool
+MrIceBlock::is_portable() const
+{
+ return ice_state == ICESTATE_FLAT;
+}
+
IMPLEMENT_FACTORY(MrIceBlock, "mriceblock")
void grab(MovingObject& object, const Vector& pos, Direction dir);
void ungrab(MovingObject& object, Direction dir);
+ bool is_portable() const;
+
bool can_break();
virtual MrIceBlock* clone() const { return new MrIceBlock(*this); }
#include "game_object.hpp"
#include "object_remove_listener.hpp"
-
-GameObject::GameObject(std::string name)
- : wants_to_die(false), remove_listeners(0), name(name)
+GameObject::GameObject()
+ : wants_to_die(false), remove_listeners(NULL)
{
}
-GameObject::GameObject(const lisp::Lisp& lisp)
- : wants_to_die(false), remove_listeners(0), name("")
-{
- lisp.get("name" , name);
-}
-
GameObject::~GameObject()
{
// call remove listeners (and remove them from the list)
RemoveListenerListEntry* entry = remove_listeners;
- while(entry != 0) {
+ while(entry != NULL) {
RemoveListenerListEntry* next = entry->next;
entry->listener->object_removed(this);
delete entry;
entry = next;
}
}
+
* draw() functions. Both are called once per frame.
* - Providing a safe way to remove the object by calling the remove_me
* functions.
- * - a 32bit bitset for flags...
*/
class GameObject : public RefCounter
{
public:
- GameObject(std::string name = "");
- GameObject(const lisp::Lisp& lisp);
+ GameObject();
virtual ~GameObject();
/** This function is called once per frame and allows the object to update
remove_listeners = entry;
}
- std::string get_name() const
+ const std::string& get_name() const
{
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:
- std::string name; /**< user-defined name for use in scripts or empty string if not scriptable */
+ /**
+ * a name for the gameobject, this is mostly a hint for scripts and for
+ * debugging, don't rely on names being set or being unique
+ */
+ std::string name;
};
#endif /*SUPERTUX_GAMEOBJECT_H*/
+
#include "moving_object.hpp"
-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)
+MovingObject::MovingObject()
{
+ group = COLGROUP_MOVING;
}
MovingObject::~MovingObject()
class MovingObject : public GameObject
{
public:
- MovingObject(std::string name = "");
- MovingObject(const lisp::Lisp& lisp);
+ MovingObject();
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
{
return group;
}
- void set_group(CollisionGroup group)
- {
- 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;
+ void set_group(CollisionGroup group)
+ {
+ this->group = group;
+ }
+
/** The bounding box of the object (as used for collision detection, this
* isn't necessarily the bounding box for graphics)
*/
* 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) :
- MovingObject(lisp), sample(""), sound_source(0), latency(0),
- distance_factor(0), distance_bias(0), maximumvolume(1), currentvolume(0)
+AmbientSound::AmbientSound(const lisp::Lisp& lisp)
{
- set_group( COLGROUP_DISABLED );
- float dimensionX = 0;
- float dimensionY = 0;
- lisp.get("width" , dimensionX);
- lisp.get("height", dimensionY);
- set_size( dimensionX, dimensionY );
+ 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 );
// set dimension to zero if smaller than 64, which is default size in flexlay
- if ((get_width() <= 64) && (get_height() <= 64)) {
- set_size(0, 0);
+ if ((dimension.x <= 64) || (dimension.y <= 64)) {
+ dimension.x = 0;
+ dimension.y = 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) :
- sample(file), sound_source(0), latency(0), distance_factor(factor*factor),
- distance_bias(bias*bias), maximumvolume(vol), currentvolume(0)
+AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std::string file)
{
- bbox.p1 = pos;
- bbox.p2 = pos;
+ 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;
// 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<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);
+ 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);
// 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)
{
- if(name.empty()) return;
- expose_object(vm, table_idx, dynamic_cast<Scripting::AmbientSound *>(this), name, false);
+ Scripting::AmbientSound* interface = static_cast<Scripting::AmbientSound*> (this);
+ expose_object(vm, table_idx, interface, 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() const
+{
+ return position.x;
+}
+
+float
+AmbientSound::get_pos_y() const
+{
+ return position.y;
+}
+
IMPLEMENT_FACTORY(AmbientSound, "ambient_sound");
#ifndef __AMBIENT_SOUND_H__
#define __AMBIENT_SOUND_H__
-#include "moving_object.hpp"
+#include "game_object.hpp"
#include "resources.hpp"
#include "player.hpp"
#include "script_interface.hpp"
class SoundSource;
-class AmbientSound : public MovingObject, public ScriptInterface, public Scripting::AmbientSound
+class AmbientSound : public GameObject, 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 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();
+ return position;
}
- float get_pos_y() const
- {
- return MovingObject::get_pos_y();
- }
- // --- END METHODS TO EXPOSE TO SQUIRREL --- //
+ // --- Scripting Interface ---
- HitResponse collision(GameObject&, const CollisionHit&)
- {
- return ABORT_MOVE;
- }
+ void set_pos(float x, float y);
+ float get_pos_x() const;
+ float get_pos_y() const;
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);
- 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, std::string name) :
- GameObject(name), mode(NORMAL), sector(newsector), do_backscrolling(true),
- scrollchange(NONE)
+Camera::Camera(Sector* newsector, std::string name)
+ : mode(NORMAL), sector(newsector), do_backscrolling(true),
+ scrollchange(NONE)
{
+ this->name = name;
}
Camera::~Camera()
static const float BORDER_SIZE = 75;
-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)
+DisplayEffect::DisplayEffect(std::string 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)
{
+ this->name = name;
}
DisplayEffect::~DisplayEffect()
void
DisplayEffect::update(float elapsed_time)
{
- switch(screen_fade) {
- case NO_FADE:
- break;
- case FADE_IN:
- screen_fading -= elapsed_time;
- if(screen_fading < 0) {
- screen_fade = NO_FADE;
- }
- break;
- case FADE_OUT:
- screen_fading -= elapsed_time;
- if(screen_fading < 0) {
- screen_fade = NO_FADE;
- black = true;
- }
- break;
- default:
- assert(false);
+ switch(screen_fade) {
+ case NO_FADE:
+ break;
+ case FADE_IN:
+ screen_fading -= elapsed_time;
+ if(screen_fading < 0) {
+ screen_fade = NO_FADE;
}
+ break;
+ case FADE_OUT:
+ screen_fading -= elapsed_time;
+ if(screen_fading < 0) {
+ screen_fade = NO_FADE;
+ black = true;
+ }
+ break;
+ default:
+ assert(false);
+ }
- switch(border_fade) {
- case NO_FADE:
- break;
- case FADE_IN:
- border_fading -= elapsed_time;
- if(border_fading < 0) {
- border_fade = NO_FADE;
- }
- border_size = border_fading / border_fading * BORDER_SIZE;
- break;
- case FADE_OUT:
- border_fading -= elapsed_time;
- if(border_fading < 0) {
- borders = false;
- border_fade = NO_FADE;
- }
- border_size = (border_fadetime - border_fading)
- / border_fadetime * BORDER_SIZE;
- break;
- default:
- assert(false);
+ switch(border_fade) {
+ case NO_FADE:
+ break;
+ case FADE_IN:
+ border_fading -= elapsed_time;
+ if(border_fading < 0) {
+ border_fade = NO_FADE;
}
+ border_size = border_fading / border_fading * BORDER_SIZE;
+ break;
+ case FADE_OUT:
+ border_fading -= elapsed_time;
+ if(border_fading < 0) {
+ borders = false;
+ border_fade = NO_FADE;
+ }
+ border_size = (border_fadetime - border_fading)
+ / border_fadetime * BORDER_SIZE;
+ break;
+ default:
+ assert(false);
+ }
}
void
DisplayEffect::draw(DrawingContext& context)
{
- context.push_transform();
- context.set_translation(Vector(0, 0));
-
- if(black || screen_fade != NO_FADE) {
- float alpha;
- if(black) {
- alpha = 1.0f;
- } else {
- switch(screen_fade) {
- case FADE_IN:
- alpha = screen_fading / screen_fadetime;
- break;
- case FADE_OUT:
- alpha = (screen_fadetime - screen_fading) / screen_fadetime;
- break;
- default:
- alpha = 0;
- assert(false);
- }
+ context.push_transform();
+ context.set_translation(Vector(0, 0));
+
+ if(black || screen_fade != NO_FADE) {
+ float alpha;
+ if(black) {
+ alpha = 1.0f;
+ } else {
+ switch(screen_fade) {
+ case FADE_IN:
+ alpha = screen_fading / screen_fadetime;
+ break;
+ case FADE_OUT:
+ alpha = (screen_fadetime - screen_fading) / screen_fadetime;
+ break;
+ default:
+ alpha = 0;
+ assert(false);
}
- context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
- Color(0, 0, 0, alpha), LAYER_GUI-10);
}
+ context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
+ Color(0, 0, 0, alpha), LAYER_GUI-10);
+ }
- if (borders) {
- context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, border_size),
- Color(0, 0, 0, 1.0f), LAYER_GUI-10);
- context.draw_filled_rect(Vector(0, SCREEN_HEIGHT - border_size), Vector(SCREEN_WIDTH, border_size),
- Color(0, 0, 0, 1.0f), LAYER_GUI-10);
- }
+ if (borders) {
+ context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, border_size),
+ Color(0, 0, 0, 1.0f), LAYER_GUI-10);
+ context.draw_filled_rect(Vector(0, SCREEN_HEIGHT - border_size), Vector(SCREEN_WIDTH, border_size),
+ Color(0, 0, 0, 1.0f), LAYER_GUI-10);
+ }
- context.pop_transform();
+ context.pop_transform();
}
void
DisplayEffect::fade_out(float fadetime)
{
- black = false;
- screen_fadetime = fadetime;
- screen_fading = fadetime;
- screen_fade = FADE_OUT;
+ black = false;
+ screen_fadetime = fadetime;
+ screen_fading = fadetime;
+ screen_fade = FADE_OUT;
}
void
DisplayEffect::fade_in(float fadetime)
{
- black = false;
- this->screen_fadetime = fadetime;
- screen_fading = fadetime;
- screen_fade = FADE_IN;
+ black = false;
+ this->screen_fadetime = fadetime;
+ screen_fading = fadetime;
+ screen_fade = FADE_IN;
}
void
DisplayEffect::set_black(bool enabled)
{
- black = enabled;
+ black = enabled;
}
bool
DisplayEffect::is_black()
{
- return black;
+ return black;
}
void
sprite->set_action("empty");
start_bounce();
- set_solid(true);
set_group(COLGROUP_STATIC);
visible = true;
}
// 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 02111-1307, USA.
-
#include <config.h>
+
#include <stdexcept>
#include "moving_sprite.hpp"
}
MovingSprite::MovingSprite(const lisp::Lisp& reader, const Vector& pos, int layer, CollisionGroup collision_group)
- : MovingObject(reader), layer(layer)
+ : layer(layer)
{
bbox.set_pos(pos);
- if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set");
+ if (!reader.get("sprite", sprite_name))
+ throw std::runtime_error("no sprite name set");
+
sprite = sprite_manager->create(sprite_name);
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
set_group(collision_group);
}
MovingSprite::MovingSprite(const lisp::Lisp& reader, const std::string& sprite_name, int layer, CollisionGroup collision_group)
- : MovingObject(reader), sprite_name(sprite_name), layer(layer)
+ : 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");
+ 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");
+
sprite = sprite_manager->create(sprite_name);
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
set_group(collision_group);
}
MovingSprite::MovingSprite(const lisp::Lisp& reader, int layer, CollisionGroup collision_group)
- : MovingObject(reader), layer(layer)
+ : 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");
- if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set");
+ 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");
+ if (!reader.get("sprite", sprite_name))
+ throw std::runtime_error("no sprite name set");
+
sprite = sprite_manager->create(sprite_name);
bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height());
set_group(collision_group);
MovingSprite&
MovingSprite::operator=(const MovingSprite& other)
{
- if (this == &other) return *this;
+ if (this == &other)
+ return *this;
delete sprite;
sprite = new Sprite(*other.sprite);
path->read(*pathLisp);
walker.reset(new PathWalker(path.get(), running));
bbox.set_pos(path->get_base());
-
- set_solid(true);
}
Platform::Platform(const Platform& other)
feet->draw(context, pos, layer-2);
}
-Player::Player(PlayerStatus* _player_status, std::string name) :
- MovingObject(name), player_status(_player_status), grabbed_object(NULL),
- ghost_mode(false)
+Player::Player(PlayerStatus* _player_status, const std::string& name)
+ : player_status(_player_status), grabbed_object(NULL), ghost_mode(false)
{
+ this->name = name;
controller = main_controller;
smalltux_gameover = sprite_manager->create("images/creatures/tux_small/smalltux-gameover.sprite");
smalltux_star = sprite_manager->create("images/creatures/tux_small/smalltux-star.sprite");
void
Player::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name.empty()) return;
+ 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)
{
- if (name.empty()) return;
+ if (name.empty())
+ return;
+
Scripting::unexpose_object(vm, table_idx, name);
}
Physic physic;
public:
- Player(PlayerStatus* player_status, std::string name = "");
+ Player(PlayerStatus* player_status, const 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
+ virtual bool is_portable() const
{
- return portable;
+ return true;
}
- // --- END METHODS TO EXPOSE TO SQUIRREL --- //
-
-private:
- bool portable; /**< true if this object can currently be carried */
};
#endif
}
Rock::Rock(const lisp::Lisp& reader)
- : MovingSprite(reader, "images/objects/rock/rock.sprite")
+ : MovingSprite(reader, "images/objects/rock/rock.sprite")
{
sound_manager->preload( ROCK_SOUND );
on_ground = false;
grabbed = false;
- set_solid(true);
- set_portable(true);
}
void
SkullTile::SkullTile(const lisp::Lisp& lisp)
: MovingSprite(lisp, "images/objects/skull_tile/skull_tile.sprite", LAYER_TILES, COLGROUP_STATIC), hit(false), falling(false)
{
- set_solid(true);
}
HitResponse
if(timer.check()) {
falling = true;
physic.enable_gravity(true);
- set_solid(false);
timer.stop();
} else if(!timer.started()) {
timer.start(FALLTIME);
#include "scripting/squirrel_util.hpp"
#include "log.hpp"
-TextObject::TextObject(std::string name) :
- GameObject(name), fading(0), fadetime(0), visible(false)
+TextObject::TextObject(std::string name)
+ : fading(0), fadetime(0), visible(false)
{
+ this->name = name;
font = blue_text;
centered = false;
}
void
TextObject::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name.empty()) return;
+ 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)
{
- if (name.empty()) return;
+ if (name.empty())
+ return;
+
Scripting::unexpose_object(vm, table_idx, name);
}
}
Thunderstorm::Thunderstorm(const lisp::Lisp& reader)
- : GameObject(reader), running(true), interval(10.0f)
+ : running(true), interval(10.0f)
{
reader.get("name", name);
reader.get("running", running);
}
TileMap::TileMap(const lisp::Lisp& reader, TileManager* new_tile_manager)
- : GameObject(reader), solid(false), speed(1), width(-1), height(-1), z_pos(0), x_offset(0), y_offset(0),
- drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0), remaining_fade_time(0)
+ : solid(false), speed(1), width(-1), height(-1), z_pos(0),
+ x_offset(0), y_offset(0),
+ drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0),
+ remaining_fade_time(0)
{
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);
}
TileMap::TileMap(std::string name, int z_pos, bool solid, size_t width, size_t height)
- : GameObject(name), solid(solid), speed(1), width(0), height(0), z_pos(z_pos),
- x_offset(0), y_offset(0), drawing_effect(NO_EFFECT), alpha(1.0), current_alpha(1.0), remaining_fade_time(0)
+ : solid(solid), speed(1), width(0), height(0), z_pos(z_pos),
+ x_offset(0), y_offset(0), drawing_effect(NO_EFFECT), alpha(1.0),
+ current_alpha(1.0), remaining_fade_time(0)
{
+ this->name = name;
tilemanager = tile_manager;
resize(width, height);
physic.enable_gravity(true);
on_ground = false;
- bool portable = true;
+ portable = true;
//Check if this trampoline is not portable
if( lisp.get( "portable", portable ) ){
if( !portable ){
sprite->set_action("normal");
}
}
- set_portable(portable);
}
void
-Trampoline::update( float elapsed_time ){
- if( !on_ground ){
- movement = physic.get_movement(elapsed_time);
- }
- if(sprite->animation_done()) {
- sprite->set_action("normal");
- }
+Trampoline::update( float elapsed_time )
+{
+ if(!on_ground) {
+ movement = physic.get_movement(elapsed_time);
+ }
+ if(sprite->animation_done()) {
+ sprite->set_action("normal");
+ }
}
HitResponse
physic.set_velocity(0, 0);
}
+bool
+Trampoline::is_portable() const
+{
+ return portable;
+}
IMPLEMENT_FACTORY(Trampoline, "trampoline");
/**
* Jumping on a trampolin makes tux jump higher.
*/
-class Trampoline : public MovingSprite,
- public Portable
-
+class Trampoline : public MovingSprite, public Portable
{
public:
Trampoline(const lisp::Lisp& reader);
HitResponse collision(GameObject& other, const CollisionHit& hit);
- void collision_solid( const CollisionHit& hit );
- void update( float elapsed_time );
+ void collision_solid(const CollisionHit& hit);
+ void update(float elapsed_time);
void grab( MovingObject&, const Vector& pos, Direction );
void ungrab(MovingObject& , Direction );
+ bool is_portable() const;
private:
Physic physic;
bool on_ground;
+ bool portable;
};
#endif
if (sprite->animation_done()) {
state = STATE_DISINTEGRATING;
sprite->set_action("disintegrating", 1);
- set_solid(false);
set_group(COLGROUP_DISABLED);
physic.enable_gravity(true);
}
: MovingSprite(lisp, "images/objects/strawbox/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL)
{
sprite->set_action("normal");
- set_solid(true);
}
HitResponse
state = STATE_DISINTEGRATING;
sprite->set_action("disintegrating", 1);
spreadHit();
- set_solid(false);
set_group(COLGROUP_DISABLED);
}
break;
#include "scripting/wind.hpp"
#include "scripting/squirrel_util.hpp"
-Wind::Wind(const lisp::Lisp& reader) :
- MovingObject(reader), blowing(true), acceleration(100),
- elapsed_time(0)
+Wind::Wind(const lisp::Lisp& reader)
+ : blowing(true), acceleration(100), elapsed_time(0)
{
+ reader.get("name", name);
reader.get("x", bbox.p1.x);
reader.get("y", bbox.p1.y);
float w = 32, h = 32;
void
Wind::expose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name == "") return;
+ if (name == "")
+ return;
+
Scripting::Wind* interface = new Scripting::Wind(this);
expose_object(vm, table_idx, interface, name, true);
}
void
Wind::unexpose(HSQUIRRELVM vm, SQInteger table_idx)
{
- if (name == "") return;
+ if (name == "")
+ return;
+
Scripting::unexpose_object(vm, table_idx, name);
}
{
LevelTile::LevelTile(const std::string& basedir, const lisp::Lisp* lisp)
- : GameObject(*lisp), solved(false), auto_path(true), basedir(basedir), picture_cached(false), picture(0)
+ : solved(false), auto_path(true), basedir(basedir), picture_cached(false),
+ picture(0)
{
+ lisp->get("name", name);
lisp->get("x", pos.x);
lisp->get("y", pos.y);