X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fscripted_object.cpp;h=56a1fd5da8ab784b98cebb39c9fff63d0a494ae8;hb=78ac7aef674f518549f96160c6354b589553f952;hp=591053d0b0c989eec733e54944a4cfd9ba3959b0;hpb=714a30abd887def6331a193216387e66cbfbd1bb;p=supertux.git diff --git a/src/object/scripted_object.cpp b/src/object/scripted_object.cpp index 591053d0b..56a1fd5da 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_STATIC), - 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 == "") @@ -79,7 +80,7 @@ ScriptedObject::set_pos(float x, float y) { printf("SetPos: %f %f\n", x, y); bbox.set_pos(Vector(x, y)); - physic = Physic(); + physic.reset(); } float @@ -104,13 +105,13 @@ ScriptedObject::set_velocity(float x, float y) float ScriptedObject::get_velocity_x() { - return physic.vx; + return physic.get_velocity_x(); } float ScriptedObject::get_velocity_y() { - return physic.vy; + return physic.get_velocity_y(); } void @@ -142,7 +143,6 @@ ScriptedObject::is_solid() return solid; } - void ScriptedObject::set_action(const std::string& animation) { @@ -168,8 +168,7 @@ ScriptedObject::update(float elapsed_time) return; if(new_vel_set) { - physic.vx = new_vel.x; - physic.vy = new_vel.y; + physic.set_velocity(new_vel.x, new_vel.y); new_vel_set = false; } movement = physic.get_movement(elapsed_time); @@ -191,14 +190,14 @@ ScriptedObject::collision_solid(const CollisionHit& hit) return; if(hit.bottom) { - if(physic.vy > 0) - physic.vy = 0; + if(physic.get_velocity_y() > 0) + physic.set_velocity_y(0); } else if(hit.top) { - physic.vy = .1; + physic.set_velocity_y(.1f); } if(hit.left || hit.right) { - physic.vx = 0; + physic.set_velocity_x(0); } } @@ -209,3 +208,5 @@ ScriptedObject::collision(GameObject& , const CollisionHit& ) } IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject"); + +/* EOF */