-Worldmap cleanups (use DrawingContext transformstack)
[supertux.git] / src / object / growup.cpp
1 #include <config.h>
2
3 #include <math.h>
4 #include "growup.h"
5 #include "resources.h"
6 #include "camera.h"
7 #include "sector.h"
8 #include "player.h"
9 #include "app/globals.h"
10 #include "special/sprite_manager.h"
11
12 GrowUp::GrowUp(const Vector& pos)
13 {
14   bbox.set_pos(pos);
15   bbox.set_size(32, 32);
16   
17   sprite = sprite_manager->create("egg");
18   physic.enable_gravity(true);
19   physic.set_velocity_x(100);
20 }
21
22 GrowUp::~GrowUp()
23 {
24   delete sprite;
25 }
26
27 void
28 GrowUp::action(float elapsed_time)
29 {
30   movement = physic.get_movement(elapsed_time);
31 }
32
33 HitResponse
34 GrowUp::collision(GameObject& other, const CollisionHit& hit)
35 {
36   if(other.get_flags() & FLAG_SOLID) {
37     if(fabsf(hit.normal.y) > .5) { // roof or ground
38       physic.set_velocity_y(0);
39     } else { // bumped left or right
40       physic.set_velocity_x(-physic.get_velocity_x());
41     }
42
43     return CONTINUE;
44   }
45   
46   Player* player = dynamic_cast<Player*>(&other);
47   if(player != 0) {
48     player->set_bonus(GROWUP_BONUS, true);
49     SoundManager::get()->play_sound(IDToSound(SND_EXCELLENT));
50     remove_me();
51     
52     return ABORT_MOVE;
53   }
54
55   return FORCE_MOVE;
56 }
57
58 void
59 GrowUp::draw(DrawingContext& context)
60 {
61   sprite->draw(context, get_pos(), LAYER_OBJECTS);
62 }
63