X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fobject%2Fscripted_object.cpp;h=b5ae6ed8989f85a2137629484552904ca083db37;hb=02006fdd9da5000586077bf331620b92854c8125;hp=ee6000bbb0d5cad7943448b837c963e2e75d1a36;hpb=caf1fac28250de0cf57c703b6359e0a69730f2bf;p=supertux.git diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index ee6000bbb..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,23 +12,26 @@ // 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. -#include +// along with this program. If not, see . -#include -#include +#include "object/scripted_object.hpp" -#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" +#include -ScriptedObject::ScriptedObject(const lisp::Lisp& lisp) - : MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING), - solid(true), physic_enabled(true), visible(true), new_vel_set(false) +#include "scripting/squirrel_util.hpp" +#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 == "") @@ -46,9 +47,9 @@ 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); + layer = reader_get_layer (lisp, /* default = */ LAYER_OBJECTS); if( solid ){ - set_group( COLGROUP_MOVING ); + set_group( COLGROUP_MOVING_STATIC ); } else { set_group( COLGROUP_DISABLED ); } @@ -58,14 +59,14 @@ void ScriptedObject::expose(HSQUIRRELVM vm, SQInteger table_idx) { if (name.empty()) return; - expose_object(vm, table_idx, dynamic_cast(this), name, false); + expose_object(vm, table_idx, dynamic_cast(this), name, false); } void ScriptedObject::unexpose(HSQUIRRELVM vm, SQInteger table_idx) { if (name.empty()) return; - Scripting::unexpose_object(vm, table_idx, name); + scripting::unexpose_object(vm, table_idx, name); } void @@ -77,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(); } @@ -114,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 @@ -126,11 +127,11 @@ ScriptedObject::is_visible() } void -ScriptedObject::set_solid(bool solid) +ScriptedObject::set_solid(bool solid_) { - this->solid = solid; + this->solid = solid_; if( solid ){ - set_group( COLGROUP_MOVING ); + set_group( COLGROUP_MOVING_STATIC ); } else { set_group( COLGROUP_DISABLED ); } @@ -142,6 +143,17 @@ 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) @@ -193,7 +205,7 @@ ScriptedObject::collision_solid(const CollisionHit& hit) if(physic.get_velocity_y() > 0) physic.set_velocity_y(0); } else if(hit.top) { - physic.set_velocity_y(.1); + physic.set_velocity_y(.1f); } if(hit.left || hit.right) { @@ -207,4 +219,4 @@ ScriptedObject::collision(GameObject& , const CollisionHit& ) return FORCE_MOVE; } -IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject"); +/* EOF */