[Super-tux-commit] supertux/src gameloop.cpp,1.215,1.216 player_status.cpp,1.1,1.2 player_status.h,1
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2005-04-01 12:17:36
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14310/src Modified Files: gameloop.cpp player_status.cpp player_status.h sector.cpp title.cpp worldmap.cpp worldmap.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_status.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player_status.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- player_status.cpp 25 Mar 2005 20:39:52 -0000 1.1 +++ player_status.cpp 1 Apr 2005 12:16:50 -0000 1.2 @@ -69,15 +69,18 @@ PlayerStatus::write(lisp::Writer& writer) { switch(bonus) { - case PlayerStatus::NO_BONUS: + case NO_BONUS: writer.write_string("bonus", "none"); break; - case PlayerStatus::GROWUP_BONUS: + case GROWUP_BONUS: writer.write_string("bonus", "growup"); break; - case PlayerStatus::FLOWER_BONUS: + case FIRE_BONUS: writer.write_string("bonus", "fireflower"); break; + case ICE_BONUS: + writer.write_string("bonus", "iceflower"); + break; default: std::cerr << "Unknown bonus type.\n"; writer.write_string("bonus", "none"); @@ -100,7 +103,9 @@ } else if(bonusname == "growup") { bonus = GROWUP_BONUS; } else if(bonusname == "fireflower") { - bonus = FLOWER_BONUS; + bonus = FIRE_BONUS; + } else if(bonusname == "iceflower") { + bonus = ICE_BONUS; } else { std::cerr << "Unknown bonus '" << bonusname << "' in savefile.\n"; bonus = NO_BONUS; Index: sector.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/sector.cpp,v retrieving revision 1.68 retrieving revision 1.69 diff -u -d -r1.68 -r1.69 --- sector.cpp 30 Mar 2005 01:52:12 -0000 1.68 +++ sector.cpp 1 Apr 2005 12:16:50 -0000 1.69 @@ -56,6 +56,7 @@ #include "badguy/jumpy.h" #include "badguy/spike.h" #include "trigger/sequence_trigger.h" +#include "player_status.h" //#define USE_GRID @@ -66,7 +67,7 @@ currentmusic(LEVEL_MUSIC) { song_title = "Mortimers_chipdisko.mod"; - player = new Player(); + player = new Player(&player_status); add_object(player); grid = new CollisionGrid(32000, 32000); @@ -157,14 +158,15 @@ update_game_objects(); fix_old_tiles(); - update_game_objects(); if(!camera) { std::cerr << "sector '" << name << "' does not contain a camera.\n"; - camera = new Camera(this); - add_object(camera); + update_game_objects(); + add_object(new Camera(this)); } if(!solids) throw std::runtime_error("sector does not contain a solid tile layer."); + + update_game_objects(); } void @@ -417,24 +419,6 @@ { _current = this; - // Apply bonuses from former levels - switch (player_status.bonus) { - case PlayerStatus::NO_BONUS: - break; - - case PlayerStatus::FLOWER_BONUS: - player->got_power = Player::FIRE_POWER; // FIXME: add ice power to here - // fall through - - case PlayerStatus::GROWUP_BONUS: - player->grow(false); - break; - - default: - std::cerr << "Unknown bonus in PlayerStatus?!?\n"; - break; - } - player->move(player_pos); camera->reset(player->get_pos()); } @@ -742,22 +726,19 @@ // TODO remove this function and move these checks elsewhere... static const size_t MAX_FIRE_BULLETS = 2; static const size_t MAX_ICE_BULLETS = 1; - - if(player->got_power == Player::FIRE_POWER) { + + Bullet* new_bullet = 0; + if(player_status.bonus == FIRE_BONUS) { if(bullets.size() > MAX_FIRE_BULLETS-1) return false; - } else if(player->got_power == Player::ICE_POWER) { + new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET); + } else if(player_status.bonus == ICE_BONUS) { if(bullets.size() > MAX_ICE_BULLETS-1) return false; - } - - Bullet* new_bullet = 0; - if(player->got_power == Player::FIRE_POWER) - new_bullet = new Bullet(pos, xm, dir, FIRE_BULLET); - else if(player->got_power == Player::ICE_POWER) new_bullet = new Bullet(pos, xm, dir, ICE_BULLET); - else - throw std::runtime_error("wrong bullet type."); + } else { + return false; + } add_object(new_bullet); SoundManager::get()->play_sound(IDToSound(SND_SHOOT)); Index: title.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/title.cpp,v retrieving revision 1.142 retrieving revision 1.143 diff -u -d -r1.142 -r1.143 --- title.cpp 30 Mar 2005 12:00:56 -0000 1.142 +++ title.cpp 1 Apr 2005 12:16:51 -0000 1.143 @@ -84,8 +84,7 @@ */ void resume_demo() { - // FIXME: shouldn't be needed if GameSession - // didn't relay on global variables + player_status.reset(); titlesession->get_current_sector()->activate("main"); titlesession->set_current(); @@ -261,7 +260,7 @@ // Wrap around at the end of the level back to the beginnig if(world->solids->get_width() * 32 - 320 < tux->get_pos().x) { - tux->level_begin(); + world->activate("main"); world->camera->reset(tux->get_pos()); } Index: worldmap.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.cpp,v retrieving revision 1.141 retrieving revision 1.142 diff -u -d -r1.141 -r1.142 --- worldmap.cpp 30 Mar 2005 12:00:58 -0000 1.141 +++ worldmap.cpp 1 Apr 2005 12:16:51 -0000 1.142 @@ -33,6 +33,7 @@ #include "video/screen.h" #include "video/drawing_context.h" #include "special/frame_rate.h" +#include "special/sprite_manager.h" #include "audio/sound_manager.h" #include "lisp/parser.h" #include "lisp/lisp.h" @@ -110,10 +111,8 @@ Tux::Tux(WorldMap* worldmap_) : worldmap(worldmap_) { - largetux_sprite = new Surface(datadir + "/images/worldmap/tux.png", true); - firetux_sprite = new Surface(datadir + "/images/worldmap/firetux.png", true); - smalltux_sprite = new Surface(datadir + "/images/worldmap/smalltux.png", true); - + tux_sprite = sprite_manager->create("worldmaptux"); + offset = 0; moving = false; tile_pos.x = worldmap->get_start_x(); @@ -124,30 +123,31 @@ Tux::~Tux() { - delete smalltux_sprite; - delete firetux_sprite; - delete largetux_sprite; + delete tux_sprite; } void -Tux::draw(DrawingContext& context, const Vector& offset) +Tux::draw(DrawingContext& context) { - Vector pos = get_pos(); - switch (player_status.bonus) - { - case PlayerStatus::GROWUP_BONUS: - context.draw_surface(largetux_sprite, - Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS); + switch (player_status.bonus) { + case GROWUP_BONUS: + tux_sprite->set_action("large"); break; - case PlayerStatus::FLOWER_BONUS: - context.draw_surface(firetux_sprite, - Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS); + case FIRE_BONUS: + tux_sprite->set_action("fire"); break; - case PlayerStatus::NO_BONUS: - context.draw_surface(smalltux_sprite, - Vector(pos.x + offset.x, pos.y + offset.y - 10), LAYER_OBJECTS); + case NO_BONUS: + tux_sprite->set_action("small"); break; - } + default: +#ifdef DBEUG + std::cerr << "Bonus type not handled in worldmap.\n"; +#endif + tux_sprite->set_action("large"); + break; + } + + tux_sprite->draw(context, get_pos(), LAYER_OBJECTS); } @@ -739,14 +739,6 @@ level->statistics.merge(global_stats); calculate_total_stats(); - if (session.get_current_sector()->player->got_power != - session.get_current_sector()->player->NONE_POWER) - player_status.bonus = PlayerStatus::FLOWER_BONUS; - else if (session.get_current_sector()->player->size == BIG) - player_status.bonus = PlayerStatus::GROWUP_BONUS; - else - player_status.bonus = PlayerStatus::NO_BONUS; - if (old_level_state != level->solved && level->auto_path) { // Try to detect the next direction to which we should walk // FIXME: Mostly a hack @@ -784,7 +776,7 @@ status. But the minimum lives and no bonus. */ player_status.distros = old_player_status.distros; player_status.lives = std::min(old_player_status.lives, player_status.lives); - player_status.bonus = player_status.NO_BONUS; + player_status.bonus = NO_BONUS; break; case GameSession::ES_GAME_OVER: @@ -914,26 +906,24 @@ return 0; } - void -WorldMap::draw(DrawingContext& context, const Vector& offset) +WorldMap::draw(DrawingContext& context) { for(int y = 0; y < height; ++y) for(int x = 0; x < width; ++x) { const Tile* tile = at(Vector(x, y)); - tile->draw(context, Vector(x*32 + offset.x, y*32 + offset.y), - LAYER_TILES); + tile->draw(context, Vector(x*32, y*32), LAYER_TILES); } for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) { if (i->solved) context.draw_surface(leveldot_green, - Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1); + Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1); else context.draw_surface(leveldot_red, - Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1); + Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1); } for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i) @@ -943,20 +933,23 @@ if (i->teleport_dest != Vector(-1, -1)) context.draw_surface(teleporterdot, - Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1); + Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1); else if (!i->map_message.empty() && !i->passive_message) context.draw_surface(messagedot, - Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1); + Vector(i->pos.x*32, i->pos.y*32), LAYER_TILES+1); } - tux->draw(context, offset); + tux->draw(context); draw_status(context); } void WorldMap::draw_status(DrawingContext& context) { + context.push_transform(); + context.set_translation(Vector(0, 0)); + char str[80]; sprintf(str, " %d", total_stats.get_points(SCORE_STAT)); @@ -1026,6 +1019,8 @@ context.draw_text(gold_text, passive_message, Vector(screen->w/2, screen->h - white_text->get_height() - 60), CENTER_ALLIGN, LAYER_FOREGROUND1); + + context.pop_transform(); } void @@ -1066,8 +1061,11 @@ if (offset.x < screen->w - width*32) offset.x = screen->w - width*32; if (offset.y < screen->h - height*32) offset.y = screen->h - height*32; - - draw(context, offset); + + context.push_transform(); + context.set_translation(offset); + draw(context); + context.pop_transform(); get_input(); update(elapsed_time); Index: player_status.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/player_status.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- player_status.h 25 Mar 2005 20:39:52 -0000 1.1 +++ player_status.h 1 Apr 2005 12:16:50 -0000 1.2 @@ -23,6 +23,10 @@ #include "timer.h" #include "serializable.h" +enum BonusType { + NO_BONUS, GROWUP_BONUS, FIRE_BONUS, ICE_BONUS +}; + /** * This class memorizes player status between different game sessions (for * example when switching maps in the worldmap) @@ -40,10 +44,9 @@ int distros; int lives; - enum BonusType { NO_BONUS, GROWUP_BONUS, FLOWER_BONUS }; BonusType bonus; - int score_multiplier; + int score_multiplier; int max_score_multiplier; }; Index: worldmap.h =================================================================== RCS file: /cvsroot/super-tux/supertux/src/worldmap.h,v retrieving revision 1.54 retrieving revision 1.55 diff -u -d -r1.54 -r1.55 --- worldmap.h 5 Dec 2004 16:57:14 -0000 1.54 +++ worldmap.h 1 Apr 2005 12:16:51 -0000 1.55 @@ -32,6 +32,7 @@ namespace SuperTux { class Menu; + class Sprite; } extern Menu* worldmap_menu; @@ -66,9 +67,7 @@ Direction back_direction; private: WorldMap* worldmap; - Surface* largetux_sprite; - Surface* firetux_sprite; - Surface* smalltux_sprite; + Sprite* tux_sprite; Direction input_direction; Direction direction; @@ -83,7 +82,7 @@ Tux(WorldMap* worldmap_); ~Tux(); - void draw(DrawingContext& context, const Vector& offset); + void draw(DrawingContext& context); void action(float elapsed_time); void set_direction(Direction dir); @@ -227,7 +226,7 @@ void update(float delta); /** Draw one frame */ - void draw(DrawingContext& context, const Vector& offset); + void draw(DrawingContext& context); Vector get_next_tile(Vector pos, Direction direction); const Tile* at(Vector pos); Index: gameloop.cpp =================================================================== RCS file: /cvsroot/super-tux/supertux/src/gameloop.cpp,v retrieving revision 1.215 retrieving revision 1.216 diff -u -d -r1.215 -r1.216 --- gameloop.cpp 30 Mar 2005 12:00:53 -0000 1.215 +++ gameloop.cpp 1 Apr 2005 12:16:50 -0000 1.216 @@ -458,17 +458,15 @@ // Cheating words (the goal of this is really for debugging, // but could be used for some cheating, nothing wrong with that) if(compare_last(last_keys, "grow")) { - tux.grow(false); + tux.set_bonus(GROWUP_BONUS, false); last_keys.clear(); } if(compare_last(last_keys, "fire")) { - tux.grow(false); - tux.got_power = tux.FIRE_POWER; + tux.set_bonus(FIRE_BONUS, false); last_keys.clear(); } if(compare_last(last_keys, "ice")) { - tux.grow(false); - tux.got_power = tux.ICE_POWER; + tux.set_bonus(ICE_BONUS, false); last_keys.clear(); } if(compare_last(last_keys, "lifeup")) { @@ -547,8 +545,6 @@ exit_status = ES_LEVEL_FINISHED; return; } else if (!end_sequence && tux->is_dead()) { - player_status.bonus = PlayerStatus::NO_BONUS; - if (player_status.lives < 0) { // No more lives!? exit_status = ES_GAME_OVER; } else { // Still has lives, so reset Tux to the levelstart @@ -571,10 +567,14 @@ // respawning in new sector? if(newsector != "" && newspawnpoint != "") { Sector* sector = level->get_sector(newsector); + if(sector == 0) { + std::cerr << "Sector '" << newsector << "' not found.\n"; + } + sector->activate(newspawnpoint); + sector->play_music(LEVEL_MUSIC); currentsector = sector; - currentsector->activate(newspawnpoint); - currentsector->play_music(LEVEL_MUSIC); - newsector = newspawnpoint = ""; + newsector = ""; + newspawnpoint = ""; } } |