1c05ef0d2f282714386bc32f4ab769f15ea3a6ac
[supertux.git] / src / badguy / mole_rock.cpp
1 //  $Id$
2 //
3 //  MoleRock - Rock thrown by "Mole" Badguy
4 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.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
19 //  02111-1307, USA.
20
21 #include <config.h>
22
23 #include "mole_rock.hpp"
24
25 #include "lisp/writer.hpp"
26 #include "object_factory.hpp"
27 #include "audio/sound_manager.hpp"
28 #include "sprite/sprite.hpp"
29
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))
32 {
33   physic.enable_gravity(true);
34   countMe = false;
35   sound_manager->preload("sounds/darthit.wav");
36   sound_manager->preload("sounds/stomp.wav");
37 }
38
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)
41 {
42   physic.enable_gravity(true);
43   countMe = false;
44   sound_manager->preload("sounds/darthit.wav");
45   sound_manager->preload("sounds/stomp.wav");
46 }
47
48 MoleRock::MoleRock(const MoleRock& other)
49         : BadGuy(other), parent(other.parent), initial_velocity(Vector(0, -400))
50 {
51   sound_manager->preload("sounds/darthit.wav");
52   sound_manager->preload("sounds/stomp.wav");
53 }
54
55 MoleRock::~MoleRock()
56 {
57 }
58
59 bool
60 MoleRock::updatePointers(const GameObject* from_object, GameObject* to_object)
61 {
62   if (from_object == parent) {
63     parent = dynamic_cast<MoleRock*>(to_object);
64     return true;
65   }
66   return false;
67 }
68
69 void
70 MoleRock::write(lisp::Writer& writer)
71 {
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");
76 }
77
78 void
79 MoleRock::initialize()
80 {
81   physic.set_velocity(initial_velocity);
82   sprite->set_action("default");
83 }
84
85 void
86 MoleRock::deactivate()
87 {
88   remove_me();
89 }
90
91 void
92 MoleRock::active_update(float elapsed_time)
93 {
94   BadGuy::active_update(elapsed_time);
95 }
96
97 void
98 MoleRock::collision_solid(const CollisionHit& )
99 {
100   sound_manager->play("sounds/darthit.wav", get_pos());
101   remove_me();
102 }
103
104 HitResponse
105 MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& )
106 {
107   // ignore collisions with parent
108   if (&badguy == parent) {
109     return FORCE_MOVE;
110   }
111   sound_manager->play("sounds/stomp.wav", get_pos());
112   remove_me();
113   badguy.kill_fall();
114   return ABORT_MOVE;
115 }
116
117 HitResponse
118 MoleRock::collision_player(Player& player, const CollisionHit& hit)
119 {
120   sound_manager->play("sounds/stomp.wav", get_pos());
121   remove_me();
122   return BadGuy::collision_player(player, hit);
123 }
124
125 IMPLEMENT_FACTORY(MoleRock, "mole_rock")