d72b7ac331052386f3c6395bb43f15bd079bb42b
[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 "utils/lispreader.h"
9
10 Platform::Platform(LispReader& reader)
11 {
12   sprite = sprite_manager->create("flying_platform");
13   movement = Vector(0, 1);
14   reader.read_float("x", bbox.p1.x);
15   reader.read_float("y", bbox.p1.y);
16   bbox.set_size(sprite->get_width(), sprite->get_height());
17
18   flags |= FLAG_SOLID;
19
20   state = 0;
21 }
22
23 Platform::~Platform()
24 {
25   delete sprite;
26 }
27
28 HitResponse
29 Platform::collision(GameObject& , const CollisionHit& )
30 {
31 #if 0
32   if(typeid(object) == typeid(Player)) {
33     Player* player = (Player*) &object;
34     //player->movement += movement;
35   }
36 #endif
37   return FORCE_MOVE;
38 }
39
40 void
41 Platform::action(float )
42 {
43   // just some test code...
44   if(state == 0) {
45     movement = Vector(0, 1);
46     if(bbox.p1.y > 250)
47       state = 1;
48   }
49   if(state == 1) {
50     movement = Vector(0, -1);
51     if(bbox.p1.y < 50)
52       state = 2;
53   }
54   if(state == 2) {
55     movement = Vector(1, 0);
56     if(bbox.p1.x > 800)
57       state = 3;
58   }
59   if(state == 3) {
60     movement = Vector(-1, 0);
61     if(bbox.p1.x < 400)
62       state = 4;
63   }
64   if(state == 4) {
65     movement = Vector(-1, 1);
66     if(bbox.p1.x < 0)
67       state = 0;
68   }
69 }
70
71 void
72 Platform::draw(DrawingContext& context)
73 {
74   sprite->draw(context, get_pos(), LAYER_OBJECTS);
75 }