From: Marek Moeckel Date: Sun, 2 Jan 2005 19:00:43 +0000 (+0000) Subject: added PoisonIvy badguy contributed by Stephen Groundwater X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=6f988a2dfbe4de1096a5ca6a4b30e7fc5355316c;p=supertux.git added PoisonIvy badguy contributed by Stephen Groundwater SVN-Revision: 2271 --- diff --git a/data/images/shared/poisonivy-left-0.png b/data/images/shared/poisonivy-left-0.png new file mode 100644 index 000000000..2a984f3dc Binary files /dev/null and b/data/images/shared/poisonivy-left-0.png differ diff --git a/data/images/shared/poisonivy-left-1.png b/data/images/shared/poisonivy-left-1.png new file mode 100644 index 000000000..f2fc9827e Binary files /dev/null and b/data/images/shared/poisonivy-left-1.png differ diff --git a/data/images/shared/poisonivy-left-2.png b/data/images/shared/poisonivy-left-2.png new file mode 100644 index 000000000..bd010c6eb Binary files /dev/null and b/data/images/shared/poisonivy-left-2.png differ diff --git a/data/images/shared/poisonivy-squished-left.png b/data/images/shared/poisonivy-squished-left.png new file mode 100644 index 000000000..4ca865107 Binary files /dev/null and b/data/images/shared/poisonivy-squished-left.png differ diff --git a/data/images/supertux.strf b/data/images/supertux.strf index ec8b35af0..1eddb4e24 100644 --- a/data/images/supertux.strf +++ b/data/images/supertux.strf @@ -1161,6 +1161,73 @@ (images "shared/dummyguy-dead.png"))) + ; MrTree + (sprite (name "mrtree") + (action + (y-offset -3) + (fps 5) + (name "left") + (images "shared/mrtree-walk-left-0.png" + "shared/mrtree-walk-left-1.png" + "shared/mrtree-walk-left-2.png") + ) + (action + (y-offset -3) + (fps 5) + (name "right") + (mirror-action "left") + ) + (action + (y-offset -3) + (name "small-left") + (images "shared/mrtree-small-left-0.png" + "shared/mrtree-small-left-1.png" + "shared/mrtree-small-left-2.png") + ) + (action + (y-offset -3) + (name "small-right") + (mirror-action "small-left") + ) + (action + (y-offset -6) + (name "squished-left") + (images "shared/mrtree-squished-left.png") + ) + (action + (y-offset -6) + (name "squished-right") + (mirror-action "squished-left") + ) + ) + + ; PoisonIvy + (sprite (name "poisonivy") + (action + (name "left") + (x-offset 2) + (y-offset 4) + (images "shared/poisonivy-left-0.png" + "shared/poisonivy-left-1.png" + "shared/poisonivy-left-2.png")) + + (action + (name "right") + (x-offset 2) + (y-offset 4) + (mirror-action "left")) + (action + (name "squished-left") + (x-offset 1) + (y-offset -19) + (images "shared/poisonivy-squished-left.png")) + + (action + (name "squished-right") + (x-offset 1) + (y-offset -19) + (mirror-action "squished-left"))) + ;; Game elements follow @@ -1326,45 +1393,6 @@ (images "tilesets/bonus2-d.png")) ) - (sprite (name "mrtree") - (action - (y-offset -3) - (fps 5) - (name "left") - (images "shared/mrtree-walk-left-0.png" - "shared/mrtree-walk-left-1.png" - "shared/mrtree-walk-left-2.png") - ) - (action - (y-offset -3) - (fps 5) - (name "right") - (mirror-action "left") - ) - (action - (y-offset -3) - (name "small-left") - (images "shared/mrtree-small-left-0.png" - "shared/mrtree-small-left-1.png" - "shared/mrtree-small-left-2.png") - ) - (action - (y-offset -3) - (name "small-right") - (mirror-action "small-left") - ) - (action - (y-offset -6) - (name "squished-left") - (images "shared/mrtree-squished-left.png") - ) - (action - (y-offset -6) - (name "squished-right") - (mirror-action "squished-left") - ) - ) - ; Stomp (sprite (name "stomp") (action diff --git a/data/levels/test/mrtree.stl b/data/levels/test/mrtree.stl index cee56ad8a..3c37f5f85 100644 --- a/data/levels/test/mrtree.stl +++ b/data/levels/test/mrtree.stl @@ -192,6 +192,14 @@ )) (mrtree (x 200) (y 10)) + (poisonivy (x 800) (y 10)) + (poisonivy (x 1000) (y 10)) + (poisonivy (x 1200) (y 10)) + (poisonivy (x 1400) (y 10)) + (poisonivy (x 1800) (y 10)) + (poisonivy (x 2000) (y 10)) + (poisonivy (x 2500) (y 10)) + (poisonivy (x 3000) (y 10)) ) ) diff --git a/src/badguy/poisonivy.cpp b/src/badguy/poisonivy.cpp new file mode 100644 index 000000000..7739b82f0 --- /dev/null +++ b/src/badguy/poisonivy.cpp @@ -0,0 +1,79 @@ +#include + +#include "poisonivy.h" + +static const float WALKSPEED = 80; + +PoisonIvy::PoisonIvy(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("poisonivy"); + set_direction = false; +} + +PoisonIvy::PoisonIvy(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("poisonivy"); + set_direction = true; + initial_direction = d; +} + +void +PoisonIvy::write(lisp::Writer& writer) +{ + writer.start_list("poisonivy"); + + writer.write_float("x", start_position.x); + writer.write_float("y", start_position.y); + + writer.end_list("poisonivy"); +} + +void +PoisonIvy::activate() +{ + if (set_direction) {dir = initial_direction;} + physic.set_velocity_x(dir == LEFT ? -WALKSPEED : WALKSPEED); + sprite->set_action(dir == LEFT ? "left" : "right"); +} + +bool +PoisonIvy::collision_squished(Player& player) +{ + sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); + kill_squished(player); + return true; +} + +HitResponse +PoisonIvy::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 +PoisonIvy::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(PoisonIvy, "poisonivy") diff --git a/src/badguy/poisonivy.h b/src/badguy/poisonivy.h new file mode 100644 index 000000000..811fc4e97 --- /dev/null +++ b/src/badguy/poisonivy.h @@ -0,0 +1,23 @@ +#ifndef __POISONIVY_H__ +#define __POISONIVY_H__ + +#include "badguy.h" + +class PoisonIvy : public BadGuy +{ +public: + PoisonIvy(const lisp::Lisp& reader); + PoisonIvy(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