From: Wolfgang Becker Date: Tue, 12 Feb 2008 19:36:28 +0000 (+0000) Subject: * Launcher can shoot two new types of snowballs. X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=9a59c6599a15d5e6614d956de2111edc572b9486;p=supertux.git * Launcher can shoot two new types of snowballs. SVN-Revision: 5323 --- diff --git a/data/images/creatures/canon/canon.png b/data/images/creatures/canon/canon.png deleted file mode 100644 index cb658fdd3..000000000 Binary files a/data/images/creatures/canon/canon.png and /dev/null differ diff --git a/data/images/creatures/dispenser/canon.png b/data/images/creatures/dispenser/canon.png new file mode 100644 index 000000000..cb658fdd3 Binary files /dev/null and b/data/images/creatures/dispenser/canon.png differ diff --git a/data/images/creatures/dispenser/dispenser.sprite b/data/images/creatures/dispenser/dispenser.sprite index cc2f3be84..b7870ab56 100644 --- a/data/images/creatures/dispenser/dispenser.sprite +++ b/data/images/creatures/dispenser/dispenser.sprite @@ -5,6 +5,11 @@ (images "dropper.png")) (action + (name "working") + (hitbox 3 5 32 60) + (images "canon.png")) + + (action (name "working-left") (hitbox 5 12 55 40) (images "working.png")) diff --git a/data/images/creatures/snowball/collision-left.png b/data/images/creatures/snowball/collision-left.png new file mode 100644 index 000000000..87e3ddefb Binary files /dev/null and b/data/images/creatures/snowball/collision-left.png differ diff --git a/data/images/creatures/snowball/cpt-left-0.png b/data/images/creatures/snowball/cpt-left-0.png new file mode 100644 index 000000000..9c43ae87b Binary files /dev/null and b/data/images/creatures/snowball/cpt-left-0.png differ diff --git a/data/images/creatures/snowball/cpt-left-1.png b/data/images/creatures/snowball/cpt-left-1.png new file mode 100644 index 000000000..c9f129622 Binary files /dev/null and b/data/images/creatures/snowball/cpt-left-1.png differ diff --git a/data/images/creatures/snowball/cpt-left-2.png b/data/images/creatures/snowball/cpt-left-2.png new file mode 100644 index 000000000..4d3d51315 Binary files /dev/null and b/data/images/creatures/snowball/cpt-left-2.png differ diff --git a/data/images/creatures/snowball/cpt-right-0.png b/data/images/creatures/snowball/cpt-right-0.png new file mode 100644 index 000000000..81595c463 Binary files /dev/null and b/data/images/creatures/snowball/cpt-right-0.png differ diff --git a/data/images/creatures/snowball/cpt-right-1.png b/data/images/creatures/snowball/cpt-right-1.png new file mode 100644 index 000000000..7b1542062 Binary files /dev/null and b/data/images/creatures/snowball/cpt-right-1.png differ diff --git a/data/images/creatures/snowball/cpt-right-2.png b/data/images/creatures/snowball/cpt-right-2.png new file mode 100644 index 000000000..00bf77cda Binary files /dev/null and b/data/images/creatures/snowball/cpt-right-2.png differ diff --git a/data/images/creatures/snowball/cpt-snowball.sprite b/data/images/creatures/snowball/cpt-snowball.sprite new file mode 100644 index 000000000..545151e4c --- /dev/null +++ b/data/images/creatures/snowball/cpt-snowball.sprite @@ -0,0 +1,26 @@ +(supertux-sprite + (action + (name "left") + (hitbox 2 4 31.8 31.8) + (images "cpt-left-0.png" + "cpt-left-1.png" + "cpt-left-2.png") + ) + (action + (name "right") + (hitbox 8 4 31.8 31.8) + (images "cpt-right-0.png" + "cpt-right-1.png" + "cpt-right-2.png") + ) + (action + (name "squished-left") + (hitbox 1 -19 31.8 31.8) + (images "cpt-squished-left.png") + ) + (action + (name "squished-right") + (hitbox 1 -19 31.8 31.8) + (images "cpt-squished-right.png") + ) +) diff --git a/data/images/creatures/snowball/cpt-squished-left.png b/data/images/creatures/snowball/cpt-squished-left.png new file mode 100644 index 000000000..a1c3017c3 Binary files /dev/null and b/data/images/creatures/snowball/cpt-squished-left.png differ diff --git a/data/images/creatures/snowball/cpt-squished-right.png b/data/images/creatures/snowball/cpt-squished-right.png new file mode 100644 index 000000000..1e583bfe5 Binary files /dev/null and b/data/images/creatures/snowball/cpt-squished-right.png differ diff --git a/data/images/creatures/snowball/kamikaze-left.png b/data/images/creatures/snowball/kamikaze-left.png new file mode 100644 index 000000000..c5be83837 Binary files /dev/null and b/data/images/creatures/snowball/kamikaze-left.png differ diff --git a/data/images/creatures/snowball/kamikaze-snowball.sprite b/data/images/creatures/snowball/kamikaze-snowball.sprite new file mode 100644 index 000000000..3aba29b31 --- /dev/null +++ b/data/images/creatures/snowball/kamikaze-snowball.sprite @@ -0,0 +1,30 @@ +(supertux-sprite + (action + (name "left") + (hitbox 2 4 31.8 23.8) + (images "kamikaze-left.png") + ) + (action + (name "right") + (hitbox 13 4 31.8 23.8) + (mirror-action "left") + ) + (action + (name "squished-left") + (hitbox 1 -19 31.8 31.8) + (images "squished-left.png") + ) + (action + (name "squished-right") + (hitbox 1 -19 31.8 31.8) + (mirror-action "squished-left") + ) + (action + (name "collision-left") + (images "collision-left.png") + ) + (action + (name "collision-right") + (mirror-action "collision-left") + ) +) diff --git a/data/images/creatures/snowball/left-0.png b/data/images/creatures/snowball/left-0.png index 5d6e71826..fa8dde55e 100644 Binary files a/data/images/creatures/snowball/left-0.png and b/data/images/creatures/snowball/left-0.png differ diff --git a/data/images/creatures/snowball/left-1.png b/data/images/creatures/snowball/left-1.png index 1b53c2488..2dcf8fb40 100644 Binary files a/data/images/creatures/snowball/left-1.png and b/data/images/creatures/snowball/left-1.png differ diff --git a/data/images/creatures/snowball/left-2.png b/data/images/creatures/snowball/left-2.png index ad04a7772..b00204e59 100644 Binary files a/data/images/creatures/snowball/left-2.png and b/data/images/creatures/snowball/left-2.png differ diff --git a/data/images/creatures/snowball/sport-left-0.png b/data/images/creatures/snowball/sport-left-0.png index 82454b90e..c5c6ede0d 100644 Binary files a/data/images/creatures/snowball/sport-left-0.png and b/data/images/creatures/snowball/sport-left-0.png differ diff --git a/data/images/creatures/snowball/sport-left-1.png b/data/images/creatures/snowball/sport-left-1.png index 1abb5db5b..271d3017f 100644 Binary files a/data/images/creatures/snowball/sport-left-1.png and b/data/images/creatures/snowball/sport-left-1.png differ diff --git a/data/images/creatures/snowball/sport-left-2.png b/data/images/creatures/snowball/sport-left-2.png index e853efeb9..463fa1c4f 100644 Binary files a/data/images/creatures/snowball/sport-left-2.png and b/data/images/creatures/snowball/sport-left-2.png differ diff --git a/data/images/creatures/snowball/squished-left.png b/data/images/creatures/snowball/squished-left.png index df64fa959..4362c557b 100644 Binary files a/data/images/creatures/snowball/squished-left.png and b/data/images/creatures/snowball/squished-left.png differ diff --git a/src/badguy/captainsnowball.cpp b/src/badguy/captainsnowball.cpp new file mode 100644 index 000000000..a6975dab6 --- /dev/null +++ b/src/badguy/captainsnowball.cpp @@ -0,0 +1,61 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2008 Wolfgang Becker +// +// 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 "captainsnowball.hpp" + +namespace{ + static const float WALK_SPEED = 50; + static const float BOARDING_SPEED = 300; +} + + +CaptainSnowball::CaptainSnowball(const lisp::Lisp& reader) + : WalkingBadguy(reader, "images/creatures/snowball/cpt-snowball.sprite", "left", "right") +{ + walk_speed = WALK_SPEED; // peg leg + max_drop_height = -1;// eye patch +} + +CaptainSnowball::CaptainSnowball(const Vector& pos, Direction d) + : WalkingBadguy(pos, d, "images/creatures/snowball/cpt-snowball.sprite", "left", "right") +{ + // Created during game eg. by dispencer. Board the enemy! + walk_speed = BOARDING_SPEED; + physic.set_velocity_y(-500); +} + +void +CaptainSnowball::collision_solid(const CollisionHit& hit) +{ + WalkingBadguy::collision_solid(hit); + walk_speed = WALK_SPEED; + physic.set_velocity_x(dir == LEFT ? -walk_speed : walk_speed); +} + +bool +CaptainSnowball::collision_squished(GameObject& object) +{ + sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); + kill_squished(object); + return true; +} + +IMPLEMENT_FACTORY(CaptainSnowball, "captainsnowball") diff --git a/src/badguy/captainsnowball.hpp b/src/badguy/captainsnowball.hpp new file mode 100644 index 000000000..b1043a0e1 --- /dev/null +++ b/src/badguy/captainsnowball.hpp @@ -0,0 +1,39 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2008 Wolfgang Becker +// +// 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 __CAPTAINSNOWBALL_H__ +#define __CAPTAINSNOWBALL_H__ + +#include "walking_badguy.hpp" + +class CaptainSnowball : public WalkingBadguy +{ +public: + CaptainSnowball(const lisp::Lisp& reader); + CaptainSnowball(const Vector& pos, Direction d); + + virtual CaptainSnowball* clone() const { return new CaptainSnowball(*this); } + void collision_solid(const CollisionHit& hit); + +protected: + bool collision_squished(GameObject& object); + +}; + +#endif diff --git a/src/badguy/dispenser.cpp b/src/badguy/dispenser.cpp index c603946e3..73a931b6a 100644 --- a/src/badguy/dispenser.cpp +++ b/src/badguy/dispenser.cpp @@ -28,6 +28,8 @@ #include "badguy/poisonivy.hpp" #include "badguy/snail.hpp" #include "badguy/skullyhop.hpp" +#include "badguy/captainsnowball.hpp" +#include "badguy/kamikazesnowball.hpp" #include "random_generator.hpp" Dispenser::Dispenser(const lisp::Lisp& reader) @@ -42,8 +44,11 @@ Dispenser::Dispenser(const lisp::Lisp& reader) if( start_dir == AUTO ){ autotarget = true; } + } else if ( badguy == "kamikazesnowball" || badguy == "captainsnowball" ) { + sprite->set_action("working"); + } else { + sprite->set_action("dropper"); } - else {sprite->set_action("dropper");} bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); countMe = false; } @@ -64,6 +69,13 @@ Dispenser::write(lisp::Writer& writer) void Dispenser::activate() { + if( autotarget && !swivel ){ // auto canon sprite might be wrong + Player* player = this->get_nearest_player(); + if( player ){ + dir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT; + sprite->set_action(dir == LEFT ? "working-left" : "working-right"); + } + } dispense_timer.start(cycle, true); launch_badguy(); } @@ -121,33 +133,44 @@ Dispenser::launch_badguy() { //FIXME: Does is_offscreen() work right here? if (!is_offscreen()) { + Direction launchdir = dir; + if( !autotarget && start_dir == AUTO ){ + Player* player = this->get_nearest_player(); + if( player ){ + launchdir = (player->get_pos().x > get_pos().x) ? RIGHT : LEFT; + } + } if (badguy == "snowball") - Sector::current()->add_object(new SnowBall(Vector(get_pos().x, get_pos().y+32), dir)); + Sector::current()->add_object(new SnowBall(Vector(get_pos().x, get_pos().y+32), launchdir)); else if (badguy == "bouncingsnowball") - Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x, get_pos().y+32), dir)); + Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x, get_pos().y+32), launchdir)); else if (badguy == "mrbomb") - Sector::current()->add_object(new MrBomb(Vector(get_pos().x, get_pos().y+32), dir)); + Sector::current()->add_object(new MrBomb(Vector(get_pos().x, get_pos().y+32), launchdir)); else if (badguy == "mriceblock") - Sector::current()->add_object(new MrIceBlock(Vector(get_pos().x, get_pos().y+32), dir)); + Sector::current()->add_object(new MrIceBlock(Vector(get_pos().x, get_pos().y+32), launchdir)); else if (badguy == "snail") - Sector::current()->add_object(new Snail(Vector(get_pos().x, get_pos().y+32), dir)); - else if (badguy == "mrrocket") { - Sector::current()->add_object(new MrRocket(Vector(get_pos().x+(dir == LEFT ? -32 : 32), get_pos().y), dir));} + Sector::current()->add_object(new Snail(Vector(get_pos().x, get_pos().y+32), launchdir)); + else if (badguy == "mrrocket") + Sector::current()->add_object(new MrRocket(Vector(get_pos().x+(launchdir == LEFT ? -32 : 32), get_pos().y), launchdir)); + else if (badguy == "captainsnowball") + Sector::current()->add_object(new CaptainSnowball(Vector(get_pos().x+(launchdir == LEFT ? -32 : 32), get_pos().y), launchdir)); + else if (badguy == "kamikazesnowball") + Sector::current()->add_object(new KamikazeSnowball(Vector(get_pos().x+(launchdir == LEFT ? -32 : 32), get_pos().y), launchdir)); else if (badguy == "poisonivy") - Sector::current()->add_object(new PoisonIvy(Vector(get_pos().x, get_pos().y+32), dir)); + Sector::current()->add_object(new PoisonIvy(Vector(get_pos().x, get_pos().y+32), launchdir)); else if (badguy == "skullyhop") - Sector::current()->add_object(new SkullyHop(Vector(get_pos().x, get_pos().y+44), dir)); + Sector::current()->add_object(new SkullyHop(Vector(get_pos().x, get_pos().y+44), launchdir)); else if (badguy == "random") { switch (systemRandom.rand(7)) { - case 0: Sector::current()->add_object(new SnowBall(Vector(get_pos().x, get_pos().y+32), dir)); break; - case 1: Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x, get_pos().y+32), dir)); break; - case 2: Sector::current()->add_object(new MrBomb(Vector(get_pos().x, get_pos().y+32), dir)); break; - case 3: Sector::current()->add_object(new MrIceBlock(Vector(get_pos().x, get_pos().y+32), dir)); break; - case 4: Sector::current()->add_object(new PoisonIvy(Vector(get_pos().x, get_pos().y+32), dir)); break; - case 5: Sector::current()->add_object(new Snail(Vector(get_pos().x, get_pos().y+32), dir)); break; - case 6: Sector::current()->add_object(new SkullyHop(Vector(get_pos().x, get_pos().y+44), dir)); break; + case 0: Sector::current()->add_object(new SnowBall(Vector(get_pos().x, get_pos().y+32), launchdir)); break; + case 1: Sector::current()->add_object(new BouncingSnowball(Vector(get_pos().x, get_pos().y+32), launchdir)); break; + case 2: Sector::current()->add_object(new MrBomb(Vector(get_pos().x, get_pos().y+32), launchdir)); break; + case 3: Sector::current()->add_object(new MrIceBlock(Vector(get_pos().x, get_pos().y+32), launchdir)); break; + case 4: Sector::current()->add_object(new PoisonIvy(Vector(get_pos().x, get_pos().y+32), launchdir)); break; + case 5: Sector::current()->add_object(new Snail(Vector(get_pos().x, get_pos().y+32), launchdir)); break; + case 6: Sector::current()->add_object(new SkullyHop(Vector(get_pos().x, get_pos().y+44), launchdir)); break; } } } diff --git a/src/badguy/kamikazesnowball.cpp b/src/badguy/kamikazesnowball.cpp new file mode 100644 index 000000000..ebfdc3613 --- /dev/null +++ b/src/badguy/kamikazesnowball.cpp @@ -0,0 +1,94 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2008 Wolfgang Becker +// +// 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 "kamikazesnowball.hpp" + +/* + * Kamikaze Snowball will fly in one direction until he hits something. + * On impact he is destroyed, trying to kill what he hit or hit him. + */ +namespace{ + static const float SPEED = 200; + const std::string SPLAT_SOUND = "sounds/splat.wav"; +} + +KamikazeSnowball::KamikazeSnowball(const lisp::Lisp& reader) + : BadGuy(reader, "images/creatures/snowball/kamikaze-snowball.sprite") +{ + sound_manager->preload(SPLAT_SOUND); +} + +KamikazeSnowball::KamikazeSnowball(const Vector& pos, Direction d) + : BadGuy(pos, d, "images/creatures/snowball/kamikaze-snowball.sprite") +{ + sound_manager->preload(SPLAT_SOUND); +} + +void +KamikazeSnowball::initialize() +{ + physic.set_velocity_x(dir == LEFT ? -SPEED : SPEED); + physic.enable_gravity(false); + sprite->set_action(dir == LEFT ? "left" : "right"); +} + +bool +KamikazeSnowball::collision_squished(GameObject& object) +{ + sprite->set_action(dir == LEFT ? "squished-left" : "squished-right"); + kill_squished(object); + return true; +} + +void +KamikazeSnowball::collision_solid(const CollisionHit& hit) +{ + if(hit.top || hit.bottom) { + physic.set_velocity_y(0); + } else if(hit.left || hit.right) { + kill_collision(); + } +} + +void +KamikazeSnowball::kill_collision() +{ + sprite->set_action(dir == LEFT ? "collision-left" : "collision-right"); + sound_manager->play(SPLAT_SOUND, get_pos()); + physic.set_velocity_x(0); + physic.set_velocity_y(0); + physic.enable_gravity(true); + set_state(STATE_FALLING); +} + +HitResponse +KamikazeSnowball::collision_player(Player& player, const CollisionHit& hit) +{ + HitResponse response = BadGuy::collision_player(player, hit); + if(response == FORCE_MOVE){ + kill_collision(); + response = ABORT_MOVE; + } + return response; +} + + +IMPLEMENT_FACTORY(KamikazeSnowball, "kamikazesnowball") diff --git a/src/badguy/kamikazesnowball.hpp b/src/badguy/kamikazesnowball.hpp new file mode 100644 index 000000000..04854b8d4 --- /dev/null +++ b/src/badguy/kamikazesnowball.hpp @@ -0,0 +1,42 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2008 Wolfgang Becker +// +// 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 __KAMIKAZESNOWBALL_H__ +#define __KAMIKAZESNOWBALL_H__ + +#include "badguy.hpp" + +class KamikazeSnowball : public BadGuy +{ +public: + KamikazeSnowball(const lisp::Lisp& reader); + KamikazeSnowball(const Vector& pos, Direction d); + + void initialize(); + void collision_solid(const CollisionHit& hit); + + virtual KamikazeSnowball* clone() const { return new KamikazeSnowball(*this); } + +protected: + bool collision_squished(GameObject& object); + HitResponse collision_player(Player& player, const CollisionHit& hit); + void kill_collision(); +}; + +#endif