#include "badguy/mrrocket.hpp"
#include "badguy/poisonivy.hpp"
#include "badguy/snowsnail.hpp"
+#include "badguy/skullyhop.hpp"
Dispenser::Dispenser(const lisp::Lisp& reader)
{
Sector::current()->add_object(new MrRocket(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y, dir));}
else if (badguy == "poisonivy")
Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir));
+ else if (badguy == "skullyhop")
+ Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir));
else if (badguy == "random")
{
- switch (rand()%6)
+ switch (rand()%7)
{
case 0: Sector::current()->add_object(new SnowBall(get_pos().x, get_pos().y+32, dir)); break;
case 1: Sector::current()->add_object(new BouncingSnowball(get_pos().x, get_pos().y+32, dir)); break;
case 3: Sector::current()->add_object(new MrIceBlock(get_pos().x, get_pos().y+32, dir, false)); break;
case 4: Sector::current()->add_object(new PoisonIvy(get_pos().x, get_pos().y+32, dir)); break;
case 5: Sector::current()->add_object(new SnowSnail(get_pos().x, get_pos().y+32, dir)); break;
+ case 6: Sector::current()->add_object(new SkullyHop(get_pos().x, get_pos().y+44, dir)); break;
}
}
}
--- /dev/null
+// $Id: skullyhop.cpp 2960 2005-12-28 00:09:51Z matzebraun $
+//
+// SkullyHop - A Hopping Skull
+// Copyright (C) 2006 Christoph Sommer <supertux@2006.expires.deltadevelopment.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 "skullyhop.hpp"
+
+namespace {
+ const float VERTICAL_SPEED = 450; /**< y-speed when jumping */
+ const float HORIZONTAL_SPEED = 220; /**< x-speed when jumping */
+ const float MIN_RECOVER_TIME = 0.1; /**< minimum time to stand still before starting a (new) jump */
+ const float MAX_RECOVER_TIME = 1.0; /**< maximum time to stand still before starting a (new) jump */
+}
+
+SkullyHop::SkullyHop(const lisp::Lisp& reader)
+{
+ reader.get("x", start_position.x);
+ reader.get("y", start_position.y);
+ bbox.set_size(33.8, 43.8); //sprite is 34x44
+ sprite = sprite_manager->create("skullyhop");
+ has_initial_direction = false;
+}
+
+SkullyHop::SkullyHop(float pos_x, float pos_y, Direction d)
+{
+ start_position.x = pos_x;
+ start_position.y = pos_y;
+ bbox.set_size(33.8, 43.8); //sprite is 34x44
+ sprite = sprite_manager->create("skullyhop");
+ has_initial_direction = true;
+ initial_direction = d;
+}
+
+void
+SkullyHop::write(lisp::Writer& writer)
+{
+ writer.start_list("skullyhop");
+ writer.write_float("x", start_position.x);
+ writer.write_float("y", start_position.y);
+ writer.end_list("skullyhop");
+}
+
+void
+SkullyHop::activate()
+{
+ if (has_initial_direction) dir = initial_direction;
+
+ // initial state is JUMPING, because we might start airborne
+ state = JUMPING;
+ sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
+}
+
+void
+SkullyHop::set_state(SkullyHopState newState)
+{
+ if (newState == STANDING) {
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
+ sprite->set_action(dir == LEFT ? "standing-left" : "standing-right");
+
+ float recover_time = MIN_RECOVER_TIME + (float)rand() / RAND_MAX * (MAX_RECOVER_TIME - MIN_RECOVER_TIME);
+ recover_timer.start(recover_time);
+ } else
+ if (newState == CHARGING) {
+ sprite->set_action(dir == LEFT ? "charging-left" : "charging-right", 1);
+ } else
+ if (newState == JUMPING) {
+ sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
+ physic.set_velocity_x(dir == LEFT ? -HORIZONTAL_SPEED : HORIZONTAL_SPEED);
+ physic.set_velocity_y(VERTICAL_SPEED);
+ }
+
+ state = newState;
+}
+
+bool
+SkullyHop::collision_squished(Player& player)
+{
+ sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
+ kill_squished(player);
+ return true;
+}
+
+HitResponse
+SkullyHop::collision_solid(GameObject& , const CollisionHit& hit)
+{
+ // ignore collisions while standing still
+ if(state != JUMPING) return CONTINUE;
+
+ // check if we hit the floor while falling
+ if ((hit.normal.y < 0) && (physic.get_velocity_y() < 0)) {
+ set_state(STANDING);
+ }
+
+ // check if we hit the roof while climbing
+ if ((hit.normal.y > 0) && (physic.get_velocity_y() > 0)) {
+ physic.set_velocity_y(0);
+ }
+
+ // check if we hit left or right while moving in either direction
+ if ((hit.normal.x != 0) && (physic.get_velocity_x() != 0)) {
+ dir = dir == LEFT ? RIGHT : LEFT;
+ sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
+ physic.set_velocity_x(-0.25*physic.get_velocity_x());
+ }
+
+ return CONTINUE;
+}
+
+HitResponse
+SkullyHop::collision_badguy(BadGuy& badguy, const CollisionHit& hit)
+{
+ // behaviour for badguy collisions is the same as for collisions with solids
+ return collision_solid(badguy, hit);
+}
+
+void
+SkullyHop::active_update(float elapsed_time)
+{
+ BadGuy::active_update(elapsed_time);
+
+ // charge when fully recovered
+ if ((state == STANDING) && (recover_timer.check())) {
+ set_state(CHARGING);
+ return;
+ }
+
+ // jump as soon as charging animation completed
+ if ((state == CHARGING) && (sprite->animation_done())) {
+ set_state(JUMPING);
+ return;
+ }
+}
+
+IMPLEMENT_FACTORY(SkullyHop, "skullyhop")
--- /dev/null
+// $Id: skullyhop.hpp 2642 2005-06-26 13:38:53Z matzebraun $
+//
+// SkullyHop - A Hopping Skull
+// Copyright (C) 2006 Christoph Sommer <supertux@2006.expires.deltadevelopment.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 __SKULLYHOP_H__
+#define __SKULLYHOP_H__
+
+#include "badguy.hpp"
+
+/**
+ * Badguy "SkullyHop" - A Hopping Skull
+ */
+class SkullyHop : public BadGuy
+{
+public:
+ SkullyHop(const lisp::Lisp& reader);
+ SkullyHop(float pos_x, float pos_y, Direction d);
+
+ void activate();
+ void write(lisp::Writer& writer);
+ HitResponse collision_solid(GameObject& other, const CollisionHit& hit);
+ HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+ bool collision_squished(Player& player);
+ void active_update(float elapsed_time);
+
+protected:
+ enum SkullyHopState {
+ STANDING,
+ CHARGING,
+ JUMPING
+ };
+
+ bool has_initial_direction;
+ Direction initial_direction;
+
+ Timer recover_timer;
+ SkullyHopState state;
+
+ void set_state(SkullyHopState newState);
+};
+
+#endif
+