617704c545b61ae737df2b9e586103efba6a4198
[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.set_velocity((direction == LEFT) ? -SPEED : SPEED, INITIALJUMP);
37 }
38
39 void
40 Star::update(float elapsed_time)
41 {
42   movement = physic.get_movement(elapsed_time);
43 }
44
45 void
46 Star::collision_solid(const CollisionHit& hit)
47 {
48   if(hit.bottom) {
49     physic.set_velocity_y(JUMPSPEED);
50   } else if(hit.top) {
51     physic.set_velocity_y(0);
52   } else if(hit.left || hit.right) {
53     physic.set_velocity_x(-physic.get_velocity_x());
54   }
55 }
56
57 HitResponse
58 Star::collision(GameObject& other, const CollisionHit& )
59 {
60   Player* player = dynamic_cast<Player*> (&other);
61   if(player) {
62     player->make_invincible();
63     remove_me();
64     return ABORT_MOVE;
65   }
66
67   return FORCE_MOVE;
68 }
69