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