X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Ftrigger%2Fswitch.cpp;h=df292421ba71fb61bfb12411398d48c1f5f3a2fc;hb=dfaf28adf2756d68091c7e54ab16fcb174dfcc5c;hp=8b20a7349c7f7f6878c6834a3a637c988f386647;hpb=8eb7e8d524a32345a31dc9d4d691b3e791e569ff;p=supertux.git diff --git a/src/trigger/switch.cpp b/src/trigger/switch.cpp index 8b20a7349..df292421b 100644 --- a/src/trigger/switch.cpp +++ b/src/trigger/switch.cpp @@ -1,12 +1,10 @@ -// $Id$ -// // SuperTux - Switch Trigger // 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,50 +12,42 @@ // 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 -#include "switch.hpp" -#include "object_factory.hpp" +#include "audio/sound_manager.hpp" #include "sprite/sprite.hpp" #include "sprite/sprite_manager.hpp" -#include "sector.hpp" -#include "audio/sound_manager.hpp" +#include "supertux/object_factory.hpp" +#include "supertux/sector.hpp" +#include "trigger/switch.hpp" + +#include namespace { - const std::string SWITCH_SOUND = "sounds/switch.ogg"; +const std::string SWITCH_SOUND = "sounds/switch.ogg"; } -Switch::Switch(const lisp::Lisp& reader) - : state(OFF) +Switch::Switch(const Reader& reader) : + sprite_name(), + sprite(), + script(), + state(OFF) { if (!reader.get("x", bbox.p1.x)) throw std::runtime_error("no x position set"); if (!reader.get("y", bbox.p1.y)) throw std::runtime_error("no y position set"); if (!reader.get("sprite", sprite_name)) throw std::runtime_error("no sprite name set"); - sprite = sprite_manager->create(sprite_name); + sprite = SpriteManager::current()->create(sprite_name); bbox.set_size(sprite->get_current_hitbox_width(), sprite->get_current_hitbox_height()); if (!reader.get("script", script)) throw std::runtime_error("no script set"); - sound_manager->preload( SWITCH_SOUND ); + SoundManager::current()->preload( SWITCH_SOUND ); } Switch::~Switch() { - delete sprite; -} - -void -Switch::write(lisp::Writer& writer) -{ - writer.start_list("switch"); - writer.write_float("x", bbox.p1.x); - writer.write_float("y", bbox.p1.y); - writer.write_string("sprite", sprite_name); - writer.write_string("script", script); - writer.end_list("switch"); } void @@ -68,23 +58,25 @@ Switch::update(float ) break; case TURN_ON: if(sprite->animation_done()) { - std::istringstream stream(script); - Sector::current()->run_script(stream, "Switch"); + std::istringstream stream(script); + std::ostringstream location; + location << "switch" << bbox.p1; + Sector::current()->run_script(stream, location.str()); - sprite->set_action("on", 1); - state = ON; + sprite->set_action("on", 1); + state = ON; } break; case ON: if(sprite->animation_done()) { - sprite->set_action("turnoff", 1); - state = TURN_OFF; + sprite->set_action("turnoff", 1); + state = TURN_OFF; } break; case TURN_OFF: if(sprite->animation_done()) { - sprite->set_action("off"); - state = OFF; + sprite->set_action("off"); + state = OFF; } break; } @@ -103,9 +95,9 @@ Switch::event(Player& , EventType type) switch (state) { case OFF: - sprite->set_action("turnon", 1); - sound_manager->play( SWITCH_SOUND ); - state = TURN_ON; + sprite->set_action("turnon", 1); + SoundManager::current()->play( SWITCH_SOUND ); + state = TURN_ON; break; case TURN_ON: break; @@ -117,4 +109,4 @@ Switch::event(Player& , EventType type) } -IMPLEMENT_FACTORY(Switch, "switch"); +/* EOF */