From 001cb827d5d08d5f2a47cdd19a72070e314a028a Mon Sep 17 00:00:00 2001 From: Marek Moeckel Date: Tue, 17 May 2005 17:35:13 +0000 Subject: [PATCH] added a powerup object that can be placed in levels and represent various powerups (without the need for a bonus block) powerups are set according to hirarchy now (i.e. EGGbonus == type) + if(player_status->bonus >= type) return; if(player_status->bonus == NO_BONUS) { diff --git a/src/object/powerup.cpp b/src/object/powerup.cpp new file mode 100644 index 000000000..dd6267bdf --- /dev/null +++ b/src/object/powerup.cpp @@ -0,0 +1,95 @@ +// $Id: growup.cpp 2458 2005-05-10 11:29:58Z matzebraun $ +// +// SuperTux +// Copyright (C) 2005 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// 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. +#include + +#include +#include "powerup.h" +#include "resources.h" +#include "player.h" +#include "sprite/sprite_manager.h" +#include "object_factory.h" +#include "sector.h" + +PowerUp::PowerUp(const lisp::Lisp& lisp) +{ + 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); + physic.enable_gravity(true); +} + +PowerUp::~PowerUp() +{ + delete sprite; +} + +HitResponse +PowerUp::collision(GameObject& other, const CollisionHit& hit) +{ + 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(); + } + remove_me(); + + return ABORT_MOVE; + } + + return FORCE_MOVE; +} + +void +PowerUp::update(float elapsed_time) +{ + movement = physic.get_movement(elapsed_time); +} + +void +PowerUp::draw(DrawingContext& context) +{ + sprite->draw(context, get_pos(), LAYER_OBJECTS); +} + +IMPLEMENT_FACTORY(PowerUp, "powerup"); + diff --git a/src/object/powerup.h b/src/object/powerup.h new file mode 100644 index 000000000..a14d3742d --- /dev/null +++ b/src/object/powerup.h @@ -0,0 +1,46 @@ +// $Id: growup.h 2458 2005-05-10 11:29:58Z matzebraun $ +// +// SuperTux +// Copyright (C) 2005 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// 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. +#ifndef __POWERUP_H__ +#define __POWERUP_H__ + +#include "moving_object.h" +#include "lisp/lisp.h" +#include "sprite/sprite.h" +#include "collision_hit.h" +#include "physic.h" + +class PowerUp : public MovingObject +{ +public: + PowerUp(const lisp::Lisp& lisp); + ~PowerUp(); + + virtual void update(float elapsed_time); + virtual void draw(DrawingContext& context); + virtual HitResponse collision(GameObject& other, const CollisionHit& hit); + +private: + Sprite* sprite; + Physic physic; + std::string type; +}; + +#endif + -- 2.11.0