X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fobject%2Fpowerup.cpp;h=09a747063e4d402318e99ee2bd80e0e893447b09;hb=ed161bf9da56b598f3db3637c6017fa22e9ab0d7;hp=dd6267bdf406dfc37e846c0369998878276a5b3b;hpb=001cb827d5d08d5f2a47cdd19a72070e314a028a;p=supertux.git diff --git a/src/object/powerup.cpp b/src/object/powerup.cpp index dd6267bdf..09a747063 100644 --- a/src/object/powerup.cpp +++ b/src/object/powerup.cpp @@ -1,7 +1,7 @@ -// $Id: growup.cpp 2458 2005-05-10 11:29:58Z matzebraun $ -// +// $Id$ +// // SuperTux -// Copyright (C) 2005 Matthias Braun +// Copyright (C) 2006 Matthias Braun // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License @@ -12,84 +12,84 @@ // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. -// +// // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA -// 02111-1307, USA. +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + #include +#include #include -#include "powerup.h" -#include "resources.h" -#include "player.h" -#include "sprite/sprite_manager.h" -#include "object_factory.h" -#include "sector.h" +#include +#include "powerup.hpp" +#include "resources.hpp" +#include "player.hpp" +#include "audio/sound_manager.hpp" +#include "object_factory.hpp" +#include "sector.hpp" +#include "log.hpp" PowerUp::PowerUp(const lisp::Lisp& lisp) + : MovingSprite(lisp, LAYER_OBJECTS, COLGROUP_MOVING) { - lisp.get("x", bbox.p1.x); - lisp.get("y", bbox.p1.y); - lisp.get("type", type); - bbox.set_size(32, 32); - sprite = sprite_manager->create(type); + lisp.get("script", script); + no_physics = false; + lisp.get("disable-physics", no_physics); physic.enable_gravity(true); + sound_manager->preload("sounds/grow.wav"); + sound_manager->preload("sounds/fire-flower.wav"); } -PowerUp::~PowerUp() +void +PowerUp::collision_solid(const CollisionHit& hit) { - delete sprite; + if(hit.bottom) { + physic.set_velocity_y(0); + } + if(hit.right || hit.left) { + physic.set_velocity_x(-physic.get_velocity_x()); + } } HitResponse -PowerUp::collision(GameObject& other, const CollisionHit& hit) +PowerUp::collision(GameObject& other, const CollisionHit&) { - if(other.get_flags() & FLAG_SOLID) { - if(fabsf(hit.normal.y) > .5) { // roof or ground - physic.set_velocity_y(0); - } else { // bumped left or right - physic.set_velocity_x(-physic.get_velocity_x()); - } - - return CONTINUE; - } - Player* player = dynamic_cast(&other); - if(player != 0) { - if (type == "egg") { - player->set_bonus(GROWUP_BONUS, true); - sound_manager->play_sound("grow"); - } - else if (type == "fireflower") { - player->set_bonus(FIRE_BONUS, true); - sound_manager->play_sound("fire-flower"); - } - else if (type == "star") { - player->make_invincible(); - } - else if (type == "1up") { - player->get_status()->incLives(); - } + if(player == 0) + return FORCE_MOVE; + + if (script != "") { + std::istringstream stream(script); + Sector::current()->run_script(stream, "powerup-script"); remove_me(); - return ABORT_MOVE; } - return FORCE_MOVE; -} + // some defaults if no script has been set + if (sprite_name == "images/powerups/egg/egg.sprite") { + if(!player->add_bonus(GROWUP_BONUS, true)) + return FORCE_MOVE; + sound_manager->play("sounds/grow.wav"); + } else if (sprite_name == "images/powerups/fireflower/fireflower.sprite") { + if(!player->add_bonus(FIRE_BONUS, true)) + return FORCE_MOVE; + sound_manager->play("sounds/fire-flower.wav"); + } else if (sprite_name == "images/powerups/star/star.sprite") { + player->make_invincible(); + } else if (sprite_name == "images/powerups/1up/1up.sprite") { + player->get_status()->add_coins(100); + } -void -PowerUp::update(float elapsed_time) -{ - movement = physic.get_movement(elapsed_time); + remove_me(); + return ABORT_MOVE; } void -PowerUp::draw(DrawingContext& context) +PowerUp::update(float elapsed_time) { - sprite->draw(context, get_pos(), LAYER_OBJECTS); + if (!no_physics) + movement = physic.get_movement(elapsed_time); } IMPLEMENT_FACTORY(PowerUp, "powerup"); -