[Super-tux-commit] supertux/src/object block.cpp,1.10,1.11 coin.cpp,1.6,1.7 flower.cpp,1.3,1.4 growu
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2005-04-01 12:17:03
|
Update of /cvsroot/super-tux/supertux/src/object In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14310/src/object Modified Files: block.cpp coin.cpp flower.cpp growup.cpp oneup.cpp player.cpp player.h Log Message: -Worldmap cleanups (use DrawingContext transformstack) -Refactoring/Cleanup in PlayerStatus handling (no separate handling of PlayerStatus in Player object now) -Reimplemented stalactite badguy -more smaller cleanups Index: player.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/player.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- player.h 25 Mar 2005 20:39:55 -0000 1.3 +++ player.h 1 Apr 2005 12:16:53 -0000 1.4 @@ -28,6 +28,7 @@ #include "special/moving_object.h" #include "special/sprite.h" #include "math/physic.h" +#include "player_status.h" using namespace SuperTux; @@ -42,10 +43,6 @@ #define TUX_FLAPPING_TIME 1 /* How long Tux can flap his wings to gain additional jump height */ #define TIME_WARNING 20 /* When to alert player they're low on time! */ -/* Sizes: */ -#define SMALL 0 -#define BIG 1 - struct PlayerKeymap { public: @@ -126,12 +123,10 @@ { public: enum HurtMode { KILL, SHRINK }; - enum Power { NONE_POWER, FIRE_POWER, ICE_POWER }; enum FallMode { ON_GROUND, JUMPING, TRAMPOLINE_JUMP, FALLING }; PlayerInputType input; - int got_power; - int size; + PlayerStatus* player_status; bool duck; bool dead; @@ -160,7 +155,7 @@ int flaps_nb; // temporary to help player's choosing a flapping - enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NONE_FLAP }; + enum { MAREK_FLAP, RICARDO_FLAP, RYAN_FLAP, NO_FLAP }; int flapping_mode; Timer2 invincible_timer; @@ -175,15 +170,12 @@ Physic physic; public: - Player(); + Player(PlayerStatus* player_status); virtual ~Player(); bool key_event(SDLKey key, bool state); - void level_begin(); void handle_input(); - PlayerStatus& get_status(); - virtual void action(float elapsed_time); virtual void draw(DrawingContext& context); virtual HitResponse collision(GameObject& other, const CollisionHit& hit); @@ -201,13 +193,18 @@ void kill(HurtMode mode); void player_remove_powerups(); void check_bounds(Camera* camera); - void grow(bool animate = false); void move(const Vector& vector); + void set_bonus(BonusType type, bool animate = false); + PlayerStatus* get_status() + { + return player_status; + } void bounce(BadGuy& badguy); bool is_dead() const { return dead; } + bool is_big(); private: bool on_ground(); @@ -216,7 +213,6 @@ void handle_horizontal_input(); void handle_vertical_input(); - void remove_powerups(); Portable* grabbed_object; Index: coin.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/coin.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- coin.cpp 25 Mar 2005 20:39:55 -0000 1.6 +++ coin.cpp 1 Apr 2005 12:16:53 -0000 1.7 @@ -45,7 +45,7 @@ void Coin::collect() { - Sector::current()->player->get_status().incCoins(); + Sector::current()->player->get_status()->incCoins(); Sector::current()->add_object(new BouncyCoin(get_pos())); global_stats.add_points(COINS_COLLECTED_STAT, 1); remove_me(); Index: growup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/growup.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- growup.cpp 25 Mar 2005 20:39:55 -0000 1.3 +++ growup.cpp 1 Apr 2005 12:16:53 -0000 1.4 @@ -45,7 +45,7 @@ Player* player = dynamic_cast<Player*>(&other); if(player != 0) { - player->grow(); + player->set_bonus(GROWUP_BONUS, true); SoundManager::get()->play_sound(IDToSound(SND_EXCELLENT)); remove_me(); Index: player.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/player.cpp,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- player.cpp 30 Mar 2005 01:52:14 -0000 1.5 +++ player.cpp 1 Apr 2005 12:16:53 -0000 1.6 @@ -28,7 +28,6 @@ #include "special/sprite_manager.h" #include "player.h" #include "tile.h" -#include "player_status.h" #include "special/sprite.h" #include "sector.h" #include "resources.h" @@ -125,8 +124,8 @@ feet->draw(context, pos, layer-2, drawing_effect); } -Player::Player() - : grabbed_object(0) +Player::Player(PlayerStatus* _player_status) + : player_status(_player_status), grabbed_object(0) { smalltux_gameover = sprite_manager->create("smalltux-gameover"); smalltux_star = sprite_manager->create("smalltux-star"); @@ -144,10 +143,10 @@ void Player::init() { - bbox.set_size(31.8, 31.8); - - size = SMALL; - got_power = NONE_POWER; + if(is_big()) + bbox.set_size(31.8, 63.8); + else + bbox.set_size(31.8, 31.8); dir = RIGHT; old_dir = dir; @@ -168,7 +167,7 @@ flapping_velocity = 0; // temporary to help player's choosing a flapping - flapping_mode = MAREK_FLAP; + flapping_mode = NO_FLAP; // Ricardo's flapping flaps_nb = 0; @@ -229,27 +228,6 @@ } void -Player::level_begin() -{ - move(Vector(100, 170)); - duck = false; - - dying = false; - - input.reset(); - - on_ground_flag = false; - - physic.reset(); -} - -PlayerStatus& -Player::get_status() -{ - return player_status; -} - -void Player::action(float elapsed_time) { if(dying && dying_timer.check()) { @@ -303,6 +281,15 @@ return on_ground_flag; } +bool +Player::is_big() +{ + if(player_status->bonus == NO_BONUS) + return false; + + return true; +} + void Player::handle_horizontal_input() { @@ -455,10 +442,10 @@ can_jump = false; can_flap = false; flaps_nb = 0; // Ricardo's flapping - if (size == SMALL) - SoundManager::get()->play_sound(IDToSound(SND_JUMP)); - else + if (is_big()) SoundManager::get()->play_sound(IDToSound(SND_BIGJUMP)); + else + SoundManager::get()->play_sound(IDToSound(SND_JUMP)); } // Let go of jump key else if(!input.jump) @@ -576,7 +563,7 @@ butt_jump = false; // Do butt jump - if (butt_jump && on_ground() && size == BIG) + if (butt_jump && on_ground() && is_big()) { // Add a smoke cloud if (duck) @@ -657,7 +644,7 @@ handle_vertical_input(); /* Shoot! */ - if (input.fire && !input.old_fire && got_power != NONE_POWER) { + if (input.fire && !input.old_fire && player_status->bonus == FIRE_BONUS) { if(Sector::current()->add_bullet( // get_pos() + Vector(0, bbox.get_height()/2), get_pos() + ((dir == LEFT)? Vector(0, bbox.get_height()/2) @@ -669,14 +656,14 @@ } /* Duck! */ - if (input.down && size == BIG && !duck + if (input.down && is_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 && size == BIG && duck) + else if(!input.down && is_big() && duck) { // try if we can really unduck bbox.move(Vector(0, -32)); @@ -697,17 +684,19 @@ } void -Player::grow(bool animate) +Player::set_bonus(BonusType type, bool animate) { - if(size == BIG) + if(player_status->bonus == type) return; - size = BIG; - bbox.set_height(63.8); - bbox.move(Vector(0, -32)); - - if(animate) - growing_timer.start(GROWING_TIME); + if(player_status->bonus == NO_BONUS) { + bbox.set_height(63.8); + bbox.move(Vector(0, -32)); + if(animate) + growing_timer.start(GROWING_TIME); + } + + player_status->bonus = type; } void @@ -715,19 +704,19 @@ { TuxBodyParts* tux_body; - if (size == SMALL) - tux_body = small_tux; - else if (got_power == FIRE_POWER) + if (player_status->bonus == GROWUP_BONUS) + tux_body = big_tux; + else if (player_status->bonus == FIRE_BONUS) tux_body = fire_tux; - else if (got_power == ICE_POWER) + else if (player_status->bonus == ICE_BONUS) tux_body = ice_tux; else - tux_body = big_tux; + tux_body = small_tux; int layer = LAYER_OBJECTS + 10; /* Set Tux sprite action */ - if (duck && size == BIG) + if (duck && is_big()) { if(dir == LEFT) tux_body->set_action("duck-left"); @@ -748,7 +737,7 @@ else // dir == RIGHT tux_body->set_action("kick-right"); } - else if (butt_jump && size == BIG) + else if (butt_jump && is_big()) { if(dir == LEFT) tux_body->set_action("buttjump-left"); @@ -782,7 +771,7 @@ if(idle_timer.check()) { - if(size == BIG) + if(is_big()) { if(dir == LEFT) tux_body->head->set_action("idle-left", 1); @@ -816,7 +805,7 @@ if(dying) { smalltux_gameover->draw(context, get_pos(), layer); } else if(growing_timer.get_timeleft() > 0) { - if(size == SMALL) + if(!is_big()) { if (dir == RIGHT) context.draw_surface(growingtux_right[GROWING_FRAMES-1 - @@ -851,7 +840,7 @@ || size_t(global_time*20)%2) && !dying) { - if (size == SMALL || duck) + if (!is_big() || duck) smalltux_star->draw(context, get_pos(), layer + 5); else bigtux_star->draw(context, get_pos(), layer + 5); @@ -920,20 +909,21 @@ physic.set_velocity_x(0); - if (mode == SHRINK && size == BIG) + if (mode == SHRINK && is_big()) { - if (got_power != NONE_POWER) + if (player_status->bonus == FIRE_BONUS + || player_status->bonus == ICE_BONUS) { safe_timer.start(TUX_SAFE_TIME); - got_power = NONE_POWER; + player_status->bonus = GROWUP_BONUS; } - else + else { growing_timer.start(GROWING_TIME); safe_timer.start(TUX_SAFE_TIME + GROWING_TIME); - size = SMALL; bbox.set_height(31.8); duck = false; + player_status->bonus = NO_BONUS; } } else @@ -941,26 +931,26 @@ physic.enable_gravity(true); physic.set_acceleration(0, 0); physic.set_velocity(0, 700); - --player_status.lives; + player_status->lives -= 1; dying = true; dying_timer.start(3.0); flags |= FLAG_NO_COLLDET; } } -/* Remove Tux's power ups */ -void -Player::remove_powerups() -{ - got_power = NONE_POWER; - size = SMALL; - bbox.set_height(31.8); -} - void Player::move(const Vector& vector) { bbox.set_pos(vector); + if(is_big()) + bbox.set_size(31.8, 63.8); + else + bbox.set_size(31.8, 31.8); + on_ground_flag = false; + duck = false; + + input.reset(); + physic.reset(); } void Index: flower.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/flower.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- flower.cpp 25 Mar 2005 20:39:55 -0000 1.3 +++ flower.cpp 1 Apr 2005 12:16:53 -0000 1.4 @@ -45,9 +45,10 @@ return ABORT_MOVE; if(type == FIREFLOWER) - player->got_power = Player::FIRE_POWER; + player->set_bonus(FIRE_BONUS, true); else - player->got_power = Player::ICE_POWER; + player->set_bonus(ICE_BONUS, true); + SoundManager::get()->play_sound(IDToSound(SND_COFFEE)); remove_me(); return ABORT_MOVE; Index: block.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/block.cpp,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- block.cpp 30 Mar 2005 12:01:01 -0000 1.10 +++ block.cpp 1 Apr 2005 12:16:52 -0000 1.11 @@ -100,7 +100,7 @@ : Block(sprite_manager->create("bonusblock")) { bbox.set_pos(pos); - sprite->set_action("default"); + sprite->set_action("normal"); switch(data) { case 1: contents = CONTENT_COIN; break; case 2: contents = CONTENT_FIREGROW; break; @@ -160,11 +160,11 @@ switch(contents) { case CONTENT_COIN: Sector::current()->add_object(new BouncyCoin(get_pos())); - player.get_status().incCoins(); + player.get_status()->incCoins(); break; case CONTENT_FIREGROW: - if(player.size == SMALL) { + if(player.get_status()->bonus == NO_BONUS) { SpecialRiser* riser = new SpecialRiser( new GrowUp(get_pos() + Vector(0, -32))); sector->add_object(riser); @@ -177,7 +177,7 @@ break; case CONTENT_ICEGROW: - if(player.size == SMALL) { + if(player.get_status()->bonus == NO_BONUS) { SpecialRiser* riser = new SpecialRiser( new GrowUp(get_pos() + Vector(0, -32))); sector->add_object(riser); @@ -241,12 +241,12 @@ if(coin_counter > 0) { sector->add_object(new BouncyCoin(get_pos())); coin_counter--; - player.get_status().incCoins(); + player.get_status()->incCoins(); if(coin_counter == 0) sprite->set_action("empty"); start_bounce(); } else if(breakable) { - if(playerhit && player.size == SMALL) { + if(playerhit && !player.is_big()) { start_bounce(); return; } Index: oneup.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/object/oneup.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- oneup.cpp 25 Mar 2005 20:39:55 -0000 1.4 +++ oneup.cpp 1 Apr 2005 12:16:53 -0000 1.5 @@ -41,7 +41,7 @@ { Player* player = dynamic_cast<Player*> (&other); if(player) { - player->get_status().incLives(); + player->get_status()->incLives(); remove_me(); return ABORT_MOVE; } |