Replaced <c*> headers with <*.h>
[supertux.git] / src / object / star.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #include "object/player.hpp"
18 #include "object/star.hpp"
19
20 static const float INITIALJUMP = -400;
21 static const float SPEED = 150;
22 static const float JUMPSPEED = -300;
23
24 Star::Star(const Vector& pos, Direction direction) :
25   MovingSprite(pos, "images/powerups/star/star.sprite", LAYER_OBJECTS, COLGROUP_MOVING),
26   physic()
27 {
28   physic.set_velocity((direction == LEFT) ? -SPEED : SPEED, INITIALJUMP);
29 }
30
31 void
32 Star::update(float elapsed_time)
33 {
34   movement = physic.get_movement(elapsed_time);
35 }
36
37 void
38 Star::collision_solid(const CollisionHit& hit)
39 {
40   if(hit.bottom) {
41     physic.set_velocity_y(JUMPSPEED);
42   } else if(hit.top) {
43     physic.set_velocity_y(0);
44   } else if(hit.left || hit.right) {
45     physic.set_velocity_x(-physic.get_velocity_x());
46   }
47 }
48
49 HitResponse
50 Star::collision(GameObject& other, const CollisionHit& )
51 {
52   Player* player = dynamic_cast<Player*> (&other);
53   if(player) {
54     player->make_invincible();
55     remove_me();
56     return ABORT_MOVE;
57   }
58
59   return FORCE_MOVE;
60 }
61
62 /* EOF */