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