--- /dev/null
+// $Id: growup.cpp 2458 2005-05-10 11:29:58Z matzebraun $
+//
+// SuperTux
+// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
+//
+// 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 <config.h>
+
+#include <math.h>
+#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<Player*>(&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");
+
--- /dev/null
+// $Id: growup.h 2458 2005-05-10 11:29:58Z matzebraun $
+//
+// SuperTux
+// Copyright (C) 2005 Matthias Braun <matze@braunis.de>
+//
+// 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
+