4 // Copyright (C) 2006 Matthias Braun <matze@braunis.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 02111-1307, USA.
23 #include "lisp/writer.hpp"
24 #include "object_factory.hpp"
25 #include "audio/sound_manager.hpp"
28 const std::string ROCK_SOUND = "sounds/brick.wav"; //TODO use own sound.
31 Rock::Rock(const lisp::Lisp& reader)
32 : MovingSprite(reader, "images/objects/rock/rock.sprite")
34 sound_manager->preload( ROCK_SOUND );
36 flags |= FLAG_SOLID | FLAG_PORTABLE;
40 Rock::write(lisp::Writer& writer)
42 writer.start_list("rock");
44 writer.write_float("x", bbox.p1.x);
45 writer.write_float("y", bbox.p1.y);
47 writer.end_list("rock");
51 Rock::update(float elapsed_time)
54 movement = physic.get_movement(elapsed_time);
59 Rock::collision_solid(const CollisionHit& hit)
61 physic.set_velocity(0, 0);
62 if( hit.bottom && !on_ground ){
63 sound_manager->play( ROCK_SOUND, get_pos() );
69 Rock::collision(GameObject& other, const CollisionHit& hit)
75 //Fake being solid for moving_object.
76 MovingObject* moving_object = dynamic_cast<MovingObject*> (&other);
79 float inside = moving_object->get_bbox().get_bottom() - get_bbox().get_top();
81 Vector pos = moving_object->get_pos();
83 moving_object->set_pos( pos );
86 CollisionHit hit_other = hit;
87 std::swap(hit_other.left, hit_other.right);
88 std::swap(hit_other.top, hit_other.bottom);
89 moving_object->collision_solid( hit_other );
95 Rock::grab(MovingObject& , const Vector& pos, Direction)
97 movement = pos - get_pos();
98 set_group( COLGROUP_DISABLED );
104 Rock::ungrab(MovingObject& , Direction ){
105 set_group( COLGROUP_MOVING );
107 physic.set_velocity(0, 0);
110 IMPLEMENT_FACTORY(Rock, "rock");