1 // DartTrap - Shoots a Dart at regular intervals
2 // Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "badguy/dart.hpp"
18 #include "badguy/darttrap.hpp"
20 #include "audio/sound_manager.hpp"
21 #include "sprite/sprite.hpp"
22 #include "supertux/object_factory.hpp"
23 #include "supertux/sector.hpp"
24 #include "util/reader.hpp"
27 const float MUZZLE_Y = 25; /**< [px] muzzle y-offset from top */
30 DartTrap::DartTrap(const Reader& reader) :
31 BadGuy(reader, "images/creatures/darttrap/darttrap.sprite", LAYER_TILES-1),
38 reader.get("initial-delay", initial_delay);
39 reader.get("fire-delay", fire_delay);
40 reader.get("ammo", ammo);
42 sound_manager->preload("sounds/dartfire.wav");
43 if (start_dir == AUTO) log_warning << "Setting a DartTrap's direction to AUTO is no good idea" << std::endl;
45 set_colgroup_active(COLGROUP_DISABLED);
46 if (initial_delay == 0) initial_delay = 0.1f;
50 DartTrap::initialize()
52 sprite->set_action(dir == LEFT ? "idle-left" : "idle-right");
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");