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