src/worldmap/sprite_change.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 #include <config.h>
00017 
00018 #include "sprite/sprite.hpp"
00019 #include "sprite/sprite_manager.hpp"
00020 #include "util/reader.hpp"
00021 #include "video/drawing_context.hpp"
00022 #include "worldmap/sprite_change.hpp"
00023 
00024 namespace worldmap {
00025 
00026 SpriteChange::SpriteChange(const Reader& lisp) :
00027   pos(),
00028   change_on_touch(false), 
00029   sprite(),
00030   stay_action(),
00031   stay_group(),
00032   in_stay_action(false)
00033 {
00034   lisp.get("x", pos.x);
00035   lisp.get("y", pos.y);
00036   lisp.get("change-on-touch", change_on_touch);
00037 
00038   std::string spritefile = "";
00039   lisp.get("sprite", spritefile);
00040   sprite = sprite_manager->create(spritefile);
00041 
00042   lisp.get("stay-action", stay_action);
00043   lisp.get("initial-stay-action", in_stay_action);
00044 
00045   lisp.get("stay-group", stay_group);
00046 
00047   all_sprite_changes.push_back(this);
00048 }
00049 
00050 SpriteChange::~SpriteChange()
00051 {
00052   all_sprite_changes.remove(this);
00053 }
00054 
00055 void
00056 SpriteChange::draw(DrawingContext& context)
00057 {
00058   if(in_stay_action && stay_action != "") {
00059     sprite->set_action(stay_action);
00060     sprite->draw(context, pos * 32, LAYER_OBJECTS-1);
00061   }
00062 }
00063 
00064 void
00065 SpriteChange::update(float )
00066 {
00067 }
00068 
00069 void
00070 SpriteChange::set_stay_action()
00071 {
00072   in_stay_action = true;
00073 }
00074 
00075 void
00076 SpriteChange::clear_stay_action()
00077 {
00078   in_stay_action = false;
00079 
00080   // if we are in a stay_group, also clear all stay actions in this group
00081   if (stay_group != "") {
00082     for (std::list<SpriteChange*>::iterator i = all_sprite_changes.begin(); i != all_sprite_changes.end(); i++) {
00083       SpriteChange* sc = *i;
00084       if (sc->stay_group != stay_group) continue;
00085       sc->in_stay_action = false;
00086     }
00087   }
00088 }
00089 
00090 std::list<SpriteChange*> SpriteChange::all_sprite_changes;
00091 
00092 }
00093 
00094 /* EOF */

Generated on Mon Jun 9 03:38:24 2014 for SuperTux by  doxygen 1.5.1