2 // Copyright (C) 2006 Matthias Braun <matze@braunis.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/>.
18 #include "sprite/sprite.hpp"
19 #include "sprite/sprite_manager.hpp"
20 #include "video/drawing_context.hpp"
21 #include "worldmap/sprite_change.hpp"
23 namespace WorldMapNS {
25 SpriteChange::SpriteChange(const lisp::Lisp* lisp) :
27 change_on_touch(false),
33 lisp->get("x", pos.x);
34 lisp->get("y", pos.y);
35 lisp->get("change-on-touch", change_on_touch);
37 std::string spritefile = "";
38 lisp->get("sprite", spritefile);
39 sprite = sprite_manager->create(spritefile);
41 lisp->get("stay-action", stay_action);
42 lisp->get("initial-stay-action", in_stay_action);
44 lisp->get("stay-group", stay_group);
46 all_sprite_changes.push_back(this);
49 SpriteChange::~SpriteChange()
51 all_sprite_changes.remove(this);
55 SpriteChange::draw(DrawingContext& context)
57 if(in_stay_action && stay_action != "") {
58 sprite->set_action(stay_action);
59 sprite->draw(context, pos * 32, LAYER_OBJECTS-1);
64 SpriteChange::update(float )
69 SpriteChange::set_stay_action()
71 in_stay_action = true;
75 SpriteChange::clear_stay_action()
77 in_stay_action = false;
79 // if we are in a stay_group, also clear all stay actions in this group
80 if (stay_group != "") {
81 for (std::list<SpriteChange*>::iterator i = all_sprite_changes.begin(); i != all_sprite_changes.end(); i++) {
82 SpriteChange* sc = *i;
83 if (sc->stay_group != stay_group) continue;
84 sc->in_stay_action = false;
89 std::list<SpriteChange*> SpriteChange::all_sprite_changes;