#include <sprite_change.hpp>
Inherits GameObject.
Public Member Functions | |
SpriteChange (const Reader &lisp) | |
virtual | ~SpriteChange () |
virtual void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
virtual void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
void | set_stay_action () |
Activates the SpriteChange's stay action, if applicable. | |
void | clear_stay_action () |
Deactivates the SpriteChange's stay action, if applicable. | |
Public Attributes | |
Vector | pos |
bool | change_on_touch |
should tuxs sprite change when the tile has been completely entered, or already when the tile was just touched | |
SpritePtr | sprite |
sprite to change tux image to | |
std::string | stay_action |
stay action can be used for objects like boats or cars, if it is != "" then this sprite will be displayed when tux left the tile towards another SpriteChange object. | |
std::string | stay_group |
name of a group in which only one SpriteChange will ever have its stay_action displayed. | |
Private Attributes | |
bool | in_stay_action |
should the stayaction be displayed | |
Static Private Attributes | |
static std::list< SpriteChange * > | all_sprite_changes |
Definition at line 32 of file sprite_change.hpp.
worldmap::SpriteChange::SpriteChange | ( | const Reader & | lisp | ) |
Definition at line 26 of file sprite_change.cpp.
References all_sprite_changes, change_on_touch, SpriteManager::create(), lisp::Lisp::get(), in_stay_action, pos, sprite, sprite_manager, stay_action, stay_group, Vector::x, and Vector::y.
00026 : 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 }
worldmap::SpriteChange::~SpriteChange | ( | ) | [virtual] |
Definition at line 50 of file sprite_change.cpp.
References all_sprite_changes.
00051 { 00052 all_sprite_changes.remove(this); 00053 }
void worldmap::SpriteChange::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Implements GameObject.
Definition at line 56 of file sprite_change.cpp.
References in_stay_action, LAYER_OBJECTS, pos, sprite, and stay_action.
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 }
void worldmap::SpriteChange::update | ( | float | elapsed_time | ) | [virtual] |
This function is called once per frame and allows the object to update it's state.
The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)
Implements GameObject.
Definition at line 65 of file sprite_change.cpp.
void worldmap::SpriteChange::set_stay_action | ( | ) |
Activates the SpriteChange's stay action, if applicable.
Definition at line 70 of file sprite_change.cpp.
References in_stay_action.
Referenced by worldmap::Tux::tryContinueWalking().
00071 { 00072 in_stay_action = true; 00073 }
void worldmap::SpriteChange::clear_stay_action | ( | ) |
Deactivates the SpriteChange's stay action, if applicable.
Definition at line 76 of file sprite_change.cpp.
References all_sprite_changes, in_stay_action, and stay_group.
Referenced by worldmap::Tux::setup(), and worldmap::Tux::tryContinueWalking().
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 }
should tuxs sprite change when the tile has been completely entered, or already when the tile was just touched
Definition at line 56 of file sprite_change.hpp.
Referenced by SpriteChange(), and worldmap::Tux::tryContinueWalking().
sprite to change tux image to
Definition at line 59 of file sprite_change.hpp.
Referenced by draw(), worldmap::Tux::setup(), SpriteChange(), and worldmap::Tux::tryContinueWalking().
std::string worldmap::SpriteChange::stay_action |
stay action can be used for objects like boats or cars, if it is != "" then this sprite will be displayed when tux left the tile towards another SpriteChange object.
Definition at line 64 of file sprite_change.hpp.
Referenced by draw(), and SpriteChange().
std::string worldmap::SpriteChange::stay_group |
name of a group in which only one SpriteChange will ever have its stay_action displayed.
Leave empty if you don't care.
Definition at line 68 of file sprite_change.hpp.
Referenced by clear_stay_action(), and SpriteChange().
bool worldmap::SpriteChange::in_stay_action [private] |
should the stayaction be displayed
Definition at line 72 of file sprite_change.hpp.
Referenced by clear_stay_action(), draw(), set_stay_action(), and SpriteChange().
std::list< SpriteChange * > worldmap::SpriteChange::all_sprite_changes [static, private] |
Definition at line 75 of file sprite_change.hpp.
Referenced by clear_stay_action(), SpriteChange(), and ~SpriteChange().