X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fresources.cpp;h=1969242816d0380bc202021242b22e831f3d036e;hb=c0093d25093395cb62fc2526ab42be65a9f015b8;hp=ac23078d4d20deba7f9afa78dc279aa5f938c9b5;hpb=8b667c97ef73b811b75727febeeb6c7cc8c5ceec;p=supertux.git diff --git a/src/resources.cpp b/src/resources.cpp index ac23078d4..196924281 100644 --- a/src/resources.cpp +++ b/src/resources.cpp @@ -20,63 +20,22 @@ #include #include "app/globals.h" -#include "special/sprite_manager.h" +#include "sprite/sprite_manager.h" #include "app/setup.h" #include "gui/menu.h" #include "gui/button.h" -#include "scene.h" -#include "player.h" -#include "gameobjs.h" #include "resources.h" - -Surface* img_waves[3]; -Surface* img_water; -Surface* img_pole; -Surface* img_poletop; -Surface* img_flag[2]; -Surface* img_cloud[2][4]; -Surface* img_distro[4]; - -Menu* main_menu = 0; -Menu* game_menu = 0; -Menu* options_menu = 0; -Menu* options_keys_menu = 0; -Menu* options_joystick_menu = 0; -Menu* highscore_menu = 0; -Menu* load_game_menu = 0; -Menu* save_game_menu = 0; -Menu* contrib_menu = 0; -Menu* contrib_subset_menu = 0; +#include "tile_manager.h" +#include "object/gameobjs.h" +#include "object/player.h" MusicRef herring_song; MusicRef level_end_song; +MusicRef credits_song; SpriteManager* sprite_manager = 0; - -char * soundfilenames[NUM_SOUNDS] = { - "/sounds/jump.wav", - "/sounds/bigjump.wav", - "/sounds/skid.wav", - "/sounds/coin.wav", - "/sounds/invincible.wav", - "/sounds/brick.wav", - "/sounds/hurt.wav", - "/sounds/squish.wav", - "/sounds/fall.wav", - "/sounds/ricochet.wav", - "/sounds/bump-upgrade.wav", - "/sounds/upgrade.wav", - "/sounds/grow.wav", - "/sounds/fire-flower.wav", - "/sounds/shoot.wav", - "/sounds/lifeup.wav", - "/sounds/stomp.wav", - "/sounds/kick.wav", - "/sounds/explosion.wav", - "/sounds/warp.wav", - "/sounds/fireworks.wav" - }; - +TileManager* tile_manager = 0; +SoundManager* sound_manager = 0; Font* gold_text; Font* blue_text; @@ -87,8 +46,18 @@ Font* white_small_text; Font* white_big_text; /* Load graphics/sounds shared between all levels: */ -void loadshared() +void load_shared() { + /* Load GUI/menu images: */ + checkbox = new Surface(datadir + "/images/status/checkbox.png", true); + checkbox_checked = new Surface(datadir + "/images/status/checkbox-checked.png", true); + back = new Surface(datadir + "/images/status/back.png", true); + arrow_left = new Surface(datadir + "/images/icons/left.png", true); + arrow_right = new Surface(datadir + "/images/icons/right.png", true); + + /* Load the mouse-cursor */ + mouse_cursor = new MouseCursor( datadir + "/images/status/mousecursor.png",1); + MouseCursor::set_current(mouse_cursor); /* Load global images: */ gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18); @@ -114,13 +83,11 @@ void loadshared() int i; - sprite_manager = new SpriteManager(datadir + "/images/supertux.strf"); + sprite_manager = new SpriteManager( + get_resource_filename("/images/supertux.strf")); + tile_manager = new TileManager("/images/tilesets/supertux.stgt"); /* Tuxes: */ - smalltux_star = sprite_manager->create("smalltux-star"); - bigtux_star = sprite_manager->create("bigtux-star"); - smalltux_gameover = sprite_manager->create("smalltux-gameover"); - char img_name[1024]; for (int i = 0; i < GROWING_FRAMES; i++) { @@ -155,112 +122,44 @@ void loadshared() ice_tux->arms = sprite_manager->create("big-tux-arms"); ice_tux->feet = sprite_manager->create("big-tux-feet"); - /* Water: */ - img_water = new Surface(datadir + "/images/shared/water.png", false); - - img_waves[0] = new Surface(datadir + "/images/shared/waves-0.png", - true); - - img_waves[1] = new Surface(datadir + "/images/shared/waves-1.png", - true); - - - img_waves[2] = new Surface(datadir + "/images/shared/waves-2.png", - true); - - - /* Pole: */ - - img_pole = new Surface(datadir + "/images/shared/pole.png", true); - img_poletop = new Surface(datadir + "/images/shared/poletop.png", - true); - - - /* Flag: */ - - img_flag[0] = new Surface(datadir + "/images/shared/flag-0.png", - true); - img_flag[1] = new Surface(datadir + "/images/shared/flag-1.png", - true); - - - /* Cloud: */ - - img_cloud[0][0] = new Surface(datadir + "/images/shared/cloud-00.png", - true); - - img_cloud[0][1] = new Surface(datadir + "/images/shared/cloud-01.png", - true); - - img_cloud[0][2] = new Surface(datadir + "/images/shared/cloud-02.png", - true); - - img_cloud[0][3] = new Surface(datadir + "/images/shared/cloud-03.png", - true); - - - img_cloud[1][0] = new Surface(datadir + "/images/shared/cloud-10.png", - true); - - img_cloud[1][1] = new Surface(datadir + "/images/shared/cloud-11.png", - true); - - img_cloud[1][2] = new Surface(datadir + "/images/shared/cloud-12.png", - true); - - img_cloud[1][3] = new Surface(datadir + "/images/shared/cloud-13.png", - true); - /* Objects */ load_object_gfx(); - /* Distros: */ - img_distro[0] = new Surface(datadir + "/images/tilesets/coin1.png", - true); - - img_distro[1] = new Surface(datadir + "/images/tilesets/coin2.png", - true); - - img_distro[2] = new Surface(datadir + "/images/tilesets/coin3.png", - true); - - img_distro[3] = new Surface(datadir + "/images/tilesets/coin2.png", - true); - - /* Tux life: */ - tux_life = new Surface(datadir + "/images/shared/tux-life.png", true); /* Sound effects: */ - - /* if (use_sound) // this will introduce SERIOUS bugs here ! because "load_sound" - // initialize sounds[i] with the correct pointer's value: - // NULL or something else. And it will be dangerous to - // play with not-initialized pointers. - // This is also true with if (use_music) - Send a mail to me: neoneurone@users.sf.net, if you have another opinion. :) - */ - for (i = 0; i < NUM_SOUNDS; i++) - SoundManager::get - ()->add_sound(SoundManager::get - ()->load_sound(datadir + soundfilenames[i]),i); + sound_manager->preload_sound("jump"); + sound_manager->preload_sound("bigjump"); + sound_manager->preload_sound("skid"); + sound_manager->preload_sound("coin"); + sound_manager->preload_sound("invincible"); + sound_manager->preload_sound("brick"); + sound_manager->preload_sound("hurt"); + sound_manager->preload_sound("squish"); + sound_manager->preload_sound("fall"); + sound_manager->preload_sound("ricochet"); + sound_manager->preload_sound("bump-upgrade"); + sound_manager->preload_sound("upgrade"); + sound_manager->preload_sound("grow"); + sound_manager->preload_sound("fire-flower"); + sound_manager->preload_sound("shoot"); + sound_manager->preload_sound("lifeup"); + sound_manager->preload_sound("stomp"); + sound_manager->preload_sound("kick"); + sound_manager->preload_sound("explosion"); + sound_manager->preload_sound("warp"); + sound_manager->preload_sound("fireworks"); /* Herring song */ - herring_song = SoundManager::get - ()->load_music(datadir + "/music/salcon.mod"); - level_end_song = SoundManager::get - ()->load_music(datadir + "/music/leveldone.mod"); + herring_song = sound_manager->load_music(datadir + "/music/salcon.mod"); + level_end_song = sound_manager->load_music(datadir + "/music/leveldone.mod"); } /* Free shared data: */ -void unloadshared(void) +void unload_shared() { - delete smalltux_star; - delete bigtux_star; - delete smalltux_gameover; - /* Free global images: */ delete gold_text; delete white_text; @@ -272,22 +171,6 @@ void unloadshared(void) free_object_gfx(); - delete img_water; - for (int i = 0; i < 3; i++) - delete img_waves[i]; - - delete img_pole; - delete img_poletop; - - for (int i = 0; i < 2; i++) - delete img_flag[i]; - - for (int i = 0; i < 4; i++) { - delete img_distro[i]; - delete img_cloud[0][i]; - delete img_cloud[1][i]; - } - delete tux_life; delete small_tux; @@ -302,5 +185,30 @@ void unloadshared(void) delete sprite_manager; sprite_manager = 0; + delete tile_manager; + tile_manager = 0; + + /* Free GUI/menu images: */ + delete checkbox; + delete checkbox_checked; + delete back; + delete arrow_left; + delete arrow_right; + + /* Free mouse-cursor */ + delete mouse_cursor; } +std::string get_resource_filename(const std::string& resource) +{ + std::string filepath = user_dir + resource; + if(FileSystem::faccessible(filepath)) + return filepath; + + filepath = datadir + resource; + if(FileSystem::faccessible(filepath)) + return filepath; + + std::cerr << "Couldn't find resource: '" << resource << "'." << std::endl; + return ""; +}