#include <config.h>
#include <stdexcept>
+#include <math.h>
#include "scripted_object.hpp"
#include "video/drawing_context.hpp"
}
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");