[Super-tux-commit] supertux/src/object background.h,1.2,1.3 block.cpp,1.8,1.9 bullet.cpp,1.1,1.2 cam
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2005-03-25 20:40:12
|
Update of /cvsroot/super-tux/supertux/src/object In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9911/src/object Modified Files: background.h block.cpp bullet.cpp camera.cpp camera.h coin.cpp flower.cpp gameobjs.h growup.cpp oneup.cpp player.cpp player.h specialriser.cpp star.cpp tilemap.cpp tilemap.h Log Message: Had a bit of time today and worked on supertux: - Commited some old changes I had lying around here (improved mrtree images? and improvement to the collision grid which still isn't enabled by default) - Did a bit more cleanups (eleminated defines.h and renamed scene.* to player_status.* as that is waht ti really contained) - Cleaned up PlayerStatus code a bit (refactored loading/saving out of worldmap into PlayerStatus) - Implemented LevelTransformer interface and did a first test with a flip level transformer - Removed explicit LevelEndSequence attribute (can be done by placing aprorpiate SequenceTrigger objects) Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/player.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- player.h 19 Dec 2004 13:34:12 -0000 1.2 +++ player.h 25 Mar 2005 20:39:55 -0000 1.3 @@ -20,14 +20,14 @@ #define SUPERTUX_PLAYER_H #include <vector> -#include "SDL.h" +#include <SDL.h> #include "timer.h" +#include "direction.h" #include "video/surface.h" #include "special/moving_object.h" #include "special/sprite.h" #include "math/physic.h" -#include "defines.h" using namespace SuperTux; @@ -61,28 +61,33 @@ extern PlayerKeymap keymap; -struct player_input_type +/** Contains a field of booleans that indicate wheter a button is pressed or + * released. The old_ fields contain the state of the button at the previous + * frame. + */ +struct PlayerInputType { - int right; - int left; - int up; - int old_up; - int down; - int fire; - int old_fire; - int activate; - int jump; - int old_jump; -}; +public: + PlayerInputType(); + void reset(); -void player_input_init(player_input_type* pplayer_input); + bool left; + bool right; + bool up; + bool old_up; + bool down; + bool fire; + bool old_fire; + bool activate; + bool jump; + bool old_jump; +}; class Camera; class PlayerStatus; extern Surface* tux_life; - #define GROWING_TIME 1.0 #define GROWING_FRAMES 7 extern Surface* growingtux_left[GROWING_FRAMES]; @@ -124,12 +129,15 @@ enum Power { NONE_POWER, FIRE_POWER, ICE_POWER }; enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING }; - player_input_type input; + PlayerInputType input; int got_power; int size; bool duck; bool dead; - DyingType dying; + +private: + bool dying; +public: Direction dir; Direction old_dir; @@ -170,7 +178,7 @@ Player(); virtual ~Player(); - int key_event(SDLKey key, int state); + bool key_event(SDLKey key, bool state); void level_begin(); void handle_input(); @@ -183,7 +191,11 @@ void make_invincible(); bool is_invincible() const { - return invincible_timer.started(); + return invincible_timer.started(); + } + bool is_dying() const + { + return dying; } void kill(HurtMode mode); Index: coin.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/coin.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- coin.cpp 20 Dec 2004 21:24:27 -0000 1.5 +++ coin.cpp 25 Mar 2005 20:39:55 -0000 1.6 @@ -6,7 +6,7 @@ #include "special/sprite_manager.h" #include "player.h" #include "sector.h" -#include "scene.h" +#include "player_status.h" #include "gameobjs.h" #include "statistics.h" #include "object_factory.h" Index: specialriser.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/specialriser.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- specialriser.cpp 20 Nov 2004 22:14:40 -0000 1.1 +++ specialriser.cpp 25 Mar 2005 20:39:55 -0000 1.2 @@ -2,7 +2,6 @@ #include <math.h> #include "specialriser.h" -#include "defines.h" #include "resources.h" #include "camera.h" #include "sector.h" Index: growup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/growup.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- growup.cpp 24 Nov 2004 14:10:27 -0000 1.2 +++ growup.cpp 25 Mar 2005 20:39:55 -0000 1.3 @@ -2,7 +2,6 @@ #include <math.h> #include "growup.h" -#include "defines.h" #include "resources.h" #include "camera.h" #include "sector.h" Index: tilemap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/tilemap.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- tilemap.cpp 20 Dec 2004 21:24:28 -0000 1.4 +++ tilemap.cpp 25 Mar 2005 20:39:55 -0000 1.5 @@ -37,7 +37,7 @@ TileMap::TileMap() : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), - vertical_flip(false) + drawing_effect(0) { tilemanager = tile_manager; @@ -47,7 +47,7 @@ TileMap::TileMap(const lisp::Lisp& reader) : solid(false), speed(1), width(0), height(0), layer(LAYER_TILES), - vertical_flip(false) + drawing_effect(0) { tilemanager = tile_manager; @@ -87,7 +87,7 @@ TileMap::TileMap(int layer_, bool solid_, size_t width_, size_t height_) : solid(solid_), speed(1), width(0), height(0), layer(layer_), - vertical_flip(false) + drawing_effect(0) { tilemanager = tile_manager; @@ -136,8 +136,8 @@ { context.push_transform(); - if(vertical_flip) - context.set_drawing_effect(VERTICAL_FLIP); + if(drawing_effect != 0) + context.set_drawing_effect(drawing_effect); float trans_x = roundf(context.get_translation().x); float trans_y = roundf(context.get_translation().y); context.set_translation(Vector(trans_x * speed, trans_y * speed)); @@ -234,19 +234,6 @@ width = new_width; } -void -TileMap::do_vertical_flip() -{ - // remap tiles vertically flipped - for(int y = 0; y < height / 2; ++y) { - for(int x = 0; x < width; ++x) { - std::swap(tiles[y*width + x], tiles[(((height-1)*width) - (y*width)) + x]); - } - } - - vertical_flip = true; -} - const Tile* TileMap::get_tile(int x, int y) const { Index: flower.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/flower.cpp,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- flower.cpp 23 Nov 2004 16:47:26 -0000 1.2 +++ flower.cpp 25 Mar 2005 20:39:55 -0000 1.3 @@ -2,7 +2,6 @@ #include <math.h> #include "flower.h" -#include "defines.h" #include "resources.h" #include "camera.h" #include "sector.h" Index: block.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/block.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- block.cpp 20 Dec 2004 21:24:27 -0000 1.8 +++ block.cpp 25 Mar 2005 20:39:55 -0000 1.9 @@ -13,6 +13,7 @@ #include "flower.h" #include "oneup.h" #include "star.h" +#include "player_status.h" #include "badguy/badguy.h" #include "coin.h" #include "object_factory.h" @@ -25,7 +26,7 @@ : sprite(newsprite), bouncing(false), bounce_dir(0), bounce_offset(0) { bbox.set_pos(pos); - bbox.set_size(32, 32); + bbox.set_size(32, 32.1); flags |= FLAG_SOLID; original_y = pos.y; } @@ -88,6 +89,7 @@ void Block::start_bounce() { + original_y = bbox.p1.y; bouncing = true; bounce_dir = -BOUNCY_BRICK_SPEED; bounce_offset = 0; Index: gameobjs.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/gameobjs.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- gameobjs.h 28 Nov 2004 14:56:51 -0000 1.2 +++ gameobjs.h 25 Mar 2005 20:39:55 -0000 1.3 @@ -23,7 +23,6 @@ #include "video/surface.h" #include "timer.h" -#include "scene.h" #include "math/physic.h" #include "special/game_object.h" #include "special/moving_object.h" Index: tilemap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/tilemap.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- tilemap.h 28 Nov 2004 14:56:52 -0000 1.2 +++ tilemap.h 25 Mar 2005 20:39:56 -0000 1.3 @@ -61,10 +61,6 @@ */ void resize(int newwidth, int newheight); - /** Flip the all tile map vertically. The purpose of this is to let - player to play the same level in a different way :) */ - void do_vertical_flip(); - size_t get_width() const { return width; } @@ -86,6 +82,16 @@ void change_at(const Vector& pos, uint32_t newtile); + TileManager* get_tilemanager() const + { + return tilemanager; + } + + void set_drawing_effect(int effect) + { + drawing_effect = effect; + } + private: std::vector<uint32_t> tiles; @@ -96,7 +102,7 @@ int width, height; int layer; - bool vertical_flip; + int drawing_effect; }; #endif /*SUPERTUX_TILEMAP_H*/ Index: oneup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/oneup.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- oneup.cpp 29 Nov 2004 16:03:33 -0000 1.3 +++ oneup.cpp 25 Mar 2005 20:39:55 -0000 1.4 @@ -3,7 +3,7 @@ #include "oneup.h" #include "resources.h" #include "player.h" -#include "scene.h" +#include "player_status.h" #include "sector.h" #include "special/sprite_manager.h" #include "video/drawing_context.h" Index: camera.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/camera.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- camera.h 28 Nov 2004 14:56:51 -0000 1.2 +++ camera.h 25 Mar 2005 20:39:55 -0000 1.3 @@ -23,7 +23,6 @@ #include <vector> #include <cassert> -#include "defines.h" #include "math/vector.h" #include "special/game_object.h" #include "video/drawing_context.h" Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/player.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- player.cpp 19 Dec 2004 13:34:12 -0000 1.3 +++ player.cpp 25 Mar 2005 20:39:55 -0000 1.4 @@ -27,9 +27,8 @@ #include "app/gettext.h" #include "special/sprite_manager.h" #include "player.h" -#include "defines.h" -#include "scene.h" #include "tile.h" +#include "player_status.h" #include "special/sprite.h" #include "sector.h" #include "resources.h" @@ -79,18 +78,24 @@ keymap.jump = SDLK_SPACE; } -void player_input_init(player_input_type* pplayer_input) +PlayerInputType::PlayerInputType() { - pplayer_input->up = UP; - pplayer_input->old_up = UP; - pplayer_input->down = UP; - pplayer_input->fire = UP; - pplayer_input->left = UP; - pplayer_input->old_fire = UP; - pplayer_input->right = UP; - pplayer_input->jump = UP; - pplayer_input->old_jump = UP; - pplayer_input->activate = UP; + reset(); +} + +void +PlayerInputType::reset() +{ + up = false; + old_up = false; + down = false; + fire = false; + old_fire = false; + left = false; + right = false; + jump = false; + old_jump = false; + activate = false; } void @@ -149,7 +154,7 @@ duck = false; dead = false; - dying = DYING_NOT; + dying = false; last_ground_y = 0; fall_mode = ON_GROUND; jumping = false; @@ -171,13 +176,12 @@ on_ground_flag = false; grabbed_object = 0; - player_input_init(&input); - + input.reset(); physic.reset(); } -int -Player::key_event(SDLKey key, int state) +bool +Player::key_event(SDLKey key, bool state) { idle_timer.start(IDLE_TIME, true); @@ -193,8 +197,8 @@ } else if(key == keymap.up) { - if(state == UP) - input.old_up = UP; + if(state == false) + input.old_up = false; input.up = state; /* Up key also opens activates stuff */ input.activate = state; @@ -207,16 +211,16 @@ } else if(key == keymap.power) { - if (state == UP) - input.old_fire = UP; + if(state == false) + input.old_fire = false; input.fire = state; return true; } else if(key == keymap.jump) { - if (state == UP) - input.old_jump = UP; + if(state == false) + input.old_jump = false; input.jump = state; return true; } @@ -230,9 +234,9 @@ move(Vector(100, 170)); duck = false; - dying = DYING_NOT; + dying = false; - player_input_init(&input); + input.reset(); on_ground_flag = false; @@ -253,11 +257,11 @@ return; } - if(input.fire == UP) + if(input.fire == false) grabbed_object = 0; - if(dying == DYING_NOT) + if(!dying) handle_input(); movement = physic.get_movement(elapsed_time); @@ -296,36 +300,38 @@ float ay = physic.get_acceleration_y(); float dirsign = 0; - if(input.left == DOWN && input.right == UP && (!duck || physic.get_velocity_y() != 0)) { + if(!duck || physic.get_velocity_y() != 0) { + if(input.left && !input.right) { old_dir = dir; dir = LEFT; dirsign = -1; - } else if(input.left == UP && input.right == DOWN && (!duck || physic.get_velocity_y() != 0)) { + } else if(!input.left && input.right) { old_dir = dir; dir = RIGHT; dirsign = 1; + } } - if (input.fire == UP) { - ax = dirsign * WALK_ACCELERATION_X; - // limit speed - if(vx >= MAX_WALK_XM && dirsign > 0) { - vx = MAX_WALK_XM; - ax = 0; - } else if(vx <= -MAX_WALK_XM && dirsign < 0) { - vx = -MAX_WALK_XM; - ax = 0; - } + if (!input.fire) { + ax = dirsign * WALK_ACCELERATION_X; + // limit speed + if(vx >= MAX_WALK_XM && dirsign > 0) { + vx = MAX_WALK_XM; + ax = 0; + } else if(vx <= -MAX_WALK_XM && dirsign < 0) { + vx = -MAX_WALK_XM; + ax = 0; + } } else { - ax = dirsign * RUN_ACCELERATION_X; - // limit speed - if(vx >= MAX_RUN_XM && dirsign > 0) { - vx = MAX_RUN_XM; - ax = 0; - } else if(vx <= -MAX_RUN_XM && dirsign < 0) { - vx = -MAX_RUN_XM; - ax = 0; - } + ax = dirsign * RUN_ACCELERATION_X; + // limit speed + if(vx >= MAX_RUN_XM && dirsign > 0) { + vx = MAX_RUN_XM; + ax = 0; + } else if(vx <= -MAX_RUN_XM && dirsign < 0) { + vx = -MAX_RUN_XM; + ax = 0; + } } // we can reach WALK_SPEED without any acceleration @@ -419,7 +425,7 @@ } // Press jump key - if(input.jump == DOWN && can_jump && on_ground()) + if(input.jump && can_jump && on_ground()) { if(duck) { // only jump a little bit when in duck mode { physic.set_velocity_y(300); @@ -443,7 +449,7 @@ SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP)); } // Let go of jump key - else if(input.jump == UP) + else if(!input.jump) { if (!flapping && !duck && !falling_from_flap && !on_ground()) { @@ -461,8 +467,7 @@ { // Flapping, Ricardo's version // similar to SM3 Fox - if(input.jump == DOWN && input.old_jump == UP && can_flap && - flaps_nb < 3) + if(input.jump && !input.old_jump && can_flap && flaps_nb < 3) { physic.set_velocity_y(350); physic.set_velocity_x(physic.get_velocity_x() * 35); @@ -472,7 +477,7 @@ else if(flapping_mode == MAREK_FLAP) { // Flapping, Marek's version - if (input.jump == DOWN && can_flap) + if (input.jump && can_flap) { if (!flapping_timer.started()) { @@ -504,7 +509,7 @@ else if(flapping_mode == RYAN_FLAP) { // Flapping, Ryan's version - if (input.jump == DOWN && can_flap) + if (input.jump && can_flap) { if (!flapping_timer.started()) { @@ -549,13 +554,13 @@ #if 0 /* In case the player has pressed Down while in a certain range of air, enable butt jump action */ - if (input.down == DOWN && !butt_jump && !duck) + if (input.down && !butt_jump && !duck) if(tiles_on_air(TILES_FOR_BUTTJUMP) && jumping) butt_jump = true; #endif /* When Down is not held anymore, disable butt jump */ - if(butt_jump && input.down == UP) + if(butt_jump && !input.down) butt_jump = false; // Do butt jump @@ -617,13 +622,14 @@ get_pos().y + bbox.get_height() + 64)) && jumping == false && can_jump == false - && input.jump == DOWN - && input.old_jump == UP) + && input.jump && !input.old_jump) { can_jump = true; } #endif + // FIXME: why the heck is this here and not somewhere where the keys are + // checked?!? input.old_jump = input.jump; } @@ -634,30 +640,31 @@ handle_horizontal_input(); /* Jump/jumping? */ - if (on_ground() && input.jump == UP) + if (on_ground() && !input.jump) can_jump = true; handle_vertical_input(); /* Shoot! */ - if (input.fire == DOWN && input.old_fire == UP && got_power != NONE_POWER) { + if (input.fire && !input.old_fire && got_power != NONE_POWER) { if(Sector::current()->add_bullet( // get_pos() + Vector(0, bbox.get_height()/2), get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2) : Vector(32, bbox.get_height()/2)), physic.get_velocity_x(), dir)) shooting_timer.start(SHOOTING_TIME); - input.old_fire = DOWN; + // FIXME: why the heck is this here + input.old_fire = false; } /* Duck! */ - if (input.down == DOWN && size == BIG && !duck + if (input.down && size == BIG && !duck && physic.get_velocity_y() == 0 && on_ground()) { duck = true; bbox.move(Vector(0, 32)); bbox.set_height(31.8); } - else if(input.down == UP && size == BIG && duck) + else if(!input.down && size == BIG && duck) { // try if we can really unduck bbox.move(Vector(0, -32)); @@ -794,8 +801,8 @@ } /* Draw Tux */ - if (dying == DYING_SQUISHED) { - smalltux_gameover->draw(context, get_pos(), LAYER_FOREGROUNDTILES+1); + if(dying) { + smalltux_gameover->draw(context, get_pos(), layer); } else if(growing_timer.get_timeleft() > 0) { if(size == SMALL) { @@ -848,7 +855,7 @@ Player::collision(GameObject& other, const CollisionHit& hit) { Portable* portable = dynamic_cast<Portable*> (&other); - if(portable && grabbed_object == 0 && input.fire == DOWN + if(portable && grabbed_object == 0 && input.fire && fabsf(hit.normal.x) > .9) { grabbed_object = portable; return CONTINUE; @@ -872,7 +879,7 @@ TriggerBase* trigger = dynamic_cast<TriggerBase*> (&other); if(trigger) { - if(input.up == DOWN && input.old_up == UP) + if(input.up && !input.old_up) trigger->event(*this, TriggerBase::EVENT_ACTIVATE); } @@ -923,7 +930,7 @@ physic.set_acceleration(0, 0); physic.set_velocity(0, 700); --player_status.lives; - dying = DYING_SQUISHED; + dying = true; dying_timer.start(3.0); flags |= FLAG_NO_COLLDET; } Index: star.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/star.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- star.cpp 20 Nov 2004 22:14:40 -0000 1.1 +++ star.cpp 25 Mar 2005 20:39:55 -0000 1.2 @@ -3,7 +3,7 @@ #include "star.h" #include "resources.h" #include "player.h" -#include "scene.h" +#include "player_status.h" #include "special/sprite_manager.h" #include "video/drawing_context.h" Index: camera.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/camera.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- camera.cpp 20 Dec 2004 21:24:27 -0000 1.4 +++ camera.cpp 25 Mar 2005 20:39:55 -0000 1.5 @@ -178,7 +178,7 @@ /****** Vertical Scrolling part ******/ bool do_y_scrolling = true; - if(player->dying || sector->solids->get_height() == 19) + if(player->is_dying() || sector->solids->get_height() == 19) do_y_scrolling = false; if(do_y_scrolling) { @@ -260,7 +260,7 @@ { Player* player = sector->player; - if(player->dying) + if(player->is_dying()) return; if(auto_t - elapsed_time >= 0) { Index: bullet.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/bullet.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- bullet.cpp 20 Nov 2004 22:14:40 -0000 1.1 +++ bullet.cpp 25 Mar 2005 20:39:55 -0000 1.2 @@ -2,7 +2,6 @@ #include <math.h> #include "bullet.h" -#include "defines.h" #include "resources.h" #include "camera.h" #include "sector.h" Index: background.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/background.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- background.h 28 Nov 2004 14:56:51 -0000 1.2 +++ background.h 25 Mar 2005 20:39:55 -0000 1.3 @@ -25,6 +25,8 @@ #include "special/game_object.h" #include "serializable.h" +using namespace SuperTux; + class DisplayManager; namespace lisp { |