Had a bit of time today and worked on supertux:
[supertux.git] / src / resources.cpp
index 9b69d67..f2c3c0a 100644 (file)
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include <config.h>
+
 #include "app/globals.h"
-#include "scene.h"
-#include "player.h"
-#include "badguy.h"
-#include "gameobjs.h"
-#include "special.h"
-#include "resources.h"
 #include "special/sprite_manager.h"
-#include "audio/sound_manager.h"
 #include "app/setup.h"
-#include "door.h"
+#include "gui/menu.h"
 #include "gui/button.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];
+#include "resources.h"
+#include "tile_manager.h"
+#include "object/gameobjs.h"
+#include "object/player.h"
 
 Menu* main_menu      = 0;
 Menu* game_menu      = 0;
@@ -51,9 +42,10 @@ Menu* contrib_subset_menu   = 0;
 
 MusicRef herring_song;
 MusicRef level_end_song;
+MusicRef credits_song;
 
 SpriteManager* sprite_manager = 0;
-SoundManager* sound_manager = 0;
+TileManager* tile_manager = 0;
 
 char * soundfilenames[NUM_SOUNDS] = {
                                        "/sounds/jump.wav",
@@ -74,7 +66,9 @@ char * soundfilenames[NUM_SOUNDS] = {
                                        "/sounds/lifeup.wav",
                                        "/sounds/stomp.wav",
                                        "/sounds/kick.wav",
-                                       "/sounds/explosion.wav"
+                                       "/sounds/explosion.wav",
+                                       "/sounds/warp.wav",
+                                       "/sounds/fireworks.wav"
                                     };
 
 
@@ -89,7 +83,6 @@ Font* white_big_text;
 /* Load graphics/sounds shared between all levels: */
 void loadshared()
 {
-
   /* Load global images: */
   gold_text = new Font(datadir + "/images/fonts/gold.png", Font::TEXT, 16,18);
   blue_text = new Font(datadir + "/images/fonts/blue.png", Font::TEXT, 16,18,3);
@@ -114,13 +107,11 @@ void loadshared()
 
   int i;
 
-  sprite_manager = new SpriteManager(datadir + "/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->load("smalltux-star");
-  largetux_star = sprite_manager->load("largetux-star");
-  smalltux_gameover = sprite_manager->load("smalltux-gameover");
-
   char img_name[1024];
   for (int i = 0; i < GROWING_FRAMES; i++)
     {
@@ -131,123 +122,45 @@ void loadshared()
       growingtux_right[i] = new Surface(img_name, true);
     }
 
-  small_tux = sprite_manager->load("small-tux");
-  big_tux   = sprite_manager->load("big-tux");
-  ice_tux   = sprite_manager->load("ice-tux");
-  fire_tux  = sprite_manager->load("fire-tux");
-
-  tux_arm = sprite_manager->load("tux-arm");
-
-  /* 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);
-
-
-  /* Bad guys: */
-  load_badguy_gfx();
-
-  /* Upgrades: */
-  load_special_gfx();
+  small_tux = new TuxBodyParts();
+  small_tux->head = 0;
+  small_tux->body = sprite_manager->create("small-tux-body");
+  small_tux->arms = sprite_manager->create("small-tux-arms");
+  small_tux->feet = 0;
+
+  big_tux = new TuxBodyParts();
+  big_tux->head = sprite_manager->create("big-tux-head");
+  big_tux->body = sprite_manager->create("big-tux-body");
+  big_tux->arms = sprite_manager->create("big-tux-arms");
+  big_tux->feet = sprite_manager->create("big-tux-feet");
+
+  fire_tux = new TuxBodyParts();
+  fire_tux->head = sprite_manager->create("big-fire-tux-head");
+  fire_tux->body = sprite_manager->create("big-tux-body");
+  fire_tux->arms = sprite_manager->create("big-tux-arms");
+  fire_tux->feet = sprite_manager->create("big-tux-feet");
+
+  ice_tux = new TuxBodyParts();
+  ice_tux->head = sprite_manager->create("big-tux-head");
+  ice_tux->body = sprite_manager->create("big-tux-body");
+  ice_tux->arms = sprite_manager->create("big-tux-arms");
+  ice_tux->feet = sprite_manager->create("big-tux-feet");
 
   /* Objects */
   load_object_gfx();
 
-  // load the door object graphics:
-  door = sprite_manager->load("door");
-  for (int i = 0; i < DOOR_OPENING_FRAMES; i++)
-    {
-      sprintf(img_name, "%s/images/shared/door-%i.png", datadir.c_str(), i+1);
-      door_opening[i] = new Surface(img_name, true);
-    }
-
-  /* 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
+    SoundManager::get()->add_sound(SoundManager::get
                       ()->load_sound(datadir + soundfilenames[i]),i);
 
   /* Herring song */
   herring_song = SoundManager::get
-                   ()->load_music(datadir + "/music/SALCON.MOD");
+                   ()->load_music(datadir + "/music/salcon.mod");
   level_end_song = SoundManager::get
                      ()->load_music(datadir + "/music/leveldone.mod");
 }
@@ -264,44 +177,36 @@ void unloadshared(void)
   delete white_big_text;
   delete yellow_nums;
   
-  int i;
-
-  free_special_gfx();
-  free_badguy_gfx();
-
-  delete img_water;
-  for (i = 0; i < 3; i++)
-    delete img_waves[i];
-
-  delete img_pole;
-  delete img_poletop;
-
-  for (i = 0; i < 2; i++)
-    delete img_flag[i];
-
-  for (i = 0; i < 4; i++)
-    {
-      delete img_distro[i];
-      delete img_cloud[0][i];
-      delete img_cloud[1][i];
-    }
+  free_object_gfx();
 
   delete tux_life;
 
-  for (int i = 0; i < GROWING_FRAMES; i++)
-  {
+  delete small_tux;
+  delete big_tux;
+  delete fire_tux;
+  delete ice_tux;
+
+  for (int i = 0; i < GROWING_FRAMES; i++) {
     delete growingtux_left[i];
     delete growingtux_right[i];
   }
 
-  // door game object:
-
-  for (int i = 0; i < DOOR_OPENING_FRAMES; i++)
-    delete door_opening[i];
-
   delete sprite_manager;
   sprite_manager = 0;
-  sound_manager = 0;
+  delete tile_manager;
+  tile_manager = 0;
 }
 
-/* EOF */
+std::string get_resource_filename(const std::string& resource)
+{
+  std::string filepath = st_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 "";
+}