2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
17 #include "audio/sound_manager.hpp"
18 #include "object/player.hpp"
19 #include "object/powerup.hpp"
20 #include "supertux/object_factory.hpp"
21 #include "supertux/sector.hpp"
22 #include "util/reader.hpp"
24 PowerUp::PowerUp(const Reader& lisp) :
25 MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING),
30 lisp.get("script", script);
32 lisp.get("disable-physics", no_physics);
33 physic.enable_gravity(true);
34 sound_manager->preload("sounds/grow.ogg");
35 sound_manager->preload("sounds/fire-flower.wav");
39 PowerUp::collision_solid(const CollisionHit& hit)
42 physic.set_velocity_y(0);
44 if(hit.right || hit.left) {
45 physic.set_velocity_x(-physic.get_velocity_x());
50 PowerUp::collision(GameObject& other, const CollisionHit&)
52 Player* player = dynamic_cast<Player*>(&other);
57 std::istringstream stream(script);
58 Sector::current()->run_script(stream, "powerup-script");
63 // some defaults if no script has been set
64 if (sprite_name == "images/powerups/egg/egg.sprite") {
65 if(!player->add_bonus(GROWUP_BONUS, true))
67 sound_manager->play("sounds/grow.ogg");
68 } else if (sprite_name == "images/powerups/fireflower/fireflower.sprite") {
69 if(!player->add_bonus(FIRE_BONUS, true))
71 sound_manager->play("sounds/fire-flower.wav");
72 } else if (sprite_name == "images/powerups/star/star.sprite") {
73 player->make_invincible();
74 } else if (sprite_name == "images/powerups/1up/1up.sprite") {
75 player->get_status()->add_coins(100);
83 PowerUp::update(float elapsed_time)
86 movement = physic.get_movement(elapsed_time);
89 IMPLEMENT_FACTORY(PowerUp, "powerup");