X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fscripted_object.cpp;h=b5ae6ed8989f85a2137629484552904ca083db37;hb=d794aac09d4a3b3f5f93985cd74381bb4de4ce84;hp=69f15ca2a37a4c4a8364cb8f49f906cda21df9e5;hpb=b4868c421ba670cd6301394558f1034e38a0c7b3;p=supertux.git diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index 69f15ca2a..b5ae6ed89 100644 --- a/src/object/scripted_object.cpp +++ b/src/object/scripted_object.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux // Copyright (C) 2006 Matthias Braun // -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 2 -// of the License, or (at your option) any later version. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -14,29 +12,31 @@ // GNU General Public License for more details. // // 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. +// along with this program. If not, see . -#include +#include "object/scripted_object.hpp" -#include -#include +#include -#include "scripted_object.hpp" -#include "video/drawing_context.hpp" #include "scripting/squirrel_util.hpp" -#include "resources.hpp" -#include "object_factory.hpp" -#include "math/vector.hpp" - -ScriptedObject::ScriptedObject(const lisp::Lisp& lisp) - : MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING), - solid(true), physic_enabled(true), visible(true), new_vel_set(false) +#include "sprite/sprite.hpp" +#include "supertux/object_factory.hpp" +#include "util/reader.hpp" + +ScriptedObject::ScriptedObject(const Reader& lisp) : + MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING_STATIC), + physic(), + name(), + solid(true), + physic_enabled(true), + visible(true), + new_vel_set(false), + new_vel() { lisp.get("name", name); if(name == "") throw std::runtime_error("Scripted object must have a name specified"); - + // FIXME: do we need this? bbox is already set via .sprite file float width = sprite->get_width(); float height = sprite->get_height(); @@ -47,22 +47,26 @@ ScriptedObject::ScriptedObject(const lisp::Lisp& lisp) lisp.get("solid", solid); lisp.get("physic-enabled", physic_enabled); lisp.get("visible", visible); - lisp.get("z-pos", layer); - if(solid) - flags |= FLAG_SOLID; + layer = reader_get_layer (lisp, /* default = */ LAYER_OBJECTS); + if( solid ){ + set_group( COLGROUP_MOVING_STATIC ); + } else { + set_group( COLGROUP_DISABLED ); + } } void ScriptedObject::expose(HSQUIRRELVM vm, SQInteger table_idx) { - Scripting::ScriptedObject* interface = static_cast (this); - expose_object(vm, table_idx, interface, name, false); + if (name.empty()) return; + expose_object(vm, table_idx, dynamic_cast(this), name, false); } void ScriptedObject::unexpose(HSQUIRRELVM vm, SQInteger table_idx) { - Scripting::unexpose_object(vm, table_idx, name); + if (name.empty()) return; + scripting::unexpose_object(vm, table_idx, name); } void @@ -74,8 +78,8 @@ ScriptedObject::move(float x, float y) void ScriptedObject::set_pos(float x, float y) { - printf("SetPos: %f %f\n", x, y); - bbox.set_pos(Vector(x, y)); + // printf("SetPos: %f %f\n", x, y); + MovingObject::set_pos(Vector(x, y)); physic.reset(); } @@ -111,9 +115,9 @@ ScriptedObject::get_velocity_y() } void -ScriptedObject::set_visible(bool visible) +ScriptedObject::set_visible(bool visible_) { - this->visible = visible; + this->visible = visible_; } bool @@ -123,6 +127,35 @@ ScriptedObject::is_visible() } void +ScriptedObject::set_solid(bool solid_) +{ + this->solid = solid_; + if( solid ){ + set_group( COLGROUP_MOVING_STATIC ); + } else { + set_group( COLGROUP_DISABLED ); + } +} + +bool +ScriptedObject::is_solid() +{ + return solid; +} + +bool +ScriptedObject::gravity_enabled() const +{ + return physic.gravity_enabled(); +} + +void +ScriptedObject::enable_gravity(bool f) +{ + physic.enable_gravity(f); +} + +void ScriptedObject::set_action(const std::string& animation) { sprite->set_action(animation); @@ -162,31 +195,28 @@ ScriptedObject::draw(DrawingContext& context) sprite->draw(context, get_pos(), layer); } -HitResponse -ScriptedObject::collision(GameObject& other, const CollisionHit& hit) +void +ScriptedObject::collision_solid(const CollisionHit& hit) { if(!physic_enabled) - return FORCE_MOVE; - - if(!(other.get_flags() & FLAG_SOLID)) - return FORCE_MOVE; - - if(other.get_flags() & FLAG_SOLID) { - if(hit.normal.y < 0) { // landed on floor - if(physic.get_velocity_y() < 0) - physic.set_velocity_y(0); - } else if(hit.normal.y > 0) { // bumped against roof - physic.set_velocity_y(.1); - } - - if(fabsf(hit.normal.x) > .9) { // hit on side? - physic.set_velocity_x(0); - } - - return CONTINUE; + return; + + if(hit.bottom) { + if(physic.get_velocity_y() > 0) + physic.set_velocity_y(0); + } else if(hit.top) { + physic.set_velocity_y(.1f); } + if(hit.left || hit.right) { + physic.set_velocity_x(0); + } +} + +HitResponse +ScriptedObject::collision(GameObject& , const CollisionHit& ) +{ return FORCE_MOVE; } -IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject"); +/* EOF */