- commited Michael George's config-file patch
[supertux.git] / src / worldmap.cpp
index d7201fb..e18a450 100644 (file)
@@ -1,7 +1,7 @@
 //  $Id$
 //
-//  Pingus - A free Lemmings clone
-//  Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
+//  SuperTux -  A Jump'n Run
+//  Copyright (C) 2004 Ingo Ruhnke <grumbel@gmx.de>
 //
 //  This program is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU General Public License
@@ -25,6 +25,7 @@
 #include "screen.h"
 #include "lispreader.h"
 #include "gameloop.h"
+#include "setup.h"
 #include "worldmap.h"
 
 namespace WorldMapNS {
@@ -33,9 +34,11 @@ TileManager* TileManager::instance_  = 0;
 
 TileManager::TileManager()
 {
-  lisp_object_t* root_obj = lisp_read_from_file(datadir +  "images/worldmap/antarctica.scm");
-  
-  assert(root_obj);
+  std::string stwt_filename = datadir +  "images/worldmap/antarctica.scm";
+  lisp_object_t* root_obj = lisp_read_from_file(stwt_filename);
+  if (!root_obj)
+    st_abort("Couldn't load file", stwt_filename);
 
   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap-tiles") == 0)
     {
@@ -217,8 +220,11 @@ WorldMap::~WorldMap()
 void
 WorldMap::load_map()
 {
-  lisp_object_t* root_obj = lisp_read_from_file(datadir +  "levels/default/worldmap.stwm");
-  assert(root_obj);
+  std::string filename = datadir +  "levels/default/worldmap.stwm";
+  
+  lisp_object_t* root_obj = lisp_read_from_file(filename);
+  if (!root_obj)
+    st_abort("Couldn't load file", filename);
   
   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap") == 0)
     {
@@ -278,6 +284,7 @@ WorldMap::get_input()
   SDL_Event event;
 
   enter_level = false;
+  input_direction = NONE;
 
   while (SDL_PollEvent(&event))
     {
@@ -301,13 +308,37 @@ WorldMap::get_input()
               break;
             }
           break;
+          
+        case SDL_JOYAXISMOTION:
+          switch(event.jaxis.axis)
+            {
+            case JOY_X:
+              if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
+                input_direction = WEST;
+              else if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
+                input_direction = EAST;
+              break;
+            case JOY_Y:
+              if (event.jaxis.value > JOYSTICK_DEAD_ZONE)
+                input_direction = SOUTH;
+              else if (event.jaxis.value < -JOYSTICK_DEAD_ZONE)
+                input_direction = NORTH;
+              break;
+            }
+          break;
+
+        case SDL_JOYBUTTONDOWN:
+          if (event.jbutton.button == JOY_B)
+            enter_level = true;
+          break;
+
+        default:
+          break;
         }
     }
 
   Uint8 *keystate = SDL_GetKeyState(NULL);
   
-  input_direction = NONE;
-  
   if (keystate[SDLK_LEFT])
     input_direction = WEST;
   else if (keystate[SDLK_RIGHT])