From: Matthias Braun Date: Wed, 2 Aug 2006 22:23:22 +0000 (+0000) Subject: Reverted bigger parts of tuxdev patch: X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=4a486d92343d1824b311c234e9321e08f280fe68;p=supertux.git Reverted bigger parts of tuxdev patch: - Don't push convenience functions into MovingObject/GameObject - Don't allow modification of position/size of gameobjects, that's not safe - solid flag is removed now - Reverted AmbientSound changes - don't add fields to Portable interface SVN-Revision: 4114 --- diff --git a/src/badguy/mriceblock.cpp b/src/badguy/mriceblock.cpp index c4c0b1674..7b954bfc5 100644 --- a/src/badguy/mriceblock.cpp +++ b/src/badguy/mriceblock.cpp @@ -210,8 +210,6 @@ MrIceBlock::set_state(IceState state) if(ice_state == state) return; - set_portable(state == ICESTATE_FLAT); - switch(state) { case ICESTATE_NORMAL: WalkingBadguy::activate(); @@ -259,4 +257,10 @@ MrIceBlock::ungrab(MovingObject& , Direction dir) set_group(COLGROUP_MOVING); } +bool +MrIceBlock::is_portable() const +{ + return ice_state == ICESTATE_FLAT; +} + IMPLEMENT_FACTORY(MrIceBlock, "mriceblock") diff --git a/src/badguy/mriceblock.hpp b/src/badguy/mriceblock.hpp index 26546c4e8..93aba4e13 100644 --- a/src/badguy/mriceblock.hpp +++ b/src/badguy/mriceblock.hpp @@ -40,6 +40,8 @@ public: 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); } diff --git a/src/game_object.cpp b/src/game_object.cpp index 08c0eb148..ee63ec1c1 100644 --- a/src/game_object.cpp +++ b/src/game_object.cpp @@ -22,26 +22,20 @@ #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; } } + diff --git a/src/game_object.hpp b/src/game_object.hpp index 77c398058..76b0883c6 100644 --- a/src/game_object.hpp +++ b/src/game_object.hpp @@ -35,13 +35,11 @@ class ObjectRemoveListener; * 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 @@ -80,14 +78,10 @@ public: 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 @@ -103,7 +97,12 @@ private: 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*/ + diff --git a/src/moving_object.cpp b/src/moving_object.cpp index 07be14103..f71e909d0 100644 --- a/src/moving_object.cpp +++ b/src/moving_object.cpp @@ -20,26 +20,9 @@ #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() diff --git a/src/moving_object.hpp b/src/moving_object.hpp index b23302ad4..b2f3de995 100644 --- a/src/moving_object.hpp +++ b/src/moving_object.hpp @@ -77,8 +77,7 @@ enum CollisionGroup { 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 */ @@ -136,80 +135,27 @@ public: * 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) */ @@ -229,8 +175,6 @@ private: * during collision detection */ Rect dest; - - bool solid; /**< true if this object should be considered when doing collision detection */ }; #endif diff --git a/src/object/ambient_sound.cpp b/src/object/ambient_sound.cpp index 9521070ef..43ffbdeda 100644 --- a/src/object/ambient_sound.cpp +++ b/src/object/ambient_sound.cpp @@ -32,16 +32,28 @@ #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 ); @@ -50,8 +62,9 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) : // 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) @@ -67,14 +80,23 @@ AmbientSound::AmbientSound(const lisp::Lisp& lisp) : 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 @@ -82,6 +104,9 @@ AmbientSound::AmbientSound(Vector pos, float factor, float bias, float vol, std: silence_distance = 10e99; else silence_distance = 1/distance_factor; + + sound_source = 0; // not playing at the beginning + latency=0; } AmbientSound::~AmbientSound() { @@ -131,10 +156,10 @@ AmbientSound::update(float deltat) py=Sector::current()->player->get_pos().y; // Relate to which point in the area - rx=pxset_gain(currentvolume*maximumvolume); if (sqrdistance>=silence_distance && currentvolume<1e-3) - stop_playing(); + stop_playing(); latency=0; } else { if (sqrdistance(this), name, false); + Scripting::AmbientSound* interface = static_cast (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"); diff --git a/src/object/ambient_sound.hpp b/src/object/ambient_sound.hpp index 9adf724e3..948df9c7e 100644 --- a/src/object/ambient_sound.hpp +++ b/src/object/ambient_sound.hpp @@ -43,7 +43,7 @@ #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" @@ -51,43 +51,27 @@ 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); @@ -98,6 +82,10 @@ protected: 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; diff --git a/src/object/block.cpp b/src/object/block.cpp index c5b0b7a6c..b9fae8393 100644 --- a/src/object/block.cpp +++ b/src/object/block.cpp @@ -53,7 +53,6 @@ Block::Block(Sprite* newsprite) { 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"); } diff --git a/src/object/camera.cpp b/src/object/camera.cpp index ae6fecb2d..b9d0097bb 100644 --- a/src/object/camera.cpp +++ b/src/object/camera.cpp @@ -39,10 +39,11 @@ #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() diff --git a/src/object/display_effect.cpp b/src/object/display_effect.cpp index 4e6a35265..a01e9db50 100644 --- a/src/object/display_effect.cpp +++ b/src/object/display_effect.cpp @@ -27,11 +27,12 @@ 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() @@ -55,115 +56,115 @@ DisplayEffect::unexpose(HSQUIRRELVM vm, SQInteger table_idx) 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 diff --git a/src/object/invisible_block.cpp b/src/object/invisible_block.cpp index 621dfb4de..045e31999 100644 --- a/src/object/invisible_block.cpp +++ b/src/object/invisible_block.cpp @@ -69,7 +69,6 @@ InvisibleBlock::hit(Player& ) sprite->set_action("empty"); start_bounce(); - set_solid(true); set_group(COLGROUP_STATIC); visible = true; } diff --git a/src/object/moving_sprite.cpp b/src/object/moving_sprite.cpp index 8dc5376ea..aad264ac0 100644 --- a/src/object/moving_sprite.cpp +++ b/src/object/moving_sprite.cpp @@ -16,8 +16,8 @@ // 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 + #include #include "moving_sprite.hpp" @@ -45,31 +45,40 @@ MovingSprite::MovingSprite(const Vector& pos, const std::string& sprite_name, in } 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); @@ -84,7 +93,8 @@ MovingSprite::MovingSprite(const MovingSprite& other) MovingSprite& MovingSprite::operator=(const MovingSprite& other) { - if (this == &other) return *this; + if (this == &other) + return *this; delete sprite; sprite = new Sprite(*other.sprite); diff --git a/src/object/platform.cpp b/src/object/platform.cpp index e890b92b5..3ea71eca8 100644 --- a/src/object/platform.cpp +++ b/src/object/platform.cpp @@ -46,8 +46,6 @@ Platform::Platform(const lisp::Lisp& reader) path->read(*pathLisp); walker.reset(new PathWalker(path.get(), running)); bbox.set_pos(path->get_base()); - - set_solid(true); } Platform::Platform(const Platform& other) diff --git a/src/object/player.cpp b/src/object/player.cpp index a80ea94ff..dc2ae8109 100644 --- a/src/object/player.cpp +++ b/src/object/player.cpp @@ -108,10 +108,10 @@ TuxBodyParts::draw(DrawingContext& context, const Vector& pos, int layer) 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"); @@ -171,14 +171,18 @@ Player::init() void Player::expose(HSQUIRRELVM vm, SQInteger table_idx) { - if (name.empty()) return; + if (name.empty()) + return; + Scripting::expose_object(vm, table_idx, dynamic_cast(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); } diff --git a/src/object/player.hpp b/src/object/player.hpp index bfe1ba10a..409b19ddb 100644 --- a/src/object/player.hpp +++ b/src/object/player.hpp @@ -122,7 +122,7 @@ public: 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); diff --git a/src/object/portable.hpp b/src/object/portable.hpp index d3a2aef97..721879d6a 100644 --- a/src/object/portable.hpp +++ b/src/object/portable.hpp @@ -33,10 +33,6 @@ class Portable { public: - Portable(bool portable = false) : - portable(portable) - { - } virtual ~Portable() { } @@ -48,20 +44,10 @@ public: 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 diff --git a/src/object/rock.cpp b/src/object/rock.cpp index 6c45b0b9c..fc4fbe0a1 100644 --- a/src/object/rock.cpp +++ b/src/object/rock.cpp @@ -29,13 +29,11 @@ namespace { } 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 diff --git a/src/object/skull_tile.cpp b/src/object/skull_tile.cpp index 814309393..26b86bd56 100644 --- a/src/object/skull_tile.cpp +++ b/src/object/skull_tile.cpp @@ -34,7 +34,6 @@ static const float FALLTIME = 0.8; 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 @@ -72,7 +71,6 @@ SkullTile::update(float elapsed_time) if(timer.check()) { falling = true; physic.enable_gravity(true); - set_solid(false); timer.stop(); } else if(!timer.started()) { timer.start(FALLTIME); diff --git a/src/object/text_object.cpp b/src/object/text_object.cpp index 19c94164e..d7f8bed18 100644 --- a/src/object/text_object.cpp +++ b/src/object/text_object.cpp @@ -27,9 +27,10 @@ #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; } @@ -41,14 +42,18 @@ TextObject::~TextObject() void TextObject::expose(HSQUIRRELVM vm, SQInteger table_idx) { - if (name.empty()) return; + if (name.empty()) + return; + Scripting::expose_object(vm, table_idx, dynamic_cast(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); } diff --git a/src/object/thunderstorm.cpp b/src/object/thunderstorm.cpp index 1253b352f..b5d1627e8 100644 --- a/src/object/thunderstorm.cpp +++ b/src/object/thunderstorm.cpp @@ -42,7 +42,7 @@ namespace { } 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); diff --git a/src/object/tilemap.cpp b/src/object/tilemap.cpp index ebef4abeb..ce94a3cf3 100644 --- a/src/object/tilemap.cpp +++ b/src/object/tilemap.cpp @@ -45,13 +45,16 @@ TileMap::TileMap() } 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); @@ -79,9 +82,11 @@ TileMap::TileMap(const lisp::Lisp& reader, TileManager* new_tile_manager) } 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); diff --git a/src/object/trampoline.cpp b/src/object/trampoline.cpp index 73768757c..bd21fd368 100644 --- a/src/object/trampoline.cpp +++ b/src/object/trampoline.cpp @@ -41,7 +41,7 @@ Trampoline::Trampoline(const lisp::Lisp& lisp) 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 ){ @@ -51,17 +51,17 @@ Trampoline::Trampoline(const lisp::Lisp& lisp) 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 @@ -128,5 +128,10 @@ Trampoline::ungrab(MovingObject& , Direction ){ physic.set_velocity(0, 0); } +bool +Trampoline::is_portable() const +{ + return portable; +} IMPLEMENT_FACTORY(Trampoline, "trampoline"); diff --git a/src/object/trampoline.hpp b/src/object/trampoline.hpp index 8f846c655..788fe2add 100644 --- a/src/object/trampoline.hpp +++ b/src/object/trampoline.hpp @@ -28,23 +28,23 @@ /** * 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 diff --git a/src/object/unstable_tile.cpp b/src/object/unstable_tile.cpp index 67578c50d..089a18d62 100644 --- a/src/object/unstable_tile.cpp +++ b/src/object/unstable_tile.cpp @@ -62,7 +62,6 @@ UnstableTile::update(float elapsed_time) if (sprite->animation_done()) { state = STATE_DISINTEGRATING; sprite->set_action("disintegrating", 1); - set_solid(false); set_group(COLGROUP_DISABLED); physic.enable_gravity(true); } diff --git a/src/object/weak_block.cpp b/src/object/weak_block.cpp index 90f3006cd..182efae8c 100644 --- a/src/object/weak_block.cpp +++ b/src/object/weak_block.cpp @@ -34,7 +34,6 @@ WeakBlock::WeakBlock(const lisp::Lisp& lisp) : MovingSprite(lisp, "images/objects/strawbox/strawbox.sprite", LAYER_TILES, COLGROUP_STATIC), state(STATE_NORMAL) { sprite->set_action("normal"); - set_solid(true); } HitResponse @@ -77,7 +76,6 @@ WeakBlock::update(float ) state = STATE_DISINTEGRATING; sprite->set_action("disintegrating", 1); spreadHit(); - set_solid(false); set_group(COLGROUP_DISABLED); } break; diff --git a/src/object/wind.cpp b/src/object/wind.cpp index c4c9b8c79..5a392c26f 100644 --- a/src/object/wind.cpp +++ b/src/object/wind.cpp @@ -29,10 +29,10 @@ #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; @@ -91,7 +91,9 @@ Wind::collision(GameObject& other, const CollisionHit& ) 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); } @@ -99,7 +101,9 @@ Wind::expose(HSQUIRRELVM vm, SQInteger table_idx) void Wind::unexpose(HSQUIRRELVM vm, SQInteger table_idx) { - if (name == "") return; + if (name == "") + return; + Scripting::unexpose_object(vm, table_idx, name); } diff --git a/src/worldmap/level.cpp b/src/worldmap/level.cpp index 3f324964b..129f493a4 100644 --- a/src/worldmap/level.cpp +++ b/src/worldmap/level.cpp @@ -32,8 +32,10 @@ namespace WorldMapNS { 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);