-Started to move stuff from library back to main game
[supertux.git] / src / object / growup.cpp
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 // 
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #include <config.h>
22
23 #include <math.h>
24 #include "growup.h"
25 #include "resources.h"
26 #include "camera.h"
27 #include "sector.h"
28 #include "player.h"
29 #include "app/globals.h"
30 #include "sprite/sprite_manager.h"
31
32 GrowUp::GrowUp(const Vector& pos)
33 {
34   bbox.set_pos(pos);
35   bbox.set_size(32, 32);
36   
37   sprite = sprite_manager->create("egg");
38   physic.enable_gravity(true);
39   physic.set_velocity_x(100);
40 }
41
42 GrowUp::~GrowUp()
43 {
44   delete sprite;
45 }
46
47 void
48 GrowUp::action(float elapsed_time)
49 {
50   movement = physic.get_movement(elapsed_time);
51 }
52
53 HitResponse
54 GrowUp::collision(GameObject& other, const CollisionHit& hit)
55 {
56   if(other.get_flags() & FLAG_SOLID) {
57     if(fabsf(hit.normal.y) > .5) { // roof or ground
58       physic.set_velocity_y(0);
59     } else { // bumped left or right
60       physic.set_velocity_x(-physic.get_velocity_x());
61     }
62
63     return CONTINUE;
64   }
65   
66   Player* player = dynamic_cast<Player*>(&other);
67   if(player != 0) {
68     player->set_bonus(GROWUP_BONUS, true);
69     sound_manager->play_sound("grow");
70     remove_me();
71     
72     return ABORT_MOVE;
73   }
74
75   return FORCE_MOVE;
76 }
77
78 void
79 GrowUp::draw(DrawingContext& context)
80 {
81   sprite->draw(context, get_pos(), LAYER_OBJECTS);
82 }
83