implemented a new object factory mechanism which is now really independent of the...
[supertux.git] / src / object / platform.cpp
1 #include <config.h>
2
3 #include "platform.h"
4 #include "video/drawing_context.h"
5 #include "resources.h"
6 #include "player.h"
7 #include "special/sprite_manager.h"
8 #include "lisp/lisp.h"
9 #include "lisp/writer.h"
10 #include "object_factory.h"
11
12 Platform::Platform(const lisp::Lisp& reader)
13 {
14   sprite = sprite_manager->create("flying_platform");
15   movement = Vector(0, 1);
16   reader.get("x", bbox.p1.x);
17   reader.get("y", bbox.p1.y);
18   bbox.set_size(sprite->get_width(), sprite->get_height());
19
20   flags |= FLAG_SOLID;
21
22   state = 0;
23 }
24
25 Platform::~Platform()
26 {
27   delete sprite;
28 }
29
30 HitResponse
31 Platform::collision(GameObject& , const CollisionHit& )
32 {
33 #if 0
34   if(typeid(object) == typeid(Player)) {
35     Player* player = (Player*) &object;
36     //player->movement += movement;
37   }
38 #endif
39   return FORCE_MOVE;
40 }
41
42 void
43 Platform::action(float )
44 {
45   // just some test code...
46   if(state == 0) {
47     movement = Vector(0, 1);
48     if(bbox.p1.y > 250)
49       state = 1;
50   }
51   if(state == 1) {
52     movement = Vector(0, -1);
53     if(bbox.p1.y < 50)
54       state = 2;
55   }
56   if(state == 2) {
57     movement = Vector(1, 0);
58     if(bbox.p1.x > 800)
59       state = 3;
60   }
61   if(state == 3) {
62     movement = Vector(-1, 0);
63     if(bbox.p1.x < 400)
64       state = 4;
65   }
66   if(state == 4) {
67     movement = Vector(-1, 1);
68     if(bbox.p1.x < 0)
69       state = 0;
70   }
71 }
72
73 void
74 Platform::draw(DrawingContext& context)
75 {
76   sprite->draw(context, get_pos(), LAYER_OBJECTS);
77 }
78
79 IMPLEMENT_FACTORY(Platform, "flying_platform");