Had a bit of time today and worked on supertux:
[supertux.git] / src / object / oneup.cpp
1 #include <config.h>
2
3 #include "oneup.h"
4 #include "resources.h"
5 #include "player.h"
6 #include "player_status.h"
7 #include "sector.h"
8 #include "special/sprite_manager.h"
9 #include "video/drawing_context.h"
10
11 OneUp::OneUp(const Vector& pos)
12 {
13   bbox.set_pos(pos);
14   bbox.set_size(32, 32);
15   sprite = sprite_manager->create("1up");
16   physic.set_velocity(100, 400);
17 }
18
19 OneUp::~OneUp()
20 {
21   delete sprite;
22 }
23
24 void
25 OneUp::action(float elapsed_time)
26 {
27   if(!Sector::current()->inside(bbox))
28     remove_me();
29
30   movement = physic.get_movement(elapsed_time); 
31 }
32
33 void
34 OneUp::draw(DrawingContext& context)
35 {
36   sprite->draw(context, get_pos(), LAYER_OBJECTS);
37 }
38
39 HitResponse
40 OneUp::collision(GameObject& other, const CollisionHit& )
41 {
42   Player* player = dynamic_cast<Player*> (&other);
43   if(player) {
44     player->get_status().incLives();
45     remove_me();
46     return ABORT_MOVE;
47   }
48   return FORCE_MOVE;
49 }
50