00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "audio/sound_manager.hpp"
00018 #include "object/player.hpp"
00019 #include "object/powerup.hpp"
00020 #include "supertux/object_factory.hpp"
00021 #include "supertux/sector.hpp"
00022 #include "util/reader.hpp"
00023
00024 #include <sstream>
00025
00026 PowerUp::PowerUp(const Reader& lisp) :
00027 MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING),
00028 physic(),
00029 script(),
00030 no_physics()
00031 {
00032 lisp.get("script", script);
00033 no_physics = false;
00034 lisp.get("disable-physics", no_physics);
00035 physic.enable_gravity(true);
00036 sound_manager->preload("sounds/grow.ogg");
00037 sound_manager->preload("sounds/fire-flower.wav");
00038 }
00039
00040 void
00041 PowerUp::collision_solid(const CollisionHit& hit)
00042 {
00043 if(hit.bottom) {
00044 physic.set_velocity_y(0);
00045 }
00046 if(hit.right || hit.left) {
00047 physic.set_velocity_x(-physic.get_velocity_x());
00048 }
00049 }
00050
00051 HitResponse
00052 PowerUp::collision(GameObject& other, const CollisionHit&)
00053 {
00054 Player* player = dynamic_cast<Player*>(&other);
00055 if(player == 0)
00056 return FORCE_MOVE;
00057
00058 if (script != "") {
00059 std::istringstream stream(script);
00060 Sector::current()->run_script(stream, "powerup-script");
00061 remove_me();
00062 return ABORT_MOVE;
00063 }
00064
00065
00066 if (sprite_name == "images/powerups/egg/egg.sprite") {
00067 if(!player->add_bonus(GROWUP_BONUS, true))
00068 return FORCE_MOVE;
00069 sound_manager->play("sounds/grow.ogg");
00070 } else if (sprite_name == "images/powerups/fireflower/fireflower.sprite") {
00071 if(!player->add_bonus(FIRE_BONUS, true))
00072 return FORCE_MOVE;
00073 sound_manager->play("sounds/fire-flower.wav");
00074 } else if (sprite_name == "images/powerups/star/star.sprite") {
00075 player->make_invincible();
00076 } else if (sprite_name == "images/powerups/1up/1up.sprite") {
00077 player->get_status()->add_coins(100);
00078 }
00079
00080 remove_me();
00081 return ABORT_MOVE;
00082 }
00083
00084 void
00085 PowerUp::update(float elapsed_time)
00086 {
00087 if (!no_physics)
00088 movement = physic.get_movement(elapsed_time);
00089 }
00090
00091