786b39677815633c6bae2c9991cd6e666eb1e4da
[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),
25   parent(0),
26   initial_velocity(Vector(0, -400))
27 {
28   physic.enable_gravity(true);
29   countMe = false;
30   sound_manager->preload("sounds/darthit.wav");
31   sound_manager->preload("sounds/stomp.wav");
32 }
33
34 MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent = 0) :
35   BadGuy(pos, LEFT, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), 
36   parent(parent), 
37   initial_velocity(velocity)
38 {
39   physic.enable_gravity(true);
40   countMe = false;
41   sound_manager->preload("sounds/darthit.wav");
42   sound_manager->preload("sounds/stomp.wav");
43 }
44
45 MoleRock::~MoleRock()
46 {
47 }
48
49 bool
50 MoleRock::updatePointers(const GameObject* from_object, GameObject* to_object)
51 {
52   if (from_object == parent) {
53     parent = dynamic_cast<MoleRock*>(to_object);
54     return true;
55   }
56   return false;
57 }
58
59 void
60 MoleRock::initialize()
61 {
62   physic.set_velocity(initial_velocity);
63   sprite->set_action("default");
64 }
65
66 void
67 MoleRock::deactivate()
68 {
69   remove_me();
70 }
71
72 void
73 MoleRock::active_update(float elapsed_time)
74 {
75   BadGuy::active_update(elapsed_time);
76 }
77
78 void
79 MoleRock::collision_solid(const CollisionHit& )
80 {
81   sound_manager->play("sounds/darthit.wav", get_pos());
82   remove_me();
83 }
84
85 HitResponse
86 MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& )
87 {
88   // ignore collisions with parent
89   if (&badguy == parent) {
90     return FORCE_MOVE;
91   }
92   sound_manager->play("sounds/stomp.wav", get_pos());
93   remove_me();
94   badguy.kill_fall();
95   return ABORT_MOVE;
96 }
97
98 HitResponse
99 MoleRock::collision_player(Player& player, const CollisionHit& hit)
100 {
101   sound_manager->play("sounds/stomp.wav", get_pos());
102   remove_me();
103   return BadGuy::collision_player(player, hit);
104 }
105
106 /* EOF */