Images are selfmade (The Gimp) and to be considered released under either the "GPL" and "CC by-nc-sa" license.
Feel free to improve them.
SVN-Revision: 4212
--- /dev/null
+(supertux-sprite
+ (action
+ (name "idle")
+ (hitbox 19 0 26 39)
+ (images
+ "mole-0.png"
+ )
+ )
+ (action
+ (name "peeking")
+ (hitbox 19 0 26 39)
+ (fps 10)
+ (images
+ "mole-1.png"
+ "mole-2.png"
+ "mole-3.png"
+ "mole-4.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-5.png"
+ "mole-4.png"
+ "mole-3.png"
+ "mole-2.png"
+ "mole-1.png"
+ )
+ )
+)
--- /dev/null
+(supertux-sprite
+ (action
+ (name "default")
+ (hitbox 1 1 10 10)
+ (images
+ "mole-rock.png"
+ )
+ )
+)
--- /dev/null
+(supertux-sprite
+ (action
+ (name "idle-left")
+ (hitbox 1 1 40 24)
+ (fps 5.0)
+ (images
+ "toad-idle-0.png"
+ "toad-idle-1.png"
+ )
+ )
+ (action
+ (name "idle-right")
+ (hitbox 1 1 40 24)
+ (mirror-action "idle-left")
+ )
+ (action
+ (name "jumping-left")
+ (hitbox 1 1 40 24)
+ (images
+ "toad-jumping.png"
+ )
+ )
+ (action
+ (name "jumping-right")
+ (fps 10.0)
+ (hitbox 1 1 40 24)
+ (mirror-action "jumping-left")
+ )
+ (action
+ (name "squished-left")
+ (hitbox 1 1 40 24)
+ (images "toad-squished.png")
+ )
+ (action
+ (name "squished-right")
+ (hitbox 1 1 40 24)
+ (mirror-action "squished-left")
+ )
+)
--- /dev/null
+// $Id$
+//
+// SuperTux - Mole Badguy
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@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 "mole.hpp"
+#include "mole_rock.hpp"
+#include "tile.hpp"
+#include "object/tilemap.hpp"
+#include "random_generator.hpp"
+#include "log.hpp"
+#include "level.hpp"
+
+static const float IDLE_TIME = 0.2; /**< time to wait before and after throwing */
+static const float THROW_TIME = 4.6; /**< time to spend throwing */
+static const float THROW_INTERVAL = 1; /**< time between two thrown rocks */
+static const float THROW_VELOCITY = 400; /**< initial velocity of thrown rocks */
+
+Mole::Mole(const lisp::Lisp& reader)
+ : BadGuy(reader, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING)
+{
+ physic.enable_gravity(false);
+}
+
+Mole::Mole(const Vector& pos)
+ : BadGuy(pos, "images/creatures/mole/mole.sprite", LAYER_TILES-1), state(PRE_THROWING)
+{
+ physic.enable_gravity(false);
+}
+
+void
+Mole::write(lisp::Writer& writer)
+{
+ writer.start_list("mole");
+ writer.write_float("x", start_position.x);
+ writer.write_float("y", start_position.y);
+ writer.end_list("mole");
+}
+
+void
+Mole::activate()
+{
+ if (state != DEAD) set_state(PRE_THROWING);
+}
+
+void
+Mole::kill_fall()
+{
+ set_state(DEAD);
+ sound_manager->play("sounds/fall.wav", get_pos());
+ if (countMe) Sector::current()->get_level()->stats.badguys++;
+}
+
+HitResponse
+Mole::collision_badguy(BadGuy& , const CollisionHit& )
+{
+ return FORCE_MOVE;
+}
+
+bool
+Mole::collision_squished(Player& )
+{
+ set_state(DEAD);
+ sound_manager->play("sounds/squish.wav", get_pos());
+ if (countMe) Sector::current()->get_level()->stats.badguys++;
+ return true;
+}
+
+void
+Mole::throw_rock()
+{
+ float px = get_bbox().get_middle().x;
+ float py = get_bbox().get_middle().y;
+
+ float angle = systemRandom.rand(90 - 15, 90 + 15) * (M_PI / 180);
+ float vx = cos(angle) * THROW_VELOCITY;
+ float vy = -sin(angle) * THROW_VELOCITY;
+
+ sound_manager->play("sounds/dartfire.wav", get_pos());
+ Sector::current()->add_object(new MoleRock(Vector(px, py), Vector(vx, vy), this));
+}
+
+void
+Mole::active_update(float elapsed_time)
+{
+ BadGuy::active_update(elapsed_time);
+
+ switch (state) {
+ case PRE_THROWING:
+ if (timer.check()) {
+ set_state(THROWING);
+ }
+ break;
+ case THROWING:
+ if (throw_timer.check()) {
+ throw_rock();
+ throw_timer.start(THROW_INTERVAL);
+ }
+ if (timer.check()) {
+ set_state(POST_THROWING);
+ }
+ break;
+ case POST_THROWING:
+ if (timer.check()) {
+ set_state(PEEKING);
+ }
+ break;
+ case PEEKING:
+ if (sprite->animation_done()) {
+ set_state(PRE_THROWING);
+ }
+ break;
+ case DEAD:
+ break;
+ }
+
+}
+
+void
+Mole::set_state(MoleState new_state)
+{
+ switch (new_state) {
+ case PRE_THROWING:
+ sprite->set_action("idle");
+ set_group(COLGROUP_DISABLED);
+ timer.start(IDLE_TIME);
+ break;
+ case THROWING:
+ sprite->set_action("idle");
+ set_group(COLGROUP_DISABLED);
+ timer.start(THROW_TIME);
+ throw_timer.start(THROW_INTERVAL);
+ break;
+ case POST_THROWING:
+ sprite->set_action("idle");
+ set_group(COLGROUP_DISABLED);
+ timer.start(IDLE_TIME);
+ break;
+ case PEEKING:
+ sprite->set_action("peeking", 1);
+ set_group(COLGROUP_STATIC);
+ break;
+ case DEAD:
+ sprite->set_action("idle");
+ set_group(COLGROUP_DISABLED);
+ break;
+ }
+
+ state = new_state;
+}
+
+IMPLEMENT_FACTORY(Mole, "mole")
+
--- /dev/null
+// $Id$
+//
+// SuperTux - Mole Badguy
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@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 __MOLE_H__
+#define __MOLE_H__
+
+#include "badguy.hpp"
+
+class Mole : public BadGuy
+{
+public:
+ Mole(const lisp::Lisp& );
+ Mole(const Vector& pos);
+
+ void kill_fall();
+ HitResponse collision_badguy(BadGuy& , const CollisionHit& );
+ bool collision_squished(Player& player);
+
+ void activate();
+ void write(lisp::Writer& );
+ void active_update(float);
+
+ virtual Mole* clone() const { return new Mole(*this); }
+
+private:
+ enum MoleState {
+ PRE_THROWING,
+ THROWING,
+ POST_THROWING,
+ PEEKING,
+ DEAD
+ };
+
+ MoleState state;
+ Timer timer;
+ Timer throw_timer;
+
+ void set_state(MoleState new_state);
+ void throw_rock();
+
+};
+
+#endif
--- /dev/null
+// $Id$
+//
+// MoleRock - Rock thrown by "Mole" Badguy
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@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 "mole_rock.hpp"
+
+MoleRock::MoleRock(const lisp::Lisp& reader)
+ : BadGuy(reader, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(0), initial_velocity(Vector(0, -400))
+{
+ physic.enable_gravity(true);
+ countMe = false;
+}
+
+MoleRock::MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent = 0)
+ : BadGuy(pos, LEFT, "images/creatures/mole/mole_rock.sprite", LAYER_TILES - 2), parent(parent), initial_velocity(velocity)
+{
+ physic.enable_gravity(true);
+ countMe = false;
+}
+
+MoleRock::MoleRock(const MoleRock& other)
+ : BadGuy(other), parent(other.parent), initial_velocity(Vector(0, -400))
+{
+}
+
+MoleRock::~MoleRock()
+{
+}
+
+bool
+MoleRock::updatePointers(const GameObject* from_object, GameObject* to_object)
+{
+ if (from_object == parent) {
+ parent = dynamic_cast<MoleRock*>(to_object);
+ return true;
+ }
+ return false;
+}
+
+void
+MoleRock::write(lisp::Writer& writer)
+{
+ writer.start_list("mole_rock");
+ writer.write_float("x", start_position.x);
+ writer.write_float("y", start_position.y);
+ writer.end_list("mole_rock");
+}
+
+void
+MoleRock::activate()
+{
+ physic.set_velocity(initial_velocity);
+ sprite->set_action("default");
+}
+
+void
+MoleRock::deactivate()
+{
+ remove_me();
+}
+
+void
+MoleRock::active_update(float elapsed_time)
+{
+ BadGuy::active_update(elapsed_time);
+}
+
+void
+MoleRock::collision_solid(const CollisionHit& )
+{
+ sound_manager->play("sounds/darthit.wav", get_pos());
+ remove_me();
+}
+
+HitResponse
+MoleRock::collision_badguy(BadGuy& badguy, const CollisionHit& )
+{
+ // ignore collisions with parent
+ if (&badguy == parent) {
+ return FORCE_MOVE;
+ }
+ sound_manager->play("sounds/stomp.wav", get_pos());
+ remove_me();
+ badguy.kill_fall();
+ return ABORT_MOVE;
+}
+
+HitResponse
+MoleRock::collision_player(Player& player, const CollisionHit& hit)
+{
+ sound_manager->play("sounds/stomp.wav", get_pos());
+ remove_me();
+ return BadGuy::collision_player(player, hit);
+}
+
+IMPLEMENT_FACTORY(MoleRock, "mole_rock")
--- /dev/null
+// $Id$
+//
+// MoleRock - Rock thrown by "Mole" Badguy
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@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 __MOLE_ROCK_H__
+#define __MOLE_ROCK_H__
+
+#include "badguy.hpp"
+
+/**
+ * Badguy "MoleRock" - Rock thrown by "Mole" Badguy
+ */
+class MoleRock : public BadGuy
+{
+public:
+ MoleRock(const lisp::Lisp& reader);
+ MoleRock(const Vector& pos, const Vector& velocity, const BadGuy* parent);
+ MoleRock(const MoleRock& mole_rock);
+ ~MoleRock();
+
+ void activate();
+ void deactivate();
+ void write(lisp::Writer& writer);
+
+ void active_update(float elapsed_time);
+
+ void collision_solid(const CollisionHit& hit);
+ HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+ HitResponse collision_player(Player& player, const CollisionHit& hit);
+
+ virtual MoleRock* clone() const { return new MoleRock(*this); }
+
+ virtual bool updatePointers(const GameObject* from_object, GameObject* to_object);
+
+protected:
+ const BadGuy* parent; /**< collisions with this BadGuy will be ignored */
+ const Vector initial_velocity; /**< velocity at time of creation */
+};
+
+#endif
--- /dev/null
+// $Id: toad.cpp 4192 2006-08-16 23:25:39Z sommer $
+//
+// Toad - A jumping toad
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@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 "toad.hpp"
+#include "random_generator.hpp"
+
+namespace {
+ const float VERTICAL_SPEED = -450; /**< y-speed when jumping */
+ const float HORIZONTAL_SPEED = 320; /**< x-speed when jumping */
+ const float RECOVER_TIME = 0.5; /**< time to stand still before starting a (new) jump */
+ static const std::string HOP_SOUND = "sounds/hop.ogg";
+}
+
+Toad::Toad(const lisp::Lisp& reader)
+ : BadGuy(reader, "images/creatures/toad/toad.sprite")
+{
+ sound_manager->preload(HOP_SOUND);
+}
+
+Toad::Toad(const Vector& pos, Direction d)
+ : BadGuy(pos, d, "images/creatures/toad/toad.sprite")
+{
+ sound_manager->preload(HOP_SOUND);
+}
+
+void
+Toad::write(lisp::Writer& writer)
+{
+ writer.start_list("toad");
+ writer.write_float("x", start_position.x);
+ writer.write_float("y", start_position.y);
+ writer.end_list("toad");
+}
+
+void
+Toad::activate()
+{
+ // initial state is JUMPING, because we might start airborne
+ state = JUMPING;
+ sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
+}
+
+void
+Toad::set_state(ToadState newState)
+{
+ if (newState == IDLE) {
+ physic.set_velocity_x(0);
+ physic.set_velocity_y(0);
+ sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
+
+ recover_timer.start(RECOVER_TIME);
+ } 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);
+ sound_manager->play( HOP_SOUND, get_pos());
+ } else
+ if (newState == FALLING) {
+ Player* player = get_nearest_player();
+ // face player
+ if (player && (player->get_bbox().p2.x < get_bbox().p1.x) && (dir == RIGHT)) dir = LEFT;
+ if (player && (player->get_bbox().p1.x > get_bbox().p2.x) && (dir == LEFT)) dir = RIGHT;
+ sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
+ }
+
+ state = newState;
+}
+
+bool
+Toad::collision_squished(Player& player)
+{
+ sprite->set_action(dir == LEFT ? "squished-left" : "squished-right");
+ kill_squished(player);
+ return true;
+}
+
+void
+Toad::collision_solid(const CollisionHit& hit)
+{
+ // just default behaviour (i.e. stop at floor/walls) when squished
+ if (BadGuy::get_state() == STATE_SQUISHED) {
+ BadGuy::collision_solid(hit);
+ return;
+ }
+
+ // ignore collisions while standing still
+ if(state == IDLE) {
+ return;
+ }
+
+ // check if we hit left or right while moving in either direction
+ if(((physic.get_velocity_x() < 0) && hit.left) || ((physic.get_velocity_x() > 0) && hit.right)) {
+ /*
+ dir = dir == LEFT ? RIGHT : LEFT;
+ if (state == JUMPING) {
+ sprite->set_action(dir == LEFT ? "jumping-left" : "jumping-right");
+ } else {
+ sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
+ }
+ */
+ physic.set_velocity_x(-0.25*physic.get_velocity_x());
+ }
+
+ // check if we hit the floor while falling
+ if ((state == FALLING) && hit.bottom) {
+ set_state(IDLE);
+ return;
+ }
+
+ // check if we hit the roof while climbing
+ if ((state == JUMPING) && hit.top) {
+ physic.set_velocity_y(0);
+ }
+
+}
+
+HitResponse
+Toad::collision_badguy(BadGuy& , const CollisionHit& hit)
+{
+ // behaviour for badguy collisions is the same as for collisions with solids
+ collision_solid(hit);
+
+ return CONTINUE;
+}
+
+void
+Toad::active_update(float elapsed_time)
+{
+ BadGuy::active_update(elapsed_time);
+
+ // change sprite when we are falling
+ if ((state == JUMPING) && (physic.get_velocity_y() > 0)) {
+ set_state(FALLING);
+ return;
+ }
+
+ // jump when fully recovered
+ if ((state == IDLE) && (recover_timer.check())) {
+ set_state(JUMPING);
+ return;
+ }
+
+}
+
+IMPLEMENT_FACTORY(Toad, "toad")
--- /dev/null
+// $Id: toad.hpp 4063 2006-07-21 21:05:23Z anmaster $
+//
+// Toad - A jumping toad
+// Copyright (C) 2006 Christoph Sommer <christoph.sommer@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 __TOAD_H__
+#define __TOAD_H__
+
+#include "badguy.hpp"
+
+/**
+ * Badguy "Toad" - A jumping toad
+ */
+class Toad : public BadGuy
+{
+public:
+ Toad(const lisp::Lisp& reader);
+ Toad(const Vector& pos, Direction d);
+
+ void activate();
+ void write(lisp::Writer& writer);
+ void collision_solid(const CollisionHit& hit);
+ HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit);
+ bool collision_squished(Player& player);
+ void active_update(float elapsed_time);
+
+ virtual Toad* clone() const { return new Toad(*this); }
+
+protected:
+ enum ToadState {
+ IDLE,
+ JUMPING,
+ FALLING
+ };
+
+ Timer recover_timer;
+ ToadState state;
+
+ void set_state(ToadState newState);
+};
+
+#endif