[Super-tux-commit] supertux/src door.cpp,1.3,1.4 door.h,1.3,1.4 resources.cpp,1.39,1.40
Brought to you by:
wkendrick
From: Ricardo C. <rm...@us...> - 2004-06-20 14:50:32
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11203/src Modified Files: door.cpp door.h resources.cpp Log Message: A couple of fixes on Door class: - door images were being stored for each object (IMO door game object, should be putted together with the others. This way, wouldn't be needed to add stuff into resources.cpp directly, but to load_objects_gfx() func); - animation was not working properly (could be added to Sprite one time animations). Index: door.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/door.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- door.cpp 10 Jun 2004 16:03:17 -0000 1.3 +++ door.cpp 20 Jun 2004 14:50:21 -0000 1.4 @@ -25,6 +25,11 @@ #include "sprite.h" #include "sprite_manager.h" #include "screen/drawing_context.h" +#include "globals.h" + +/** data images */ +Sprite* door; +Surface* door_opening[DOOR_OPENING_FRAMES]; Door::Door(LispReader& reader) { @@ -36,9 +41,10 @@ reader.read_string("sector", target_sector); reader.read_string("spawnpoint", target_spawnpoint); - sprite = sprite_manager->load("door"); animation_timer.init(true); door_activated = false; + + animation_timer.init(true); } void @@ -69,13 +75,16 @@ void Door::draw(DrawingContext& context) { - sprite->draw(context, Vector(area.x, area.y), LAYER_TILES); + if(animation_timer.check()) + context.draw_surface(door_opening[(animation_timer.get_gone() * DOOR_OPENING_FRAMES) / + DOOR_OPENING_TIME], Vector(area.x, area.y - (door_opening[0]->h/2)), LAYER_TILES); + else + door->draw(context, Vector(area.x, area.y), LAYER_TILES); //Check if door animation is complete //TODO: Move this out of the "draw" method as this is extremely dirty :) if ((!animation_timer.check()) && (door_activated)) { door_activated = false; - sprite = sprite_manager->load("door"); GameSession::current()->respawn(target_sector, target_spawnpoint); } } @@ -87,9 +96,7 @@ //TODO: Resetting the animation doesn't work correctly // Tux and badguys should stop moving while the door is opening if(type == INTERACTION_ACTIVATE) { - sprite = sprite_manager->load("openingdoor"); - sprite->reset(); - animation_timer.start(ANIM_TIME); + animation_timer.start(DOOR_OPENING_TIME); door_activated = true; } } Index: door.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/door.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- door.h 10 Jun 2004 16:03:17 -0000 1.3 +++ door.h 20 Jun 2004 14:50:21 -0000 1.4 @@ -26,12 +26,16 @@ #include "serializable.h" #include "timer.h" -#define ANIM_TIME 1500 - class Sprite; class LispReader; +/** data images */ +#define DOOR_OPENING_TIME 1500 +#define DOOR_OPENING_FRAMES 8 +extern Sprite* door; +extern Surface* door_opening[DOOR_OPENING_FRAMES]; + class Door : public InteractiveObject, public Serializable { public: @@ -45,7 +49,6 @@ virtual void interaction(InteractionType type); private: - Sprite* sprite; std::string target_sector; std::string target_spawnpoint; Timer animation_timer; //Used for door animation Index: resources.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/resources.cpp,v retrieving revision 1.39 retrieving revision 1.40 diff -u -d -r1.39 -r1.40 --- resources.cpp 8 Jun 2004 17:44:29 -0000 1.39 +++ resources.cpp 20 Jun 2004 14:50:21 -0000 1.40 @@ -27,6 +27,7 @@ #include "sprite_manager.h" #include "sound_manager.h" #include "setup.h" +#include "door.h" Surface* img_waves[3]; Surface* img_water; @@ -194,6 +195,14 @@ /* Objects */ load_object_gfx(); + // load the door object graphics: + door = sprite_manager->load("door"); + for (int i = 0; i < DOOR_OPENING_FRAMES; i++) + { + sprintf(img_name, "%s/images/shared/door-%i.png", datadir.c_str(), i+1); + door_opening[i] = new Surface(img_name, false); + } + /* Distros: */ img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png", USE_ALPHA); @@ -264,6 +273,11 @@ delete growingtux_right[i]; } + // door game object: + + for (int i = 0; i < DOOR_OPENING_FRAMES; i++) + delete door_opening[i]; + for (i = 0; i < NUM_SOUNDS; i++) free_chunk(sounds[i]); |