87e2c11a6548f8352892f537b6f3855f98a4fa64
[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, Direction direction)
34         : MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING)
35 {
36   physic.vx = ((direction == LEFT) ? -SPEED : SPEED);
37   physic.vy = INITIALJUMP;
38 }
39
40 void
41 Star::update(float elapsed_time)
42 {
43   movement = physic.get_movement(elapsed_time);
44 }
45
46 void
47 Star::collision_solid(const CollisionHit& hit)
48 {
49   if(hit.bottom) {
50     physic.vy = JUMPSPEED;
51   } else if(hit.top) {
52     physic.vy = 0;
53   } else if(hit.left || hit.right) {
54     physic.vx = -physic.vx;
55   }
56 }
57
58 HitResponse
59 Star::collision(GameObject& other, const CollisionHit& )
60 {
61   Player* player = dynamic_cast<Player*> (&other);
62   if(player) {
63     player->make_invincible();
64     remove_me();
65     return ABORT_MOVE;
66   }
67
68   return FORCE_MOVE;
69 }