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"
26 PowerUp::PowerUp(const Reader& lisp) :
27 MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING),
32 lisp.get("script", script);
34 lisp.get("disable-physics", no_physics);
35 physic.enable_gravity(true);
36 sound_manager->preload("sounds/grow.ogg");
37 sound_manager->preload("sounds/fire-flower.wav");
41 PowerUp::collision_solid(const CollisionHit& hit)
44 physic.set_velocity_y(0);
46 if(hit.right || hit.left) {
47 physic.set_velocity_x(-physic.get_velocity_x());
52 PowerUp::collision(GameObject& other, const CollisionHit&)
54 Player* player = dynamic_cast<Player*>(&other);
59 std::istringstream stream(script);
60 Sector::current()->run_script(stream, "powerup-script");
65 // some defaults if no script has been set
66 if (sprite_name == "images/powerups/egg/egg.sprite") {
67 if(!player->add_bonus(GROWUP_BONUS, true))
69 sound_manager->play("sounds/grow.ogg");
70 } else if (sprite_name == "images/powerups/fireflower/fireflower.sprite") {
71 if(!player->add_bonus(FIRE_BONUS, true))
73 sound_manager->play("sounds/fire-flower.wav");
74 } else if (sprite_name == "images/powerups/star/star.sprite") {
75 player->make_invincible();
76 } else if (sprite_name == "images/powerups/1up/1up.sprite") {
77 player->get_status()->add_coins(100);
85 PowerUp::update(float elapsed_time)
88 movement = physic.get_movement(elapsed_time);