From: Marek Moeckel Date: Wed, 20 Jul 2005 14:49:01 +0000 (+0000) Subject: added Mr Fluffy badguy X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=d9f6263a08f49c6f4338185a6e42110099a3172c;p=supertux.git added Mr Fluffy badguy I want him for a secret (he's going to appear only once in the whole game), so please don't mention him anywhere or put him in the editor! SVN-Revision: 2739 --- diff --git a/data/images/creatures/mr_fluffy/left-0.png b/data/images/creatures/mr_fluffy/left-0.png new file mode 100644 index 000000000..ba96d8720 Binary files /dev/null and b/data/images/creatures/mr_fluffy/left-0.png differ diff --git a/data/images/creatures/mr_fluffy/left-1.png b/data/images/creatures/mr_fluffy/left-1.png new file mode 100644 index 000000000..65b8760d3 Binary files /dev/null and b/data/images/creatures/mr_fluffy/left-1.png differ diff --git a/data/images/creatures/mr_fluffy/left-2.png b/data/images/creatures/mr_fluffy/left-2.png new file mode 100644 index 000000000..19bbad6f2 Binary files /dev/null and b/data/images/creatures/mr_fluffy/left-2.png differ diff --git a/data/images/creatures/mr_fluffy/squished-left.png b/data/images/creatures/mr_fluffy/squished-left.png new file mode 100644 index 000000000..7c1bb576d Binary files /dev/null and b/data/images/creatures/mr_fluffy/squished-left.png differ diff --git a/data/images/sprites.strf b/data/images/sprites.strf index 054da592e..879e7c47a 100644 --- a/data/images/sprites.strf +++ b/data/images/sprites.strf @@ -864,6 +864,33 @@ (y-offset -19) (mirror-action "squished-left"))) + (sprite (name "fluffy") + (action + (name "left") + (x-offset 2) + (y-offset 4) + (images "creatures/mr_fluffy/left-0.png" + "creatures/mr_fluffy/left-1.png" + "creatures/mr_fluffy/left-2.png" + "creatures/mr_fluffy/left-1.png")) + + (action + (name "right") + (x-offset 2) + (y-offset 4) + (mirror-action "left")) + (action + (name "squished-left") + (x-offset 1) + (y-offset -19) + (images "creatures/mr_fluffy/squished-left.png")) + + (action + (name "squished-right") + (x-offset 1) + (y-offset -19) + (mirror-action "squished-left"))) + (sprite (name "jumpy") (action (name "left-up") diff --git a/src/badguy/fluffy.cpp b/src/badguy/fluffy.cpp new file mode 100644 index 000000000..48e007ad5 --- /dev/null +++ b/src/badguy/fluffy.cpp @@ -0,0 +1,99 @@ +// $Id: Fluffy.cpp 2642 2005-06-26 13:38:53Z 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 "fluffy.hpp" + +static const float WALKSPEED = 80; + +Fluffy::Fluffy(const lisp::Lisp& reader) +{ + reader.get("x", start_position.x); + reader.get("y", start_position.y); + bbox.set_size(31.8, 31.8); + sprite = sprite_manager->create("fluffy"); + set_direction = false; +} + +Fluffy::Fluffy(float pos_x, float pos_y, Direction d) +{ + start_position.x = pos_x; + start_position.y = pos_y; + bbox.set_size(31.8, 31.8); + sprite = sprite_manager->create("fluffy"); + set_direction = true; + initial_direction = d; +} + +void +Fluffy::write(lisp::Writer& writer) +{ + writer.start_list("fluffy"); + + writer.write_float("x", start_position.x); + writer.write_float("y", start_position.y); + + writer.end_list("fluffy"); +} + +void +Fluffy::activate() +{ + if (set_direction) {dir = initial_direction;} + physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); + sprite->set_action(dir == LEFT ? "left" : "right"); +} + +bool +Fluffy::collision_squished(Player& player) +{ + sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); + kill_squished(player); + return true; +} + +HitResponse +Fluffy::collision_solid(GameObject& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.y) > .5) { // hit floor or roof? + physic.set_velocity_y(0); + } else { // hit right or left + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } + + return CONTINUE; +} + +HitResponse +Fluffy::collision_badguy(BadGuy& , const CollisionHit& hit) +{ + if(fabsf(hit.normal.x) > .8) { // left or right hit + dir = dir == LEFT ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "left" : "right"); + physic.set_velocity_x(-physic.get_velocity_x()); + } + + return CONTINUE; +} + +IMPLEMENT_FACTORY(Fluffy, "fluffy") diff --git a/src/badguy/fluffy.hpp b/src/badguy/fluffy.hpp new file mode 100644 index 000000000..f26f0a1a2 --- /dev/null +++ b/src/badguy/fluffy.hpp @@ -0,0 +1,44 @@ +// $Id: snowball.hpp 2642 2005-06-26 13:38:53Z 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 __FLUFFY_H__ +#define __FLUFFY_H__ + +#include "badguy.hpp" + +class Fluffy : public BadGuy +{ +public: + Fluffy(const lisp::Lisp& reader); + Fluffy(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& other, const CollisionHit& hit); + +protected: + bool collision_squished(Player& player); + bool set_direction; + Direction initial_direction; +}; + +#endif +