More -Weffc++ cleanup
[supertux.git] / src / worldmap / sprite_change.cpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
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.
8 //
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.
13 //
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/>.
16 #include <config.h>
17
18 #include "sprite/sprite.hpp"
19 #include "sprite/sprite_manager.hpp"
20 #include "video/drawing_context.hpp"
21 #include "worldmap/sprite_change.hpp"
22
23 namespace WorldMapNS {
24
25 SpriteChange::SpriteChange(const lisp::Lisp* lisp) :
26   pos(),
27   change_on_touch(false), 
28   sprite(),
29   stay_action(),
30   stay_group(),
31   in_stay_action(false)
32 {
33   lisp->get("x", pos.x);
34   lisp->get("y", pos.y);
35   lisp->get("change-on-touch", change_on_touch);
36
37   std::string spritefile = "";
38   lisp->get("sprite", spritefile);
39   sprite = sprite_manager->create(spritefile);
40
41   lisp->get("stay-action", stay_action);
42   lisp->get("initial-stay-action", in_stay_action);
43
44   lisp->get("stay-group", stay_group);
45
46   all_sprite_changes.push_back(this);
47 }
48
49 SpriteChange::~SpriteChange()
50 {
51   all_sprite_changes.remove(this);
52 }
53
54 void
55 SpriteChange::draw(DrawingContext& context)
56 {
57   if(in_stay_action && stay_action != "") {
58     sprite->set_action(stay_action);
59     sprite->draw(context, pos * 32, LAYER_OBJECTS-1);
60   }
61 }
62
63 void
64 SpriteChange::update(float )
65 {
66 }
67
68 void
69 SpriteChange::set_stay_action()
70 {
71   in_stay_action = true;
72 }
73
74 void
75 SpriteChange::clear_stay_action()
76 {
77   in_stay_action = false;
78
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;
85     }
86   }
87 }
88
89 std::list<SpriteChange*> SpriteChange::all_sprite_changes;
90
91 }
92
93 /* EOF */