[ Patch #1793 ] Turn physic into POD
[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.gravity_enabled = 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.gravity_enabled = 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.vx = initial_velocity.x;
71   physic.vy = initial_velocity.y;
72   sprite->set_action("default");
73 }
74
75 void
76 MoleRock::deactivate()
77 {
78   remove_me();
79 }
80
81 void
82 MoleRock::active_update(float elapsed_time)
83 {
84   BadGuy::active_update(elapsed_time);
85 }
86
87 void
88 MoleRock::collision_solid(const CollisionHit& )
89 {
90   sound_manager->play("sounds/darthit.wav", get_pos());
91   remove_me();
92 }
93
94 HitResponse
95 MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& )
96 {
97   // ignore collisions with parent
98   if (&badguy == parent) {
99     return FORCE_MOVE;
100   }
101   sound_manager->play("sounds/stomp.wav", get_pos());
102   remove_me();
103   badguy.kill_fall();
104   return ABORT_MOVE;
105 }
106
107 HitResponse
108 MoleRock::collision_player(Player& player, const CollisionHit& hit)
109 {
110   sound_manager->play("sounds/stomp.wav", get_pos());
111   remove_me();
112   return BadGuy::collision_player(player, hit);
113 }
114
115 IMPLEMENT_FACTORY(MoleRock, "mole_rock")