X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fbadguy%2Fdarttrap.cpp;h=3885cb684b94dc65c0dbfc932f364c2c7ec7cf2e;hb=1ca7a41254b95a52083b63496b8a18048ee55253;hp=ad1ea9570829d41037466256395cfe5b959cfb4a;hpb=b51a3e05e9212c00c3bf7d00c6c2bf33fe8e2970;p=supertux.git diff --git a/src/badguy/darttrap.cpp b/src/badguy/darttrap.cpp index ad1ea9570..3885cb684 100644 --- a/src/badguy/darttrap.cpp +++ b/src/badguy/darttrap.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // DartTrap - Shoots a Dart at regular intervals -// Copyright (C) 2006 Christoph Sommer +// 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 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 3 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 @@ -14,54 +12,53 @@ // 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. +// along with this program. If not, see . -#include +#include "badguy/dart.hpp" +#include "badguy/darttrap.hpp" -#include "darttrap.hpp" -#include "dart.hpp" +#include "audio/sound_manager.hpp" +#include "sprite/sprite.hpp" +#include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" +#include "util/reader.hpp" namespace { - const float MUZZLE_Y = 28; /**< [px] muzzle y-offset from top */ +const float MUZZLE_Y = 25; /**< [px] muzzle y-offset from top */ } -DartTrap::DartTrap(const lisp::Lisp& reader) : set_direction(true), initial_direction(LEFT), initial_delay(0), fire_delay(2), ammo(-1), state(IDLE) +DartTrap::DartTrap(const Reader& reader) : + BadGuy(reader, "images/creatures/darttrap/darttrap.sprite", LAYER_TILES-1), + initial_delay(0), + fire_delay(2), + ammo(-1), + state(IDLE), + fire_timer() { - 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); - sprite = sprite_manager->create("images/creatures/darttrap/darttrap.sprite"); - bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); countMe = false; + SoundManager::current()->preload("sounds/dartfire.wav"); + if (start_dir == AUTO) { log_warning << "Setting a DartTrap's direction to AUTO is no good idea" << std::endl; } + state = IDLE; + set_colgroup_active(COLGROUP_DISABLED); + if (initial_delay == 0) initial_delay = 0.1f; } void -DartTrap::write(lisp::Writer& writer) +DartTrap::initialize() { - 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"); + sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); } 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 +HitResponse DartTrap::collision_player(Player& , const CollisionHit& ) { return ABORT_MOVE; @@ -99,11 +96,10 @@ DartTrap::fire() float py = get_pos().y; py += MUZZLE_Y; - sound_manager->play("sounds/squish.wav", get_pos()); - Sector::current()->add_object(new Dart(px, py, dir, this)); + SoundManager::current()->play("sounds/dartfire.wav", get_pos()); + Sector::current()->add_object(new Dart(Vector(px, py), dir, this)); state = IDLE; sprite->set_action(dir == LEFT ? "idle-left" : "idle-right"); } -IMPLEMENT_FACTORY(DartTrap, "darttrap") - +/* EOF */