00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "audio/sound_manager.hpp"
00018 #include "badguy/walking_badguy.hpp"
00019 #include "control/controller.hpp"
00020 #include "object/player.hpp"
00021 #include "object/trampoline.hpp"
00022 #include "sprite/sprite.hpp"
00023 #include "sprite/sprite_manager.hpp"
00024 #include "supertux/object_factory.hpp"
00025 #include "util/reader.hpp"
00026
00027
00028
00029 namespace {
00030 const std::string TRAMPOLINE_SOUND = "sounds/trampoline.wav";
00031 const float VY_MIN = -900;
00032 const float VY_INITIAL = -500;
00033 }
00034
00035 Trampoline::Trampoline(const Reader& lisp) :
00036 Rock(lisp, "images/objects/trampoline/trampoline.sprite"),
00037 portable(true)
00038 {
00039 sound_manager->preload(TRAMPOLINE_SOUND);
00040
00041
00042 if(lisp.get("portable", portable)) {
00043 if(!portable) {
00044
00045 sprite_name = "images/objects/trampoline/trampoline_fix.sprite";
00046 sprite = sprite_manager->create(sprite_name);
00047 sprite->set_action("normal");
00048 }
00049 }
00050 }
00051
00052 void
00053 Trampoline::update(float elapsed_time)
00054 {
00055 if(sprite->animation_done()) {
00056 sprite->set_action("normal");
00057 }
00058
00059 Rock::update(elapsed_time);
00060 }
00061
00062 HitResponse
00063 Trampoline::collision(GameObject& other, const CollisionHit& hit)
00064 {
00065
00066
00067 if(on_ground) {
00068 Player* player = dynamic_cast<Player*> (&other);
00069
00070 if(player) {
00071 float vy = player->get_physic().get_velocity_y();
00072
00073 if(hit.top && vy >= 0) {
00074 if(player->get_controller()->hold(Controller::JUMP)) {
00075 vy = VY_MIN;
00076 } else {
00077 vy = VY_INITIAL;
00078 }
00079 player->get_physic().set_velocity_y(vy);
00080 sound_manager->play(TRAMPOLINE_SOUND);
00081 sprite->set_action("swinging", 1);
00082 return FORCE_MOVE;
00083 }
00084 }
00085 WalkingBadguy* walking_badguy = dynamic_cast<WalkingBadguy*> (&other);
00086
00087 if(walking_badguy) {
00088 float vy = walking_badguy->get_velocity_y();
00089
00090 if(hit.top && vy >= 0) {
00091 vy = VY_INITIAL;
00092 walking_badguy->set_velocity_y(vy);
00093 sound_manager->play(TRAMPOLINE_SOUND);
00094 sprite->set_action("swinging", 1);
00095 return FORCE_MOVE;
00096 }
00097 }
00098 }
00099
00100 return Rock::collision(other, hit);
00101 }
00102
00103 void
00104 Trampoline::collision_solid(const CollisionHit& hit) {
00105 Rock::collision_solid(hit);
00106 }
00107
00108 void
00109 Trampoline::grab(MovingObject& object, const Vector& pos, Direction dir) {
00110 sprite->set_animation_loops(0);
00111 Rock::grab(object, pos, dir);
00112 }
00113
00114 void
00115 Trampoline::ungrab(MovingObject& object, Direction dir) {
00116 Rock::ungrab(object, dir);
00117 }
00118
00119 bool
00120 Trampoline::is_portable() const
00121 {
00122 return Rock::is_portable() && portable;
00123 }
00124
00125