1 // $Id: unstable_tile.cpp 2642 2005-06-26 13:38:53Z matzebraun $
4 // Copyright (C) 2005 Matthias Braun <matze@braunis.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "skull_tile.hpp"
24 #include "lisp/lisp.hpp"
25 #include "object_factory.hpp"
28 #include "resources.hpp"
29 #include "sprite/sprite_manager.hpp"
30 #include "sprite/sprite.hpp"
32 static const float CRACKTIME = 0.3;
33 static const float FALLTIME = 0.8;
35 SkullTile::SkullTile(const lisp::Lisp& lisp)
36 : hit(false), falling(false)
38 lisp.get("x", bbox.p1.x);
39 lisp.get("y", bbox.p1.y);
40 bbox.set_size(32, 32);
41 sprite = sprite_manager->create("skull_tile");
45 SkullTile::~SkullTile()
51 SkullTile::collision(GameObject& other, const CollisionHit& hitdata)
53 if(hitdata.normal.y < 0.8)
56 Player* player = dynamic_cast<Player*> (&other);
64 SkullTile::draw(DrawingContext& context)
66 Vector pos = get_pos();
68 if(timer.get_timegone() > CRACKTIME) {
69 pos.x += (rand() % 6) - 3;
72 sprite->draw(context, pos, LAYER_TILES);
76 SkullTile::update(float elapsed_time)
79 movement = physic.get_movement(elapsed_time);
80 if(!Sector::current()->inside(bbox)) {
87 physic.enable_gravity(true);
90 } else if(!timer.started()) {
91 timer.start(FALLTIME);
99 IMPLEMENT_FACTORY(SkullTile, "skull_tile");