Had a bit of time today and worked on supertux:
[supertux.git] / src / object / star.cpp
1 #include <config.h>
2
3 #include "star.h"
4 #include "resources.h"
5 #include "player.h"
6 #include "player_status.h"
7 #include "special/sprite_manager.h"
8 #include "video/drawing_context.h"
9
10 static const float INITIALJUMP = 400;
11 static const float SPEED = 150;
12 static const float JUMPSPEED = 300;
13
14 Star::Star(const Vector& pos)
15 {
16   bbox.set_pos(pos);
17   bbox.set_size(32, 32);
18   sprite = sprite_manager->create("star");
19   physic.set_velocity(SPEED, INITIALJUMP);
20 }
21
22 Star::~Star()
23 {
24   delete sprite;
25 }
26
27 void
28 Star::action(float elapsed_time)
29 {
30   movement = physic.get_movement(elapsed_time);
31 }
32
33 void
34 Star::draw(DrawingContext& context)
35 {
36   sprite->draw(context, get_pos(), LAYER_OBJECTS);
37 }
38
39 HitResponse
40 Star::collision(GameObject& other, const CollisionHit& hit)
41 {
42   if(other.get_flags() & FLAG_SOLID) {
43     if(hit.normal.y < -.5) { // ground
44       physic.set_velocity_y(JUMPSPEED);
45     } else if(hit.normal.y > .5) { // roof
46       physic.set_velocity_y(0);
47     } else { // bumped left or right
48       physic.set_velocity_x(-physic.get_velocity_x());
49     }
50
51     return CONTINUE;
52   }
53   
54   Player* player = dynamic_cast<Player*> (&other);
55   if(player) {
56     player->make_invincible();
57     remove_me();
58     return ABORT_MOVE;
59   }
60
61   return FORCE_MOVE;
62 }
63