From: Christoph Sommer Date: Sat, 15 Apr 2006 16:34:34 +0000 (+0000) Subject: Badguys "DartTrap" and "Dart" X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=1ac057dac68afefe6e602f1d114becf8d7f535f2;p=supertux.git Badguys "DartTrap" and "Dart" SVN-Revision: 3347 --- diff --git a/data/images/creatures/dart/dart.sprite b/data/images/creatures/dart/dart.sprite new file mode 100644 index 000000000..461a530a1 --- /dev/null +++ b/data/images/creatures/dart/dart.sprite @@ -0,0 +1,14 @@ +(supertux-sprite + (action + (name "flying-left") + (x-offset 3) + (y-offset 3) + (images "flying.png") + ) + (action + (name "flying-right") + (x-offset 3) + (y-offset 3) + (mirror-action "flying-left") + ) + ) diff --git a/data/images/creatures/dart/flying.png b/data/images/creatures/dart/flying.png new file mode 100644 index 000000000..f817c77e7 Binary files /dev/null and b/data/images/creatures/dart/flying.png differ diff --git a/data/images/creatures/darttrap/darttrap.sprite b/data/images/creatures/darttrap/darttrap.sprite new file mode 100644 index 000000000..129dca514 --- /dev/null +++ b/data/images/creatures/darttrap/darttrap.sprite @@ -0,0 +1,25 @@ +(supertux-sprite + (action + (name "idle-left") + (images "idle.png") + ) + (action + (name "idle-right") + (mirror-action "idle-left") + ) + (action + (name "loading-left") + (images + "idle.png" + "loading-0.png" + "loading-1.png" + "loading-2.png" + "loading-3.png" + "loading-4.png" + ) + ) + (action + (name "loading-right") + (mirror-action "loading-left") + ) + ) diff --git a/data/images/creatures/darttrap/darttrap.xcf b/data/images/creatures/darttrap/darttrap.xcf new file mode 100644 index 000000000..22a18fb51 Binary files /dev/null and b/data/images/creatures/darttrap/darttrap.xcf differ diff --git a/data/images/creatures/darttrap/idle.png b/data/images/creatures/darttrap/idle.png new file mode 100644 index 000000000..69cbdaad5 Binary files /dev/null and b/data/images/creatures/darttrap/idle.png differ diff --git a/data/images/creatures/darttrap/loading-0.png b/data/images/creatures/darttrap/loading-0.png new file mode 100644 index 000000000..6ea19d122 Binary files /dev/null and b/data/images/creatures/darttrap/loading-0.png differ diff --git a/data/images/creatures/darttrap/loading-1.png b/data/images/creatures/darttrap/loading-1.png new file mode 100644 index 000000000..3b7d64300 Binary files /dev/null and b/data/images/creatures/darttrap/loading-1.png differ diff --git a/data/images/creatures/darttrap/loading-2.png b/data/images/creatures/darttrap/loading-2.png new file mode 100644 index 000000000..20aea1a5c Binary files /dev/null and b/data/images/creatures/darttrap/loading-2.png differ diff --git a/data/images/creatures/darttrap/loading-3.png b/data/images/creatures/darttrap/loading-3.png new file mode 100644 index 000000000..a19ad20ba Binary files /dev/null and b/data/images/creatures/darttrap/loading-3.png differ diff --git a/data/images/creatures/darttrap/loading-4.png b/data/images/creatures/darttrap/loading-4.png new file mode 100644 index 000000000..dfa03ff77 Binary files /dev/null and b/data/images/creatures/darttrap/loading-4.png differ diff --git a/data/levels/test/darttrap.stl b/data/levels/test/darttrap.stl new file mode 100644 index 000000000..f189b89e8 --- /dev/null +++ b/data/levels/test/darttrap.stl @@ -0,0 +1,138 @@ +;; Generated by Flexlay Editor +(supertux-level + (version 2) + (name (_ "DartTrap Test")) + (author "Marek") + (sector + (name "main") + (gravity 10.000000) + (tilemap + (layer "background") + (solid #f) + (speed 1.000000) + (width 30) + (height 30) + (tiles + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 + )) + (camera + (mode "normal") + ) + + (background + (image "images/background/arctis.jpg") + (speed 0.500000) + ) + + (darttrap (x 800) (y 850)) + (powerup (x 100) (y 700) (sprite "images/powerups/egg/egg.sprite")) + (spawnpoint (name "main") (x 40) (y 700)) + ) + ) + +;; EOF ;; diff --git a/src/badguy/dart.cpp b/src/badguy/dart.cpp new file mode 100644 index 000000000..99d5bb774 --- /dev/null +++ b/src/badguy/dart.cpp @@ -0,0 +1,101 @@ +// $Id: dart.cpp 3327 2006-04-13 15:02:40Z sommer $ +// +// Dart - Your average poison dart +// Copyright (C) 2006 Christoph Sommer +// +// 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 "dart.hpp" + +namespace { + const float SPEED = 200; +} + +Dart::Dart(const lisp::Lisp& reader) : set_direction(false), parent(0) +{ + reader.get("x", start_position.x); + reader.get("y", start_position.y); + bbox.set_size(9, 1); + sprite = sprite_manager->create("images/creatures/dart/dart.sprite"); + physic.enable_gravity(false); + countMe = false; +} + +Dart::Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent = 0) : set_direction(true), initial_direction(d), parent(parent) +{ + start_position.x = pos_x; + start_position.y = pos_y; + bbox.set_size(9, 1); + sprite = sprite_manager->create("images/creatures/dart/dart.sprite"); + physic.enable_gravity(false); + countMe = false; +} + +void +Dart::write(lisp::Writer& writer) +{ + writer.start_list("dart"); + writer.write_float("x", start_position.x); + writer.write_float("y", start_position.y); + writer.end_list("dart"); +} + +void +Dart::activate() +{ + if (set_direction) dir = initial_direction; + physic.set_velocity_x(dir == LEFT ? -::SPEED : ::SPEED); + sprite->set_action(dir == LEFT ? "flying-left" : "flying-right"); +} + +void +Dart::deactivate() +{ + remove_me(); +} + +HitResponse +Dart::collision_solid(GameObject& , const CollisionHit& ) +{ + remove_me(); + return ABORT_MOVE; +} + +HitResponse +Dart::collision_badguy(BadGuy& badguy, const CollisionHit& ) +{ + // ignore collisions with parent + if (&badguy == parent) { + return FORCE_MOVE; + } + remove_me(); + badguy.kill_fall(); + return ABORT_MOVE; +} + +HitResponse +Dart::collision_player(Player& player, const CollisionHit& hit) +{ + remove_me(); + return BadGuy::collision_player(player, hit); +} + + + +IMPLEMENT_FACTORY(Dart, "dart") + diff --git a/src/badguy/dart.hpp b/src/badguy/dart.hpp new file mode 100644 index 000000000..36f858f9f --- /dev/null +++ b/src/badguy/dart.hpp @@ -0,0 +1,50 @@ +// $Id: dart.hpp 3327 2006-04-13 15:02:40Z sommer $ +// +// Dart - Your average poison dart +// Copyright (C) 2006 Christoph Sommer +// +// 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 __DART_H__ +#define __DART_H__ + +#include "badguy.hpp" + +/** + * Badguy "Dart" - Your average poison dart + */ +class Dart : public BadGuy +{ +public: + Dart(const lisp::Lisp& reader); + Dart(float pos_x, float pos_y, Direction d, const BadGuy* parent); + + void activate(); + void deactivate(); + void write(lisp::Writer& writer); + + HitResponse collision_solid(GameObject& object, const CollisionHit& hit); + HitResponse collision_badguy(BadGuy& badguy, const CollisionHit& hit); + HitResponse collision_player(Player& player, const CollisionHit& hit); + +protected: + bool set_direction; + Direction initial_direction; + const BadGuy* parent; /**< collisions with this BadGuy will be ignored */ +}; + +#endif + diff --git a/src/badguy/darttrap.cpp b/src/badguy/darttrap.cpp new file mode 100644 index 000000000..112837a22 --- /dev/null +++ b/src/badguy/darttrap.cpp @@ -0,0 +1,108 @@ +// $Id: darttrap.cpp 3342 2006-04-14 22:48:51Z sommer $ +// +// DartTrap - Shoots a Dart at regular intervals +// Copyright (C) 2006 Christoph Sommer +// +// 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 "darttrap.hpp" +#include "dart.hpp" + +namespace { + const float MUZZLE_Y = 28; /**< [px] muzzle y-offset from top */ +} + +DartTrap::DartTrap(const lisp::Lisp& reader) : initial_delay(0), fire_delay(2), ammo(-1), state(IDLE) +{ + reader.get("x", start_position.x); + reader.get("y", start_position.y); + reader.get("initial-delay", initial_delay); + reader.get("fire-delay", fire_delay); + reader.get("ammo", ammo); + bbox.set_size(11, 37); + sprite = sprite_manager->create("images/creatures/darttrap/darttrap.sprite"); + countMe = false; +} + +void +DartTrap::write(lisp::Writer& writer) +{ + writer.start_list("darttrap"); + writer.write_float("x", start_position.x); + writer.write_float("y", start_position.y); + writer.write_float("initial-delay", initial_delay); + writer.write_float("fire-delay", fire_delay); + writer.write_int("ammo", ammo); + writer.end_list("darttrap"); +} + +void +DartTrap::activate() +{ + if (set_direction) dir = initial_direction; + state = IDLE; + sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); + + if (initial_delay == 0) initial_delay = 0.1; + fire_timer.start(initial_delay); +} + +HitResponse +DartTrap::collision_player(Player& , const CollisionHit& ) +{ + return ABORT_MOVE; +} + +void +DartTrap::active_update(float ) +{ + if (state == IDLE) { + if ((ammo != 0) && (fire_timer.check())) { + if (ammo > 0) ammo--; + load(); + fire_timer.start(fire_delay); + } + } + if (state == LOADING) { + if (sprite->animation_done()) { + fire(); + } + } +} + +void +DartTrap::load() +{ + state = LOADING; + sprite->set_action(dir == LEFT ? "loading-left" : "loading-right", 1); +} + +void +DartTrap::fire() +{ + float px = get_pos().x; + if (dir == RIGHT) px += 5; + float py = get_pos().y; + py += MUZZLE_Y; + + Sector::current()->add_object(new Dart(px, py, dir, this)); + state = IDLE; + sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); +} + +IMPLEMENT_FACTORY(DartTrap, "darttrap") + diff --git a/src/badguy/darttrap.hpp b/src/badguy/darttrap.hpp new file mode 100644 index 000000000..dce5778be --- /dev/null +++ b/src/badguy/darttrap.hpp @@ -0,0 +1,58 @@ +// $Id: darttrap.hpp 3327 2006-04-13 15:02:40Z sommer $ +// +// DartTrap - Shoots a Dart at regular intervals +// Copyright (C) 2006 Christoph Sommer +// +// 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 __DARTTRAP_H__ +#define __DARTTRAP_H__ + +#include "badguy.hpp" +#include "timer.hpp" + +/** + * Badguy "DartTrap" - Shoots a Dart at regular intervals + */ +class DartTrap : public BadGuy +{ +public: + DartTrap(const lisp::Lisp& reader); + + void activate(); + void write(lisp::Writer& writer); + void active_update(float elapsed_time); + HitResponse collision_player(Player& player, const CollisionHit& hit); + +protected: + enum State { + IDLE, LOADING + }; + + void load(); /**< load a shot */ + void fire(); /**< fire a shot */ + + bool set_direction; + Direction initial_direction; + float initial_delay; /**< time to wait before firing first shot */ + float fire_delay; /**< reload time */ + int ammo; /**< ammo left (-1 means unlimited) */ + + State state; /**< current state */ + Timer fire_timer; /**< time until new shot is fired */ +}; + +#endif +