00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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