#303: Typo fixes from mathnerd314
[supertux.git] / src / object / skull_tile.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
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.
10 //
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.
15 //
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.
19
20 #include <config.h>
21
22 #include "skull_tile.hpp"
23 #include "lisp/lisp.hpp"
24 #include "object_factory.hpp"
25 #include "player.hpp"
26 #include "sector.hpp"
27 #include "resources.hpp"
28 #include "sprite/sprite.hpp"
29 #include "random_generator.hpp"
30
31 static const float CRACKTIME = 0.3f;
32 static const float FALLTIME = 0.8f;
33
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)
36 {
37 }
38
39 HitResponse
40 SkullTile::collision(GameObject& other, const CollisionHit& )
41 {
42   Player* player = dynamic_cast<Player*> (&other);
43   if(player)
44     hit = true;
45
46   return FORCE_MOVE;
47 }
48
49 void
50 SkullTile::draw(DrawingContext& context)
51 {
52   Vector pos = get_pos();
53   // shaking
54   if(timer.get_timegone() > CRACKTIME) {
55     pos.x += systemRandom.rand(-3, 3);
56   }
57
58   sprite->draw(context, pos, layer);
59 }
60
61 void
62 SkullTile::update(float elapsed_time)
63 {
64   if(falling) {
65     movement = physic.get_movement(elapsed_time);
66     if(!Sector::current()->inside(bbox)) {
67       remove_me();
68       return;
69     }
70   } else if(hit) {
71     if(timer.check()) {
72       falling = true;
73       physic.enable_gravity(true);
74       timer.stop();
75     } else if(!timer.started()) {
76       timer.start(FALLTIME);
77     }
78   } else {
79     timer.stop();
80   }
81   hit = false;
82 }
83
84 IMPLEMENT_FACTORY(SkullTile, "skull_tile");