4 // Copyright (C) 2006 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 02111-1307, USA.
22 #include "skull_tile.hpp"
23 #include "lisp/lisp.hpp"
24 #include "object_factory.hpp"
27 #include "resources.hpp"
28 #include "sprite/sprite.hpp"
29 #include "random_generator.hpp"
31 static const float CRACKTIME = 0.3;
32 static const float FALLTIME = 0.8;
34 SkullTile::SkullTile(const lisp::Lisp& lisp)
35 : MovingSprite(lisp, "images/objects/skull_tile/skull_tile.sprite", LAYER_TILES, COLGROUP_STATIC), hit(false), falling(false)
40 SkullTile::collision(GameObject& other, const CollisionHit& )
42 Player* player = dynamic_cast<Player*> (&other);
50 SkullTile::draw(DrawingContext& context)
52 Vector pos = get_pos();
54 if(timer.get_timegone() > CRACKTIME) {
55 pos.x += systemRandom.rand(-3, 3);
58 sprite->draw(context, pos, layer);
62 SkullTile::update(float elapsed_time)
65 movement = physic.get_movement(elapsed_time);
66 if(!Sector::current()->inside(bbox)) {
73 physic.enable_gravity(true);
75 } else if(!timer.started()) {
76 timer.start(FALLTIME);
84 IMPLEMENT_FACTORY(SkullTile, "skull_tile");