fix iconv signature problems
[supertux.git] / src / object / rock.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 Matthias Braun <matze@braunis.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 #include <config.h>
21
22 #include "rock.h"
23 #include "sprite/sprite.h"
24 #include "sprite/sprite_manager.h"
25 #include "lisp/writer.h"
26 #include "video/drawing_context.h"
27 #include "resources.h"
28 #include "object_factory.h"
29
30 Rock::Rock(const lisp::Lisp& reader)
31 {
32   reader.get("x", bbox.p1.x);
33   reader.get("y", bbox.p1.y);
34   bbox.set_size(31.8, 31.8);
35   sprite = sprite_manager->create("rock");
36   grabbed = false;
37   flags |= FLAG_SOLID;
38 }
39
40 Rock::~Rock()
41 {
42   delete sprite;
43 }
44
45 void
46 Rock::write(lisp::Writer& writer)
47 {
48   writer.start_list("rock");
49
50   writer.write_float("x", bbox.p1.x);
51   writer.write_float("y", bbox.p1.y);
52
53   writer.end_list("rock");
54 }
55
56 void
57 Rock::draw(DrawingContext& context)
58 {
59
60   sprite->draw(context, get_pos(), LAYER_OBJECTS);
61 }
62
63 void
64 Rock::update(float elapsed_time)
65 {
66   if(!grabbed) {
67     flags |= FLAG_SOLID;
68     flags &= ~FLAG_NO_COLLDET;
69     movement = physic.get_movement(elapsed_time);
70   } else {
71     physic.set_velocity(0, 0);
72     flags &= ~FLAG_SOLID;
73     flags |= FLAG_NO_COLLDET;
74   }
75   
76   grabbed = false;
77 }
78
79 HitResponse
80 Rock::collision(GameObject& object, const CollisionHit& )
81 {
82   if(grabbed)
83     return FORCE_MOVE;
84
85   if(object.get_flags() & FLAG_SOLID) {
86       physic.set_velocity(0, 0);
87       return CONTINUE;
88   }
89
90   return FORCE_MOVE;
91 }
92
93 void
94 Rock::grab(MovingObject& , const Vector& pos)
95 {
96   movement = pos - get_pos();
97   grabbed = true;
98 }
99
100 IMPLEMENT_FACTORY(Rock, "rock");
101