5 #include "scripted_object.h"
6 #include "video/drawing_context.h"
7 #include "sprite/sprite_manager.h"
9 #include "object_factory.h"
10 #include "math/vector.h"
12 ScriptedObject::ScriptedObject(const lisp::Lisp& lisp)
13 : solid(true), physic_enabled(true), visible(true)
15 lisp.get("name", name);
17 throw std::runtime_error("Scripted object must have a name specified");
19 std::string spritename;
20 lisp.get("sprite", spritename);
22 throw std::runtime_error("Scripted object must have a sprite name specified");
23 sprite = sprite_manager->create(spritename);
25 lisp.get("x", bbox.p1.x);
26 lisp.get("y", bbox.p1.y);
27 float width = sprite->get_width();
28 float height = sprite->get_height();
29 lisp.get("width", width);
30 lisp.get("height", height);
31 bbox.set_size(width, height);
33 lisp.get("solid", solid);
34 lisp.get("physic-enabled", physic_enabled);
35 lisp.get("visible", visible);
40 ScriptedObject::~ScriptedObject()
46 ScriptedObject::move(float x, float y)
48 bbox.move(Vector(x, y));
52 ScriptedObject::set_pos(float x, float y)
54 bbox.set_pos(Vector(x, y));
58 ScriptedObject::get_pos_x()
64 ScriptedObject::get_pos_y()
70 ScriptedObject::set_velocity(float x, float y)
72 physic.set_velocity(x, y);
76 ScriptedObject::get_velocity_x()
78 return physic.get_velocity_x();
82 ScriptedObject::get_velocity_y()
84 return physic.get_velocity_y();
88 ScriptedObject::set_visible(bool visible)
90 this->visible = visible;
94 ScriptedObject::is_visible()
100 ScriptedObject::set_animation(const std::string& animation)
102 sprite->set_action(animation);
106 ScriptedObject::get_animation()
108 return sprite->get_action_name();
112 ScriptedObject::get_name()
118 ScriptedObject::action(float elapsed_time)
123 movement = physic.get_movement(elapsed_time);
127 ScriptedObject::draw(DrawingContext& context)
132 sprite->draw(context, get_pos(), LAYER_OBJECTS);
136 ScriptedObject::collision(GameObject& other, const CollisionHit& )
141 if(!(other.get_flags() & FLAG_SOLID))
144 physic.set_velocity(0, 0);
148 IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject");