3 #include "unstable_tile.h"
5 #include "object_factory.h"
9 #include "special/sprite_manager.h"
10 #include "special/sprite.h"
12 static const float CRACKTIME = 0.3;
13 static const float FALLTIME = 0.8;
15 UnstableTile::UnstableTile(const lisp::Lisp& lisp)
16 : hit(false), falling(false)
18 lisp.get("x", bbox.p1.x);
19 lisp.get("y", bbox.p1.y);
20 bbox.set_size(32, 32);
21 sprite = sprite_manager->create("unstable_tile");
25 UnstableTile::~UnstableTile()
31 UnstableTile::collision(GameObject& other, const CollisionHit& hitdata)
33 if(hitdata.normal.y < 0.8)
36 Player* player = dynamic_cast<Player*> (&other);
44 UnstableTile::draw(DrawingContext& context)
46 Vector pos = get_pos();
48 if(timer.get_timegone() > CRACKTIME) {
49 pos.x += (rand() % 6) - 3;
52 sprite->draw(context, pos, LAYER_TILES);
56 UnstableTile::action(float elapsed_time)
59 movement = physic.get_movement(elapsed_time);
60 if(!Sector::current()->inside(bbox)) {
67 physic.enable_gravity(true);
70 } else if(!timer.started()) {
71 timer.start(FALLTIME);
79 IMPLEMENT_FACTORY(UnstableTile, "unstable_tile");