Massive copyright update. I'm sorry if I'm crediting Matze for something he didn...
[supertux.git] / src / object / star.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 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  02111-1307, USA.
19
20 #include <config.h>
21
22 #include "star.hpp"
23 #include "resources.hpp"
24 #include "player.hpp"
25 #include "player_status.hpp"
26 #include "sprite/sprite_manager.hpp"
27 #include "video/drawing_context.hpp"
28
29 static const float INITIALJUMP = 400;
30 static const float SPEED = 150;
31 static const float JUMPSPEED = 300;
32
33 Star::Star(const Vector& pos)
34 {
35   bbox.set_pos(pos);
36   bbox.set_size(32, 32);
37   sprite = sprite_manager->create("images/powerups/star/star.sprite");
38   physic.set_velocity(SPEED, INITIALJUMP);
39
40   set_group(COLGROUP_MOVING);
41 }
42
43 Star::~Star()
44 {
45   delete sprite;
46 }
47
48 void
49 Star::update(float elapsed_time)
50 {
51   movement = physic.get_movement(elapsed_time);
52 }
53
54 void
55 Star::draw(DrawingContext& context)
56 {
57   sprite->draw(context, get_pos(), LAYER_OBJECTS);
58 }
59
60 HitResponse
61 Star::collision(GameObject& other, const CollisionHit& hit)
62 {
63   if(other.get_flags() & FLAG_SOLID) {
64     if(hit.normal.y < -.5) { // ground
65       physic.set_velocity_y(JUMPSPEED);
66     } else if(hit.normal.y > .5) { // roof
67       physic.set_velocity_y(0);
68     } else { // bumped left or right
69       physic.set_velocity_x(-physic.get_velocity_x());
70     }
71
72     return CONTINUE;
73   }
74   
75   Player* player = dynamic_cast<Player*> (&other);
76   if(player) {
77     player->make_invincible();
78     remove_me();
79     return ABORT_MOVE;
80   }
81
82   return FORCE_MOVE;
83 }
84