#include <config.h>
#include <stdexcept>
+#include <math.h>
#include "scripted_object.hpp"
#include "video/drawing_context.hpp"
#include "sprite/sprite_manager.hpp"
+#include "scripting/wrapper_util.hpp"
#include "resources.hpp"
#include "object_factory.hpp"
#include "math/vector.hpp"
}
void
+ScriptedObject::expose(HSQUIRRELVM vm, int table_idx)
+{
+ Scripting::ScriptedObject* interface = static_cast<Scripting::ScriptedObject*> (this);
+ expose_object(vm, table_idx, interface, name, false);
+}
+
+void
+ScriptedObject::unexpose(HSQUIRRELVM vm, int table_idx)
+{
+ Scripting::unexpose_object(vm, table_idx, name);
+}
+
+void
ScriptedObject::move(float x, float y)
{
bbox.move(Vector(x, y));
}
void
-ScriptedObject::set_animation(const std::string& animation)
+ScriptedObject::set_action(const std::string& animation)
{
sprite->set_action(animation);
}
std::string
-ScriptedObject::get_animation()
+ScriptedObject::get_action()
{
return sprite->get_action_name();
}
}
HitResponse
-ScriptedObject::collision(GameObject& other, const CollisionHit& )
+ScriptedObject::collision(GameObject& other, const CollisionHit& hit)
{
if(!physic_enabled)
return FORCE_MOVE;
if(!(other.get_flags() & FLAG_SOLID))
return FORCE_MOVE;
- physic.set_velocity(0, 0);
- return CONTINUE;
+ 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 FORCE_MOVE;
}
IMPLEMENT_FACTORY(ScriptedObject, "scriptedobject");