changed worldmap format a bit to be more consistent with level format
[supertux.git] / src / object / platform.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
21 #include <config.h>
22
23 #include "platform.h"
24 #include "video/drawing_context.h"
25 #include "resources.h"
26 #include "player.h"
27 #include "sprite/sprite_manager.h"
28 #include "lisp/lisp.h"
29 #include "lisp/writer.h"
30 #include "object_factory.h"
31
32 Platform::Platform(const lisp::Lisp& reader)
33 {
34   sprite = sprite_manager->create("flying_platform");
35   movement = Vector(0, 1);
36   reader.get("x", bbox.p1.x);
37   reader.get("y", bbox.p1.y);
38   bbox.set_size(sprite->get_width(), sprite->get_height());
39
40   flags |= FLAG_SOLID;
41
42   state = 0;
43 }
44
45 Platform::~Platform()
46 {
47   delete sprite;
48 }
49
50 HitResponse
51 Platform::collision(GameObject& , const CollisionHit& )
52 {
53 #if 0
54   if(typeid(object) == typeid(Player)) {
55     Player* player = (Player*) &object;
56     //player->movement += movement;
57   }
58 #endif
59   return FORCE_MOVE;
60 }
61
62 void
63 Platform::update(float )
64 {
65   // just some test code...
66   if(state == 0) {
67     movement = Vector(0, 1);
68     if(bbox.p1.y > 250)
69       state = 1;
70   }
71   if(state == 1) {
72     movement = Vector(0, -1);
73     if(bbox.p1.y < 50)
74       state = 2;
75   }
76   if(state == 2) {
77     movement = Vector(1, 0);
78     if(bbox.p1.x > 800)
79       state = 3;
80   }
81   if(state == 3) {
82     movement = Vector(-1, 0);
83     if(bbox.p1.x < 400)
84       state = 4;
85   }
86   if(state == 4) {
87     movement = Vector(-1, 1);
88     if(bbox.p1.x < 0)
89       state = 0;
90   }
91 }
92
93 void
94 Platform::draw(DrawingContext& context)
95 {
96   sprite->draw(context, get_pos(), LAYER_OBJECTS);
97 }
98
99 IMPLEMENT_FACTORY(Platform, "flying_platform");