X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fworldmap.cpp;h=37522927954005eef4b7904c1832e4fbab9ac29a;hb=6a413d912b0d6c012771d3099a598bf3a0f6e59f;hp=59da5f234c9cbb7f5357f94a44bae1fde7b7ed27;hpb=073795dd0afc7d7e4c093db5f83fc26c10501d61;p=supertux.git diff --git a/src/worldmap.cpp b/src/worldmap.cpp index 59da5f234..375229279 100644 --- a/src/worldmap.cpp +++ b/src/worldmap.cpp @@ -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 @@ string_to_direction(const std::string& directory) 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(WorldMap* worldmap_) 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 @@ WorldMap::update(float delta) 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 @@ WorldMap::update(float delta) 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: @@ -801,11 +793,11 @@ WorldMap::update(float delta) LAYER_BACKGROUND0); context.draw_text(blue_text, _("GAMEOVER"), - Vector(screen->w/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1); + Vector(SCREEN_WIDTH/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1); sprintf(str, _("COINS: %d"), player_status.distros); context.draw_text(gold_text, str, - Vector(screen->w/2, screen->w - 32), CENTER_ALLIGN, + Vector(SCREEN_WIDTH/2, SCREEN_WIDTH - 32), CENTER_ALLIGN, LAYER_FOREGROUND1); total_stats.draw_message_info(context, _("Total Statistics")); @@ -914,26 +906,24 @@ WorldMap::at_special_tile() 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 @@ WorldMap::draw(DrawingContext& context, const Vector& offset) 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)); @@ -964,29 +957,29 @@ WorldMap::draw_status(DrawingContext& context) context.draw_text(gold_text, str, Vector(96, 0), LEFT_ALLIGN, LAYER_FOREGROUND1); sprintf(str, "%d", player_status.distros); - context.draw_text(white_text, _("COINS"), Vector(screen->w/2 - 16*5, 0), + context.draw_text(white_text, _("COINS"), Vector(SCREEN_WIDTH/2 - 16*5, 0), LEFT_ALLIGN, LAYER_FOREGROUND1); - context.draw_text(gold_text, str, Vector(screen->w/2 + (16*5)/2, 0), + context.draw_text(gold_text, str, Vector(SCREEN_WIDTH/2 + (16*5)/2, 0), LEFT_ALLIGN, LAYER_FOREGROUND1); if (player_status.lives >= 5) { sprintf(str, "%dx", player_status.lives); context.draw_text(gold_text, str, - Vector(screen->w - gold_text->get_text_width(str) - tux_life->w, 0), + Vector(SCREEN_WIDTH - gold_text->get_text_width(str) - tux_life->w, 0), LEFT_ALLIGN, LAYER_FOREGROUND1); - context.draw_surface(tux_life, Vector(screen->w - + context.draw_surface(tux_life, Vector(SCREEN_WIDTH - gold_text->get_text_width("9"), 0), LEFT_ALLIGN, LAYER_FOREGROUND1); } else { for(int i= 0; i < player_status.lives; ++i) context.draw_surface(tux_life, - Vector(screen->w - tux_life->w*4 + (tux_life->w*i), 0), + Vector(SCREEN_WIDTH - tux_life->w*4 + (tux_life->w*i), 0), LAYER_FOREGROUND1); } context.draw_text(white_text, _("LIVES"), - Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width(" 99"), 0), + Vector(SCREEN_WIDTH - white_text->get_text_width(_("LIVES")) - white_text->get_text_width(" 99"), 0), LEFT_ALLIGN, LAYER_FOREGROUND1); if (!tux->is_moving()) @@ -999,8 +992,8 @@ WorldMap::draw_status(DrawingContext& context) get_level_title(*i); context.draw_text(white_text, i->title, - Vector(screen->w/2, - screen->h - white_text->get_height() - 30), + Vector(SCREEN_WIDTH/2, + SCREEN_HEIGHT - white_text->get_height() - 30), CENTER_ALLIGN, LAYER_FOREGROUND1); i->statistics.draw_worldmap_info(context); @@ -1014,8 +1007,8 @@ WorldMap::draw_status(DrawingContext& context) /* Display an in-map message in the map, if any as been selected */ if(!i->map_message.empty() && !i->passive_message) context.draw_text(gold_text, i->map_message, - Vector(screen->w/2, - screen->h - white_text->get_height() - 60), + Vector(SCREEN_WIDTH/2, + SCREEN_HEIGHT - white_text->get_height() - 60), CENTER_ALLIGN, LAYER_FOREGROUND1); break; } @@ -1024,8 +1017,10 @@ WorldMap::draw_status(DrawingContext& context) /* Display a passive message in the map, if needed */ if(passive_message_timer.check()) context.draw_text(gold_text, passive_message, - Vector(screen->w/2, screen->h - white_text->get_height() - 60), + Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT - white_text->get_height() - 60), CENTER_ALLIGN, LAYER_FOREGROUND1); + + context.pop_transform(); } void @@ -1058,16 +1053,19 @@ WorldMap::display() Vector tux_pos = tux->get_pos(); - offset.x = -tux_pos.x + screen->w/2; - offset.y = -tux_pos.y + screen->h/2; + offset.x = -tux_pos.x + SCREEN_WIDTH/2; + offset.y = -tux_pos.y + SCREEN_HEIGHT/2; if (offset.x > 0) offset.x = 0; if (offset.y > 0) offset.y = 0; - 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); + if (offset.x < SCREEN_WIDTH - width*32) offset.x = SCREEN_WIDTH - width*32; + if (offset.y < SCREEN_HEIGHT - height*32) offset.y = SCREEN_HEIGHT - height*32; + + context.push_transform(); + context.set_translation(-offset); + draw(context); + context.pop_transform(); get_input(); update(elapsed_time);