3 // DartTrap - Shoots a Dart at regular intervals
4 // Copyright (C) 2006 Christoph Sommer <supertux@2006.expires.deltadevelopment.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "darttrap.hpp"
26 const float MUZZLE_Y = 28; /**< [px] muzzle y-offset from top */
29 DartTrap::DartTrap(const lisp::Lisp& reader)
30 : BadGuy(reader, "images/creatures/darttrap/darttrap.sprite"), set_direction(true), initial_direction(LEFT), initial_delay(0), fire_delay(2), ammo(-1), state(IDLE)
32 reader.get("initial-delay", initial_delay);
33 reader.get("fire-delay", fire_delay);
34 reader.get("ammo", ammo);
39 DartTrap::write(lisp::Writer& writer)
41 writer.start_list("darttrap");
42 writer.write_float("x", start_position.x);
43 writer.write_float("y", start_position.y);
44 writer.write_float("initial-delay", initial_delay);
45 writer.write_float("fire-delay", fire_delay);
46 writer.write_int("ammo", ammo);
47 writer.end_list("darttrap");
53 if (set_direction) dir = initial_direction;
55 sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
57 if (initial_delay == 0) initial_delay = 0.1;
58 fire_timer.start(initial_delay);
62 DartTrap::collision_player(Player& , const CollisionHit& )
68 DartTrap::active_update(float )
71 if ((ammo != 0) && (fire_timer.check())) {
74 fire_timer.start(fire_delay);
77 if (state == LOADING) {
78 if (sprite->animation_done()) {
88 sprite->set_action(dir == LEFT ? "loading-left" : "loading-right", 1);
94 float px = get_pos().x;
95 if (dir == RIGHT) px += 5;
96 float py = get_pos().y;
99 sound_manager->play("sounds/dartfire.wav", get_pos());
100 Sector::current()->add_object(new Dart(Vector(px, py), dir, this));
102 sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
105 IMPLEMENT_FACTORY(DartTrap, "darttrap")