1 // SuperTux - Rusty Trampoline
2 // Copyright (C) 2006 Wolfgang Becker <uafr@gmx.de>
3 // Copyright (C) 2011 Jonas Kuemmerlin <rgcjonas@googlemail.com>
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #include "audio/sound_manager.hpp"
19 #include "badguy/walking_badguy.hpp"
20 #include "control/controller.hpp"
21 #include "object/player.hpp"
22 #include "object/rusty_trampoline.hpp"
23 #include "sprite/sprite.hpp"
24 #include "sprite/sprite_manager.hpp"
25 #include "supertux/object_factory.hpp"
26 #include "util/reader.hpp"
28 /* Trampoline will accelerate player to to VY_BOUNCE, if
29 * he jumps on it to VY_TRIGGER. */
31 const std::string BOUNCE_SOUND = "sounds/trampoline.wav";
32 const float VY_TRIGGER = -900; //negative, upwards
33 const float VY_BOUNCE = -500;
36 RustyTrampoline::RustyTrampoline(const Reader& lisp) :
37 Rock(lisp, "images/objects/rusty-trampoline/rusty-trampoline.sprite"),
38 portable(true), counter(3)
40 SoundManager::current()->preload(BOUNCE_SOUND);
42 lisp.get("counter", counter);
43 lisp.get("portable", portable); //do we really need this?
47 RustyTrampoline::update(float elapsed_time)
49 if(sprite->animation_done()) {
53 sprite->set_action("normal");
58 Rock::update(elapsed_time);
62 RustyTrampoline::collision(GameObject& other, const CollisionHit& hit)
65 //Trampoline has to be on ground to work.
67 Player* player = dynamic_cast<Player*> (&other);
68 //Trampoline works for player
70 float vy = player->get_physic().get_velocity_y();
71 //player is falling down on trampoline
72 if(hit.top && vy >= 0) {
73 if(player->get_controller()->hold(Controller::JUMP)) {
78 player->get_physic().set_velocity_y(vy);
79 SoundManager::current()->play(BOUNCE_SOUND);
82 sprite->set_action("swinging", 1);
84 sprite->set_action("breaking", 1);
90 WalkingBadguy* walking_badguy = dynamic_cast<WalkingBadguy*> (&other);
91 //Trampoline also works for WalkingBadguy
93 float vy = walking_badguy->get_velocity_y();
94 //walking_badguy is falling down on trampoline
95 if(hit.top && vy >= 0) {
97 walking_badguy->set_velocity_y(vy);
98 SoundManager::current()->play(BOUNCE_SOUND);
101 sprite->set_action("swinging", 1);
103 sprite->set_action("breaking", 1);
110 return Rock::collision(other, hit);
114 RustyTrampoline::collision_solid(const CollisionHit& hit) {
115 Rock::collision_solid(hit);
119 RustyTrampoline::grab(MovingObject& object, const Vector& pos, Direction dir) {
120 Rock::grab(object, pos, dir);
124 RustyTrampoline::ungrab(MovingObject& object, Direction dir) {
125 Rock::ungrab(object, dir);
126 sprite->set_action("breaking", 1);
127 counter = 0; //remove in update()
131 RustyTrampoline::is_portable() const
133 return Rock::is_portable() && portable;