Merged changes from branches/supertux-milestone2-grumbel/ to trunk/supertux/
[supertux.git] / src / badguy / mole_rock.cpp
1 //  MoleRock - Rock thrown by "Mole" Badguy
2 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "badguy/mole_rock.hpp"
18
19 #include "audio/sound_manager.hpp"
20 #include "sprite/sprite.hpp"
21 #include "supertux/object_factory.hpp"
22
23 MoleRock::MoleRock(const Reader& reader)
24   : BadGuy(reader, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(0), initial_velocity(Vector(0, -400))
25 {
26   physic.enable_gravity(true);
27   countMe = false;
28   sound_manager->preload("sounds/darthit.wav");
29   sound_manager->preload("sounds/stomp.wav");
30 }
31
32 MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent = 0) :
33   BadGuy(pos, LEFT, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), 
34   parent(parent), 
35   initial_velocity(velocity)
36 {
37   physic.enable_gravity(true);
38   countMe = false;
39   sound_manager->preload("sounds/darthit.wav");
40   sound_manager->preload("sounds/stomp.wav");
41 }
42
43 MoleRock::~MoleRock()
44 {
45 }
46
47 bool
48 MoleRock::updatePointers(const GameObject* from_object, GameObject* to_object)
49 {
50   if (from_object == parent) {
51     parent = dynamic_cast<MoleRock*>(to_object);
52     return true;
53   }
54   return false;
55 }
56
57 void
58 MoleRock::initialize()
59 {
60   physic.set_velocity(initial_velocity);
61   sprite->set_action("default");
62 }
63
64 void
65 MoleRock::deactivate()
66 {
67   remove_me();
68 }
69
70 void
71 MoleRock::active_update(float elapsed_time)
72 {
73   BadGuy::active_update(elapsed_time);
74 }
75
76 void
77 MoleRock::collision_solid(const CollisionHit& )
78 {
79   sound_manager->play("sounds/darthit.wav", get_pos());
80   remove_me();
81 }
82
83 HitResponse
84 MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& )
85 {
86   // ignore collisions with parent
87   if (&badguy == parent) {
88     return FORCE_MOVE;
89   }
90   sound_manager->play("sounds/stomp.wav", get_pos());
91   remove_me();
92   badguy.kill_fall();
93   return ABORT_MOVE;
94 }
95
96 HitResponse
97 MoleRock::collision_player(Player& player, const CollisionHit& hit)
98 {
99   sound_manager->play("sounds/stomp.wav", get_pos());
100   remove_me();
101   return BadGuy::collision_player(player, hit);
102 }
103
104 IMPLEMENT_FACTORY(MoleRock, "mole_rock");
105
106 /* EOF */