3 // MoleRock - Rock thrown by "Mole" Badguy
4 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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
23 #include "mole_rock.hpp"
25 #include "lisp/writer.hpp"
26 #include "object_factory.hpp"
27 #include "audio/sound_manager.hpp"
28 #include "sprite/sprite.hpp"
30 MoleRock::MoleRock(const lisp::Lisp& reader)
31 : BadGuy(reader, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(0), initial_velocity(Vector(0, -400))
33 physic.enable_gravity(true);
35 sound_manager->preload("sounds/darthit.wav");
36 sound_manager->preload("sounds/stomp.wav");
39 MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent = 0)
40 : BadGuy(pos, LEFT, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(parent), initial_velocity(velocity)
42 physic.enable_gravity(true);
44 sound_manager->preload("sounds/darthit.wav");
45 sound_manager->preload("sounds/stomp.wav");
48 MoleRock::MoleRock(const MoleRock& other)
49 : BadGuy(other), parent(other.parent), initial_velocity(Vector(0, -400))
51 sound_manager->preload("sounds/darthit.wav");
52 sound_manager->preload("sounds/stomp.wav");
60 MoleRock::updatePointers(const GameObject* from_object, GameObject* to_object)
62 if (from_object == parent) {
63 parent = dynamic_cast<MoleRock*>(to_object);
70 MoleRock::write(lisp::Writer& writer)
72 writer.start_list("mole_rock");
73 writer.write("x", start_position.x);
74 writer.write("y", start_position.y);
75 writer.end_list("mole_rock");
79 MoleRock::initialize()
81 physic.set_velocity(initial_velocity);
82 sprite->set_action("default");
86 MoleRock::deactivate()
92 MoleRock::active_update(float elapsed_time)
94 BadGuy::active_update(elapsed_time);
98 MoleRock::collision_solid(const CollisionHit& )
100 sound_manager->play("sounds/darthit.wav", get_pos());
105 MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& )
107 // ignore collisions with parent
108 if (&badguy == parent) {
111 sound_manager->play("sounds/stomp.wav", get_pos());
118 MoleRock::collision_player(Player& player, const CollisionHit& hit)
120 sound_manager->play("sounds/stomp.wav", get_pos());
122 return BadGuy::collision_player(player, hit);
125 IMPLEMENT_FACTORY(MoleRock, "mole_rock")