]> git.jsancho.org Git - lugaru.git/blobdiff - Source/GameTick.cpp
Cleanup sound loading
[lugaru.git] / Source / GameTick.cpp
index 5c8b4acd77ef67faaadbdaee4fe991ef27b0d20b..0a6d464d221d1e551ce1cc7cfdb6617d8f506acf 100644 (file)
@@ -31,17 +31,24 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #include "Game.h"
 #include "openal_wrapper.h"
 #include "Settings.h"
+#include "Input.h"
+#include "Animation.h"
 
 using namespace std;
 
+// Added more evilness needed for MSVC
+#ifdef _MSC_VER
+       #define strncasecmp(s1, s2, n) _strnicmp(s1, s2, n)
+       #define snprintf(buf, size, format, ...) _sprintf_p(buf, size, format)
+#endif
+
+
 extern float multiplier;
 extern XYZ viewer;
 extern int environment;
 extern float texscale;
 extern Terrain terrain;
-extern OPENAL_SAMPLE   *samp[100];
 extern int channels[100];
-extern Sprites sprites;
 extern int kTextureSize;
 extern float screenwidth,screenheight;
 extern float gravity;
@@ -52,7 +59,6 @@ extern int slomo;
 extern float slomodelay;
 extern bool floatjump;
 extern float volume;
-extern Animation animation[animation_count];
 extern Light light;
 extern float texdetail;
 extern GLubyte bloodText[512*512*3];
@@ -82,7 +88,6 @@ extern int netdatanew;
 extern bool loadingstuff;
 extern char mapname[256];
 extern XYZ windvector;
-extern bool buttons[3];
 extern bool debugmode;
 static int music1;
 extern int mainmenu;
@@ -101,6 +106,7 @@ extern bool foliage;
 extern bool trilinear;
 extern bool damageeffects;
 extern bool showpoints;
+extern bool showdamagebar; // (des)activate the damage bar
 extern bool texttoggle;
 extern bool alwaysblur;
 extern float gamespeed;
@@ -141,7 +147,6 @@ extern float damagetaken;
 extern int maptype;
 extern int editoractive;
 extern int editorpathtype;
-extern bool oldbuttons[3];
 
 extern float hostiletime;
 
@@ -160,16 +165,6 @@ extern int currenthotspot;
 extern int kBitsPerPixel;
 extern int hostile;
 
-extern int numaccounts;
-extern int accountactive;
-extern int accountdifficulty[10];
-extern int accountprogress[10];
-extern float accountpoints[10];
-extern float accounthighscore[10][50];
-extern float accountfasttime[10][50];
-extern bool accountunlocked[10][60];
-extern char accountname[10][256];
-
 extern bool stillloading;
 extern bool winfreeze;
 
@@ -216,14 +211,6 @@ extern bool campaign;
 
 extern float oldgamespeed;
 
-extern float accountcampaignhighscore[10];
-extern float accountcampaignfasttime[10];
-extern float accountcampaignscore[10];
-extern float accountcampaigntime[10];
-
-extern int accountcampaignchoicesmade[10];
-extern int accountcampaignchoices[10][5000];
-
 static const char *rabbitskin[] = {
 ":Data:Textures:Fur3.jpg",
 ":Data:Textures:Fur.jpg",
@@ -325,142 +312,131 @@ static void ch_save(Game *game, const char *args)
   fpackf(tfile, "Bi Bi", player[0].whichskin, player[0].creature);
 
   fpackf(tfile, "Bi", numdialogues);
-  if(numdialogues)
-    for(k=0;k<numdialogues;k++){
-      fpackf(tfile, "Bi", numdialogueboxes[k]);
-      fpackf(tfile, "Bi", dialoguetype[k]);
-      for(l=0;l<10;l++){
-       fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
-       fpackf(tfile, "Bf", participantrotation[k][l]);
-      }
-      if(numdialogueboxes)
-       for(l=0;l<numdialogueboxes[k];l++){
-         fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
-         fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
-         fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
-         fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
-         fpackf(tfile, "Bi", dialogueboxsound[k][l]);
-
-         templength=strlen(dialoguetext[k][l]);
-         fpackf(tfile, "Bi",(templength));
-         for(m=0;m<templength;m++){
-           fpackf(tfile, "Bb", dialoguetext[k][l][m]);
-           if(dialoguetext[k][l][m]=='\0')break;
-         }
-
-         templength=strlen(dialoguename[k][l]);
-         fpackf(tfile, "Bi",templength);
-         for(m=0;m<templength;m++){
-           fpackf(tfile, "Bb", dialoguename[k][l][m]);
-           if(dialoguename[k][l][m]=='\0')break;
-         }
-
-         fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
-         fpackf(tfile, "Bi", participantfocus[k][l]);
-         fpackf(tfile, "Bi", participantaction[k][l]);
-
-         for(m=0;m<10;m++)
-           fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
-
-         fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
+       for(k=0;k<numdialogues;k++){
+               fpackf(tfile, "Bi", numdialogueboxes[k]);
+               fpackf(tfile, "Bi", dialoguetype[k]);
+               for(l=0;l<10;l++){
+                       fpackf(tfile, "Bf Bf Bf", participantlocation[k][l].x, participantlocation[k][l].y, participantlocation[k][l].z);
+                       fpackf(tfile, "Bf", participantrotation[k][l]);
+               }
+               for(l=0;l<numdialogueboxes[k];l++){
+                       fpackf(tfile, "Bi", dialogueboxlocation[k][l]);
+                       fpackf(tfile, "Bf", dialogueboxcolor[k][l][0]);
+                       fpackf(tfile, "Bf", dialogueboxcolor[k][l][1]);
+                       fpackf(tfile, "Bf", dialogueboxcolor[k][l][2]);
+                       fpackf(tfile, "Bi", dialogueboxsound[k][l]);
+
+                       templength=strlen(dialoguetext[k][l]);
+                       fpackf(tfile, "Bi",(templength));
+                       for(m=0;m<templength;m++){
+                               fpackf(tfile, "Bb", dialoguetext[k][l][m]);
+                               if(dialoguetext[k][l][m]=='\0')break;
+                       }
+
+                       templength=strlen(dialoguename[k][l]);
+                       fpackf(tfile, "Bi",templength);
+                       for(m=0;m<templength;m++){
+                               fpackf(tfile, "Bb", dialoguename[k][l][m]);
+                               if(dialoguename[k][l][m]=='\0')break;
+                       }
+
+                       fpackf(tfile, "Bf Bf Bf", dialoguecamera[k][l].x, dialoguecamera[k][l].y, dialoguecamera[k][l].z);
+                       fpackf(tfile, "Bi", participantfocus[k][l]);
+                       fpackf(tfile, "Bi", participantaction[k][l]);
+
+                       for(m=0;m<10;m++)
+                               fpackf(tfile, "Bf Bf Bf", participantfacing[k][l][m].x, participantfacing[k][l][m].y, participantfacing[k][l][m].z);
+
+                       fpackf(tfile, "Bf Bf",dialoguecamerarotation[k][l],dialoguecamerarotation2[k][l]);
+               }
        }
-    }
 
-  if(player[0].numclothes)
-    for(k=0;k<player[0].numclothes;k++){
-      templength=strlen(player[0].clothes[k]);
-      fpackf(tfile, "Bi", templength);
-      for(l=0;l<templength;l++)
-       fpackf(tfile, "Bb", player[0].clothes[k][l]);
-      fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
-    }
+       for(k=0;k<player[0].numclothes;k++){
+               templength=strlen(player[0].clothes[k]);
+               fpackf(tfile, "Bi", templength);
+               for(l=0;l<templength;l++)
+                       fpackf(tfile, "Bb", player[0].clothes[k][l]);
+               fpackf(tfile, "Bf Bf Bf", player[0].clothestintr[k], player[0].clothestintg[k], player[0].clothestintb[k]);
+       }
 
   fpackf(tfile, "Bi", environment);
 
   fpackf(tfile, "Bi", objects.numobjects);
 
-  if(objects.numobjects)
     for(k=0;k<objects.numobjects;k++){
       fpackf(tfile, "Bi Bf Bf Bf Bf Bf Bf", objects.type[k], objects.rotation[k], objects.rotation2[k], objects.position[k].x, objects.position[k].y, objects.position[k].z, objects.scale[k]);
     }
 
   fpackf(tfile, "Bi", numhotspots);
-  if(numhotspots)
-    for(i=0;i<numhotspots;i++){
-      fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
-      templength=strlen(hotspottext[i]);
-      fpackf(tfile, "Bi",templength);
-      for(l=0;l<templength;l++)
-       fpackf(tfile, "Bb", hotspottext[i][l]);
-    }
+       for(i=0;i<numhotspots;i++){
+               fpackf(tfile, "Bi Bf Bf Bf Bf", hotspottype[i],hotspotsize[i],hotspot[i].x,hotspot[i].y,hotspot[i].z);
+               templength=strlen(hotspottext[i]);
+               fpackf(tfile, "Bi",templength);
+               for(l=0;l<templength;l++)
+                       fpackf(tfile, "Bb", hotspottext[i][l]);
+       }
 
   fpackf(tfile, "Bi", numplayers);
-  if(numplayers>1&&numplayers<maxplayers)
+  if(numplayers<maxplayers)
     for(j=1;j<numplayers;j++){
-      fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature, player[j].coords.x, player[j].coords.y, player[j].coords.z, player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
-      if(player[j].num_weapons>0&&player[j].num_weapons<5)
-       for(k=0;k<player[j].num_weapons;k++){
-         fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
-       }
-      if(player[j].numwaypoints<30){
-       fpackf(tfile, "Bi", player[j].numwaypoints);
-       for(k=0;k<player[j].numwaypoints;k++){
-         fpackf(tfile, "Bf", player[j].waypoints[k].x);
-         fpackf(tfile, "Bf", player[j].waypoints[k].y);
-         fpackf(tfile, "Bf", player[j].waypoints[k].z);
-         fpackf(tfile, "Bi", player[j].waypointtype[k]);
-       }
-       fpackf(tfile, "Bi", player[j].waypoint);
-      }
-      else{
-       player[j].numwaypoints=0;
-       player[j].waypoint=0;
-       fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
-      }
-
-      fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
-      fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
-      fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
-      fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
-
-      if(player[j].creature==wolftype){
-       headprop=player[j].proportionhead.x/1.1;
-       bodyprop=player[j].proportionbody.x/1.1;
-       armprop=player[j].proportionarms.x/1.1;
-       legprop=player[j].proportionlegs.x/1.1;
-      }
-
-      if(player[j].creature==rabbittype){
-       headprop=player[j].proportionhead.x/1.2;
-       bodyprop=player[j].proportionbody.x/1.05;
-       armprop=player[j].proportionarms.x/1.00;
-       legprop=player[j].proportionlegs.x/1.1;
-      }
-
-      fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
+               fpackf(tfile, "Bi Bi Bf Bf Bf Bi Bi Bf Bb Bf", player[j].whichskin, player[j].creature, player[j].coords.x, player[j].coords.y, player[j].coords.z, player[j].num_weapons, player[j].howactive, player[j].scale, player[j].immobile, player[j].rotation);
+               if(player[j].num_weapons<5)
+                       for(k=0;k<player[j].num_weapons;k++){
+                               fpackf(tfile, "Bi", weapons.type[player[j].weaponids[k]]);
+                       }
+               if(player[j].numwaypoints<30){
+                       fpackf(tfile, "Bi", player[j].numwaypoints);
+                       for(k=0;k<player[j].numwaypoints;k++){
+                               fpackf(tfile, "Bf", player[j].waypoints[k].x);
+                               fpackf(tfile, "Bf", player[j].waypoints[k].y);
+                               fpackf(tfile, "Bf", player[j].waypoints[k].z);
+                               fpackf(tfile, "Bi", player[j].waypointtype[k]);
+                       }
+                       fpackf(tfile, "Bi", player[j].waypoint);
+               } else {
+                       player[j].numwaypoints=0;
+                       player[j].waypoint=0;
+                       fpackf(tfile, "Bi Bi Bi", player[j].numwaypoints, player[j].waypoint, player[j].waypoint);
+               }
 
+               fpackf(tfile, "Bf Bf Bf", player[j].armorhead, player[j].armorhigh, player[j].armorlow);
+               fpackf(tfile, "Bf Bf Bf", player[j].protectionhead, player[j].protectionhigh, player[j].protectionlow);
+               fpackf(tfile, "Bf Bf Bf", player[j].metalhead, player[j].metalhigh, player[j].metallow);
+               fpackf(tfile, "Bf Bf", player[j].power, player[j].speedmult);
+
+               if(player[j].creature==wolftype) {
+                       headprop=player[j].proportionhead.x/1.1;
+                       bodyprop=player[j].proportionbody.x/1.1;
+                       armprop=player[j].proportionarms.x/1.1;
+                       legprop=player[j].proportionlegs.x/1.1;
+               } else if(player[j].creature==rabbittype){
+                       headprop=player[j].proportionhead.x/1.2;
+                       bodyprop=player[j].proportionbody.x/1.05;
+                       armprop=player[j].proportionarms.x/1.00;
+                       legprop=player[j].proportionlegs.x/1.1;
+               }
 
+               fpackf(tfile, "Bf Bf Bf Bf", headprop, bodyprop, armprop, legprop);
 
-      fpackf(tfile, "Bi", player[j].numclothes);
-      if(player[j].numclothes)
-       for(k=0;k<player[j].numclothes;k++){
-         int templength;
-         templength=strlen(player[j].clothes[k]);
-         fpackf(tfile, "Bi", templength);
-         for(l=0;l<templength;l++)
-           fpackf(tfile, "Bb", player[j].clothes[k][l]);
-         fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
-       }
+               fpackf(tfile, "Bi", player[j].numclothes);
+               if(player[j].numclothes)
+                       for(k=0;k<player[j].numclothes;k++){
+                               int templength;
+                               templength=strlen(player[j].clothes[k]);
+                               fpackf(tfile, "Bi", templength);
+                               for(l=0;l<templength;l++)
+                                       fpackf(tfile, "Bb", player[j].clothes[k][l]);
+                               fpackf(tfile, "Bf Bf Bf", player[j].clothestintr[k], player[j].clothestintg[k], player[j].clothestintb[k]);
+                       }
     }
 
   fpackf(tfile, "Bi", game->numpathpoints);
-  if(game->numpathpoints)
-    for(j=0;j<game->numpathpoints;j++){
-      fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
-      for(k=0;k<game->numpathpointconnect[j];k++){
-       fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
-      }
-    }
+       for(j=0;j<game->numpathpoints;j++){
+               fpackf(tfile, "Bf Bf Bf Bi", game->pathpoint[j].x, game->pathpoint[j].y, game->pathpoint[j].z, game->numpathpointconnect[j]);
+               for(k=0;k<game->numpathpointconnect[j];k++){
+                       fpackf(tfile, "Bi", game->pathpointconnect[j][k]);
+               }
+       }
 
   fpackf(tfile, "Bf Bf Bf Bf", game->mapcenter.x, game->mapcenter.y, game->mapcenter.z, game->mapradius);
 
@@ -547,9 +523,7 @@ static void set_proportion(int pnum, const char *args)
     player[pnum].proportionbody=1.1*bodyprop;
     player[pnum].proportionarms=1.1*armprop;
     player[pnum].proportionlegs=1.1*legprop;
-  }
-
-  if(player[pnum].creature==rabbittype){
+  } else if(player[pnum].creature==rabbittype){
     player[pnum].proportionhead=1.2*headprop;
     player[pnum].proportionbody=1.05*bodyprop;
     player[pnum].proportionarms=1.00*armprop;
@@ -821,23 +795,21 @@ static void ch_notindemo(Game *game, const char *args)
 static void ch_type(Game *game, const char *args)
 {
   int i, n = sizeof(editortypenames) / sizeof(editortypenames[0]);
-  for (i = 0; i < n; i++)
-    if (stripfx(args, editortypenames[i]))
-      {
-       editoractive = i;
-       break;
-      }
+       for (i = 0; i < n; i++)
+               if (stripfx(args, editortypenames[i])) {
+                       editoractive = i;
+                       break;
+               }
 }
 
 static void ch_path(Game *game, const char *args)
 {
   int i, n = sizeof(pathtypenames) / sizeof(pathtypenames[0]);
   for (i = 0; i < n; i++)
-    if (stripfx(args, pathtypenames[i]))
-      {
-       editorpathtype = i;
-       break;
-      }
+    if (stripfx(args, pathtypenames[i])) {
+               editorpathtype = i;
+               break;
+    }
 }
 
 static void ch_hs(Game *game, const char *args)
@@ -1006,9 +978,7 @@ static void ch_default(Game *game, const char *args)
     player[0].proportionbody=1.1;
     player[0].proportionarms=1.1;
     player[0].proportionlegs=1.1;
-  }
-
-  if(player[0].creature==rabbittype){
+  } else if(player[0].creature==rabbittype){
     player[0].proportionhead=1.2;
     player[0].proportionbody=1.05;
     player[0].proportionarms=1.00;
@@ -1187,10 +1157,8 @@ static void cmd_dispatch(Game *game, const char *cmd)
     }
 }
 
-
-
 /********************> Tick() <*****/
-extern void ScreenShot(const char * fname);
+extern bool save_image(const char * fname);
 void Screenshot        (void)
 {
        char temp[1024];
@@ -1203,193 +1171,8 @@ void Screenshot (void)
        #else
        mkdir("Screenshots", S_IRWXU);
        #endif
-
-       ScreenShot(temp/*"Screenshots\\Screenshot.png"*/);
-
-       /*FSSpec                                MAC_file;
-       GraphicsExportComponent QT_exporter;
-       OSErr                           MAC_error_code;
-       CGrafPtr                        MAC_currentPort;
-       GDHandle                        MAC_currentDevice;
-       unsigned char*          MAC_pixels;
-       Rect                            MAC_picture_rectangle;
-       GWorldPtr                       MAC_offscreen_graphics_port;
-
-       static int numscreenshots=0;
-
-       // Make an FSSpec
-       static char buf[256];
-       if(numscreenshots==0){
-       buf[0]=26;
-       buf[1]=':';
-       buf[2]='S';
-       buf[3]='c';
-       buf[4]='r';
-       buf[5]='e';
-       buf[6]='e';
-       buf[7]='n';
-       buf[8]='s';
-       buf[9]='h';
-       buf[10]='o';
-       buf[11]='t';
-       buf[12]='s';
-       buf[13]=':';
-       buf[14]='S';
-       buf[15]='c';
-       buf[16]='r';
-       buf[17]='e';
-       buf[18]='e';
-       buf[19]='n';
-       buf[20]='s';
-       buf[21]='h';
-       buf[22]='o';
-       buf[23]='t';
-       buf[24]='0';
-       buf[25]='0';
-       buf[26]='0';
-       }
-
-       FInfo *fndrInfo;
-       FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
-       while(!FSpGetFInfo (&MAC_file, fndrInfo)){
-       FSMakeFSSpec(0, 0, (unsigned char*)buf, &MAC_file);
-       if(!FSpGetFInfo (&MAC_file, fndrInfo)){
-       numscreenshots++;
-       buf[26]++;
-       if(buf[26]==':'){
-       buf[26]='0';
-       buf[25]++;
-       if(buf[25]==':'){
-       buf[25]='0';
-       buf[24]++;
-       if(buf[24]==':'){
-       buf[24]='9';
-       buf[25]='9';
-       buf[26]='9';
-       }
-       }
-       }
-       }
-       }
-
-
-       // Get the GWorld
-       GWorldPtr                       MAC_gWorld = (CGrafPtr) FrontWindow();
-       //assert(MAC_gWorld != NULL);
-
-       // Allocate memory for loading image
-       MAC_pixels = new unsigned char[(int)(screenheight * screenwidth * 4)];
-       if (MAC_pixels == NULL) {
-       //UTIL_Error("Could not create Texture data.");
-       return;
-       }
-
-       // Get GWorld
-       ::GetGWorld(&MAC_currentPort, &MAC_currentDevice);
-
-       // Make a picture Rectangle
-       MAC_picture_rectangle.left = 0;
-       MAC_picture_rectangle.right = screenwidth;
-       MAC_picture_rectangle.top = 0;
-       MAC_picture_rectangle.bottom = screenheight;
-
-       // Create new offscreen GWorld
-       MAC_error_code = ::QTNewGWorldFromPtr (&MAC_offscreen_graphics_port, k32ARGBPixelFormat, &MAC_picture_rectangle, NULL, NULL, 0, (char *) MAC_pixels, screenwidth * 4);
-       if (MAC_error_code)     {
-       ::SetGWorld(MAC_currentPort, MAC_currentDevice);
-       delete MAC_pixels;
-       //UTIL_Error("Could not create offscreen GWorld. ");
-       return;
-
-       }
-
-       // Copy OpenGL Context to new GWorld
-       glReadBuffer(GL_FRONT);
-       glReadPixels(0,0,screenwidth,screenheight,GL_RGBA,GL_UNSIGNED_BYTE,MAC_pixels);
-
-       // Swizzle texture
-       for (unsigned long byte = 0; byte < screenheight * screenwidth * 4; byte+=4) {
-       unsigned char temp = MAC_pixels[byte+0];
-       MAC_pixels[byte+0] = MAC_pixels[byte+3];
-       MAC_pixels[byte+3] = MAC_pixels[byte+2];
-       MAC_pixels[byte+2] = MAC_pixels[byte+1];
-       MAC_pixels[byte+1] = temp;
-       }
-
-       // Flip the image  :(   This could probably be optimized
-       int vert;
-       int src_index;
-       int dst_index;
-       unsigned char temp;
-       for (int horz = 0; horz < screenwidth; ++horz)
-       for (vert = 0; vert < screenheight / 2; ++vert) {
-       src_index = (screenwidth * vert + horz) * 4;
-       dst_index = (screenwidth * (screenheight - vert - 1) + horz) * 4;
-
-       temp=MAC_pixels[src_index+0];
-       MAC_pixels[src_index+0]=MAC_pixels[dst_index+0];
-       MAC_pixels[dst_index+0]=temp;
-
-       temp=MAC_pixels[src_index+1];
-       MAC_pixels[src_index+1]=MAC_pixels[dst_index+1];
-       MAC_pixels[dst_index+1]=temp;
-
-       temp=MAC_pixels[src_index+2];
-       MAC_pixels[src_index+2]=MAC_pixels[dst_index+2];
-       MAC_pixels[dst_index+2]=temp;
-
-       temp=MAC_pixels[src_index+3];
-       MAC_pixels[src_index+3]=MAC_pixels[dst_index+3];
-       MAC_pixels[dst_index+3]=temp;
-       }
-
-
-
-       // Export the Gworld
-       MAC_error_code =  OpenADefaultComponent(GraphicsExporterComponentType, kQTFileTypeBMP, &QT_exporter);
-       if (MAC_error_code) {
-       //UTIL_Warning("Unable to export screenshot.");
-       ::SetGWorld(MAC_currentPort, MAC_currentDevice);
-       ::DisposeGWorld(MAC_offscreen_graphics_port);
-       delete MAC_pixels;
-       return;
-       }
-
-       MAC_error_code =  GraphicsExportSetInputGWorld(QT_exporter,MAC_offscreen_graphics_port);
-       if (MAC_error_code) {
-       ::CloseComponent(QT_exporter);
-       ::SetGWorld(MAC_currentPort, MAC_currentDevice);
-       ::DisposeGWorld(MAC_offscreen_graphics_port);
-       delete MAC_pixels;
-       //UTIL_Warning("Unable to export screenshot.");
-       return;
-       }
-
-       MAC_error_code = GraphicsExportSetOutputFile(QT_exporter,&MAC_file);
-       if (MAC_error_code) {
-       ::CloseComponent(QT_exporter);
-       ::SetGWorld(MAC_currentPort, MAC_currentDevice);
-       ::DisposeGWorld(MAC_offscreen_graphics_port);
-       delete MAC_pixels;
-       //UTIL_Warning("Unable to export screenshot.");
-       return;
-       }
-
-       MAC_error_code = GraphicsExportDoExport(QT_exporter,NULL);
-       if (MAC_error_code) {
-       ::CloseComponent(QT_exporter);
-       ::SetGWorld(MAC_currentPort, MAC_currentDevice);
-       ::DisposeGWorld(MAC_offscreen_graphics_port);
-       delete MAC_pixels;
-       //UTIL_Warning("Unable to export screenshot.");
-       return;
-       }
-
-       ::CloseComponent(QT_exporter);
-       ::SetGWorld(MAC_currentPort, MAC_currentDevice);
-       ::DisposeGWorld(MAC_offscreen_graphics_port);
-
-       delete MAC_pixels;*/
+       
+       save_image(temp);
 }
 
 
@@ -1789,26 +1572,6 @@ void     Game::Loadlevel(int which){
        whichlevel=which;
 }
 
-/*char * Game::MD5_string (unsigned char *string){
-char temp[50];
-char temp2[100];
-
-strcpy(temp2,(const char *)string);
-strcat((char *)temp2,(const char *)"Lugaru");
-sprintf (temp, "%d",strlen((char *)temp2));
-strcat((char *)temp2,temp);
-
-MD5 context;
-unsigned int len = strlen ( (char *)temp2);
-
-context.update   ((unsigned char *)temp2, len);
-context.finalize ();
-
-return context.hex_digest();
-}*/
-
-
-
 void   Game::Loadlevel(char *name){
        int i,j,k,l,m;
        static int oldlevel;
@@ -1865,7 +1628,7 @@ void      Game::Loadlevel(char *name){
                won=0;
 
                //campaign=0;
-               animation[bounceidleanim].Load((char *)":Data:Animations:Idle",middleheight,neutral);
+               animation[bounceidleanim].Load((char *)"Idle",middleheight,neutral);
 
                numdialogues=0;
 
@@ -1880,7 +1643,7 @@ void      Game::Loadlevel(char *name){
                damagedealt=0;
                damagetaken=0;
 
-               if(accountactive!=-1)difficulty=accountdifficulty[accountactive];
+               if(accountactive)difficulty=accountactive->getDifficulty();
 
                if(difficulty!=2)minimap=1;
                else minimap=0;
@@ -1935,7 +1698,7 @@ void      Game::Loadlevel(char *name){
                if(!stealthloading)
                {
                        terrain.numdecals=0;
-                       sprites.numsprites=0;
+                       Sprite::deleteSprites();
                        for(i=0;i<objects.numobjects;i++)
                        {
                                objects.model[i].numdecals=0;
@@ -2431,7 +2194,7 @@ void      Game::Loadlevel(char *name){
                                player[i].proportionlegs.z=0;
                        }
 
-                       player[i].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
+                       player[i].tempanimation.Load((char *)"Tempanim",0,0);
 
                        player[i].headmorphness=0;
                        player[i].targetheadmorphness=1;
@@ -2524,12 +2287,7 @@ void     Game::Loadlevel(char *name){
                        weapons.position[i]=-1000;
                        weapons.tippoint[i]=-1000;
                }
-
-/*             for(i=0;i<32;i++){
-                       //if(i<16||i>20)
-                       OPENAL_StopSound(i);
-               }
-*/
+               
                LOG("Starting background music...");
 
                OPENAL_StopSound(OPENAL_ALL);
@@ -2569,17 +2327,6 @@ void     Game::Loadlevel(char *name){
                oldmusicvolume[2]=0;
                oldmusicvolume[3]=0;
 
-
-               /*LoadTexture(":Data:Textures:cloud.png",&sprites.cloudtexture,1,1);
-               LoadTexture(":Data:Textures:cloudimpact.png",&sprites.cloudimpacttexture,1,1);
-               LoadTexture(":Data:Textures:bloodparticle.png",&sprites.bloodtexture,1,1);
-               LoadTexture(":Data:Textures:snowflake.png",&sprites.snowflaketexture,1,1);
-               LoadTexture(":Data:Textures:flame.png",&sprites.flametexture,1,1);
-               LoadTexture(":Data:Textures:bloodflame.png",&sprites.bloodflametexture,1,1);
-               LoadTexture(":Data:Textures:smoke.png",&sprites.smoketexture,1,1);
-               LoadTexture(":Data:Textures:shine.png",&sprites.shinetexture,1,0);
-               */
-
                if(!firstload)
                {
                        firstload=1;
@@ -2613,16 +2360,10 @@ void    Game::Tick()
                displaytime[i]+=multiplier;
        }
 
-       static unsigned char    theKeyMap[16];
-       GetKeys( theKeyMap );
-
        keyboardfrozen=0;
 
-
-       static bool mainmenutogglekeydown;
-
-       if (IsKeyDown(theKeyMap, MAC_F6_KEY) && !freezetogglekeydown) {
-               if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) {
+       if (Input::isKeyDown(SDLK_F6) && !freezetogglekeydown) {
+               if (Input::isKeyDown(SDLK_LSHIFT)) {
                        stereoreverse=true;
                } else {
                        stereoreverse=false;
@@ -2636,8 +2377,8 @@ void      Game::Tick()
                freezetogglekeydown=1;
        }
 
-       if (IsKeyDown(theKeyMap, MAC_F7_KEY)) {
-               if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) {
+       if (Input::isKeyDown(SDLK_F7)) {
+               if (Input::isKeyDown(SDLK_LSHIFT)) {
                        stereoseparation -= 0.001;
                } else {
                        stereoseparation -= 0.010;
@@ -2646,8 +2387,8 @@ void      Game::Tick()
                printf("Stereo decreased increased to %f\n", stereoseparation);
        }
 
-       if (IsKeyDown(theKeyMap, MAC_F8_KEY)) {
-               if (IsKeyDown(theKeyMap, MAC_SHIFT_KEY)) {
+       if (Input::isKeyDown(SDLK_F8)) {
+               if (Input::isKeyDown(SDLK_LSHIFT)) {
                        stereoseparation += 0.001;
                } else {
                        stereoseparation += 0.010;
@@ -2659,109 +2400,16 @@ void   Game::Tick()
 
        if(!console){
                if(mainmenu&&endgame==1)mainmenu=10;
-               if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)&&!mainmenutogglekeydown&&(mainmenu==7&&entername)){
-                       for(j=0;j<255;j++){
-                               displaytext[0][j]=' ';
-                       }
-                       displaychars[0]=0;
-                       displayselected=0;
-                       entername=0;
-                       mainmenutogglekeydown=1;
-               }
-               if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)||(mainmenu==0&&((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))&&!mainmenutogglekeydown&&(!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==11||mainmenu==13||mainmenu==17||mainmenu==10)){
+               if( (Input::isKeyDown(SDLK_ESCAPE)||(mainmenu==0&&((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE)||(campaign)))&&!oldjumpkeydown&&campaign&&winfreeze))
+                   && !mainmenutogglekeydown
+                   && (!mainmenu||gameon||mainmenu==3||mainmenu==4||mainmenu==5||mainmenu==6||(mainmenu==7&&!entername)||mainmenu==9||mainmenu==10)
+                 ) { // go back
                        selected=-1;
                        if(mainmenu==1||mainmenu==2||mainmenu==0){
                                if(mainmenu==0&&!winfreeze)mainmenu=2;
                                else if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1)mainmenu=100;
                                else if(mainmenu==0&&winfreeze){
-                                       /*      if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
-                                       stealthloading=1;
-                                       else stealthloading=0;
-
-                                       if(!stealthloading){
-                                       float gLoc[3]={0,0,0};
-                                       float vel[3]={0,0,0};
-                                       OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                                       PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                                       OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                                       OPENAL_SetVolume(channels[firestartsound], 256);
-                                       OPENAL_SetPaused(channels[firestartsound], false);
-                                       OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                                       flashr=1;
-                                       flashg=0;
-                                       flashb=0;
-                                       flashamount=1;
-                                       flashdelay=1;
-                                       }
-
-                                       startbonustotal=0;
-
-                                       for(i=0;i<campaignnumlevels;i++){
-                                       levelvisible[i]=0;
-                                       levelhighlight[i]=0;
-                                       }
-
-                                       levelorder[0]=0;
-                                       levelvisible[0]=1;
-                                       if(accountcampaignchoicesmade[accountactive])
-                                       for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
-                                       levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
-                                       levelvisible[levelorder[i+1]]=1;
-                                       }
-                                       int whichlevelstart;
-                                       whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
-                                       if(whichlevelstart<0){
-                                       campaignchoicenum=1;
-                                       campaignchoicewhich[0]=0;
-                                       }
-                                       else
-                                       {
-                                       campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
-                                       if(campaignchoicenum)
-                                       for(i=0;i<campaignchoicenum;i++){
-                                       campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
-                                       levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                                       levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                                       }
-                                       }
-
-                                       loading=2;
-                                       loadtime=0;
-                                       targetlevel=7;
-                                       if(firstload)TickOnceAfter();
-                                       if(!firstload)LoadStuff();
-                                       //else {
-                                       for(i=0;i<255;i++){
-                                       mapname[i]='\0';
-                                       }
-                                       mapname[0]=':';
-                                       mapname[1]='D';
-                                       mapname[2]='a';
-                                       mapname[3]='t';
-                                       mapname[4]='a';
-                                       mapname[5]=':';
-                                       mapname[6]='M';
-                                       mapname[7]='a';
-                                       mapname[8]='p';
-                                       mapname[9]='s';
-                                       mapname[10]=':';
-
-                                       //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
-                                       //accountcampaignchoicesmade[accountactive]++;
-
-
-                                       strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
-                                       whichchoice=0;
-                                       visibleloading=1;
-                                       stillloading=1;
-                                       Loadlevel(mapname);
-                                       campaign=1;
-                                       mainmenu=0;
-                                       gameon=1;
-                                       OPENAL_SetPaused(channels[music3], true);
-
-                                       stealthloading=0;*/
+                                       
                                }
                                else if(mainmenu==1||mainmenu==2)mainmenu=0;
                                if(mainmenu&&musictoggle){
@@ -2779,20 +2427,9 @@ void     Game::Tick()
                                }
                        }
                        if(mainmenu==3){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                               fireSound();
+
+                               flash();
 
                                if(newdetail>2)newdetail=detail;
                                if(newdetail<0)newdetail=detail;
@@ -2801,21 +2438,10 @@ void    Game::Tick()
 
                                SaveSettings(*this);
                        }
-                       if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==13||mainmenu==10||mainmenu==11||mainmenu==100){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(mainmenu==4||mainmenu==5||mainmenu==6||mainmenu==7||mainmenu==9||mainmenu==10||mainmenu==100){
+                               fireSound();
+
+                               flash();
                        }
                        if(mainmenu==3&&gameon)mainmenu=2;
                        if(mainmenu==3&&!gameon)mainmenu=1;
@@ -2825,8 +2451,6 @@ void      Game::Tick()
                        if(mainmenu==6)mainmenu=5;
                        if(mainmenu==7)mainmenu=1;
                        if(mainmenu==9)mainmenu=5;
-                       if(mainmenu==11)mainmenu=5;
-                       if(mainmenu==13)mainmenu=12;
                        if(mainmenu==10)mainmenu=5;
                        if(mainmenu==100){
                                mainmenu=5;
@@ -2835,23 +2459,13 @@ void    Game::Tick()
                        }
                        mainmenutogglekeydown=1;
                }
-               if(!IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
+               if(!Input::isKeyDown(SDLK_ESCAPE)){
                        mainmenutogglekeydown=0;
                }
        }
 
-       /*static bool minimaptogglekeydown;
-       if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown){
-       minimap=1-minimap;
-       minimaptogglekeydown=1;
-       }
-       if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
-       minimaptogglekeydown=0;
-       }
-       */
-
        static bool minimaptogglekeydown;
-       if(IsKeyDown(theKeyMap, MAC_TAB_KEY)&&!minimaptogglekeydown&&tutoriallevel){
+       if(Input::isKeyDown(SDLK_TAB)&&!minimaptogglekeydown&&tutoriallevel){
                if(tutorialstage!=51)
                        tutorialstagetime=tutorialmaxtime;
                PlaySoundEx( consolefailsound, samp[consolefailsound], NULL, true);
@@ -2859,46 +2473,26 @@ void    Game::Tick()
                OPENAL_SetPaused(channels[consolefailsound], false);
                minimaptogglekeydown=1;
        }
-       if(!IsKeyDown(theKeyMap, MAC_TAB_KEY)){
+       if(!Input::isKeyDown(SDLK_TAB)){
                minimaptogglekeydown=0;
        }
 
        if(mainmenu){
                //menu buttons
                if(mainmenu==1||mainmenu==2){
-                       if(Button()&&!oldbutton&&selected==1){
+                       if(Input::Button()&&!oldbutton&&selected==1){
                                if(!gameon){
-                                       float gLoc[3]={0,0,0};
-                                       float vel[3]={0,0,0};
-                                       OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                                       PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                                       OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                                       OPENAL_SetVolume(channels[firestartsound], 256);
-                                       OPENAL_SetPaused(channels[firestartsound], false);
-                                       OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                                       flashr=1;
-                                       flashg=0;
-                                       flashb=0;
-                                       flashamount=1;
-                                       flashdelay=1;
+                                       fireSound(firestartsound);
 
-                                       //new game
-                                       if(accountactive!=-1)mainmenu=5;
-                                       else mainmenu=7;
-                                       /*
-                                       startbonustotal=0;
+                                       flash();
 
-                                       loading=2;
-                                       loadtime=0;
-                                       if(firstload)TickOnceAfter();
-                                       if(!firstload)LoadStuff();
-                                       else {
-                                       Loadlevel(0);
+                                       //new game
+                                       if(accountactive) {
+                                               mainmenu=5;
+                                       } else {
+                                               mainmenu=7;
                                        }
-                                       mainmenu=0;
-                                       gameon=1;
-                                       OPENAL_SetPaused(channels[music3], true);       */
+                                       selected=-1;
                                }
                                else
                                {
@@ -2909,21 +2503,10 @@ void    Game::Tick()
                                }
                        }
 
-                       if(Button()&&!oldbutton&&selected==2){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==2){
+                               fireSound();
+
+                               flash();
 
                                //options
 
@@ -2937,21 +2520,10 @@ void    Game::Tick()
                                if(newscreenheight<0)newscreenheight=screenheight;
                        }
 
-                       if(Button()&&!oldbutton&&selected==3){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==3){
+                               fireSound();
+
+                               flash();
 
                                if(!gameon){
                                        //quit
@@ -2964,22 +2536,12 @@ void    Game::Tick()
                                        mainmenu=1;
                                }
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
-
                if(mainmenu==3){
-                       if(Button()&&!oldbutton&&selected!=-1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
+                       if(Input::Button()&&!oldbutton&&selected!=-1){
+                               fireSound();
                        }
-                       if(Button()&&!oldbutton&&selected==0){
+                       if(Input::Button()&&!oldbutton&&selected==0){
                        
                                extern SDL_Rect **resolutions;
                                bool isCustomResolution = true;
@@ -3027,25 +2589,25 @@ void    Game::Tick()
 
                                
                        }
-                       if(Button()&&!oldbutton&&selected==1){
+                       if(Input::Button()&&!oldbutton&&selected==1){
                                newdetail++;
                                if(newdetail>2)newdetail=0;
                        }
-                       if(Button()&&!oldbutton&&selected==2){
+                       if(Input::Button()&&!oldbutton&&selected==2){
                                bloodtoggle++;
                                if(bloodtoggle>2)bloodtoggle=0;
                        }
-                       if(Button()&&!oldbutton&&selected==3){
+                       if(Input::Button()&&!oldbutton&&selected==3){
                                difficulty++;
                                if(difficulty>2)difficulty=0;
                        }
-                       if(Button()&&!oldbutton&&selected==4){
+                       if(Input::Button()&&!oldbutton&&selected==4){
                                ismotionblur=1-ismotionblur;
                        }
-                       if(Button()&&!oldbutton&&selected==5){
+                       if(Input::Button()&&!oldbutton&&selected==5){
                                decals=1-decals;
                        }
-                       if(Button()&&!oldbutton&&selected==6){
+                       if(Input::Button()&&!oldbutton&&selected==6){
                                musictoggle=1-musictoggle;
 
                                if(!musictoggle){
@@ -3065,65 +2627,43 @@ void    Game::Tick()
                                        OPENAL_SetVolume(channels[stream_music3], 256);
                                }
                        }
-                       if(Button()&&!oldbutton&&selected==9){
+                       if(Input::Button()&&!oldbutton&&selected==9){
                                invertmouse=1-invertmouse;
                        }
-                       if(Button()&&!oldbutton&&selected==10){
+                       if(Input::Button()&&!oldbutton&&selected==10){
                                usermousesensitivity+=.2;
                                if(usermousesensitivity>2)usermousesensitivity=.2;
                        }
-                       if(Button()&&!oldbutton&&selected==11){
+                       if(Input::Button()&&!oldbutton&&selected==11){
                                volume+=.1f;
                                if(volume>1.0001f)volume=0;
                                OPENAL_SetSFXMasterVolume((int)(volume*255));
                        }
-                       if(Button()&&!oldbutton&&selected==7){
-                               /*float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
+                       if(Input::Button()&&!oldbutton&&selected==7){
+                               /*fireSound();
                                */
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                               flash();
 
                                //options
 
                                mainmenu=4;
+                               selected=-1;
                                keyselect=-1;
                        }
-                       if(Button() && !oldbutton && selected == 12) {
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button() && !oldbutton && selected == 12) {
+                               flash();
                                
                                newstereomode = stereomode;
                                mainmenu=18;
-                               keyselect = -1;
+                               keyselect=-1;
                        }
-                       if(Button()&&!oldbutton&&selected==8){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button() && !oldbutton && selected == 13) {
+                               showdamagebar=!showdamagebar;
+                       }
+                       if(Input::Button()&&!oldbutton&&selected==8){
+                               fireSound();
+
+                               flash();
 
                                if(newdetail>2)newdetail=detail;
                                if(newdetail<0)newdetail=detail;
@@ -3135,112 +2675,40 @@ void   Game::Tick()
                                if(mainmenu==3&&gameon)mainmenu=2;
                                if(mainmenu==3&&!gameon)mainmenu=1;
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
                if(mainmenu==4){
-                       if(Button()&&!oldbutton&&selected!=-1&&keyselect==-1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-                       }
-                       if(Button()&&!oldbutton&&selected<9&&keyselect==-1){
-                               keyselect=selected;
-                               oldbuttons[0]=1;
-                               oldbuttons[1]=1;
-                               oldbuttons[2]=1;
-                       }
-                       if(keyselect!=-1){
-                               for(i=0;i<3;i++)
-                                       if(!buttons[i]&&!oldbutton&&!Button())oldbuttons[i]=0;
-                               for(i=0;i<140;i++){
-                                       if((IsKeyDown(theKeyMap, i)||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))&&keyselect!=-1){
-                                               if(i!=MAC_ESCAPE_KEY&&(strcmp(KeyToChar(i),"unknown")||(buttons[0]&&!oldbuttons[0]&&!oldbutton)||(buttons[1]&&!oldbuttons[1]&&!oldbutton))){
-                                                       float gLoc[3]={0,0,0};
-                                                       float vel[3]={0,0,0};
-                                                       OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                       OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                       OPENAL_SetPaused(channels[fireendsound], false);
-                                                       OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                                                       int keynum;
-                                                       keynum=i;
-                                                       if(buttons[0]&&!oldbuttons[0])keynum=MAC_MOUSEBUTTON1;
-                                                       if(buttons[1]&&!oldbuttons[1])keynum=MAC_MOUSEBUTTON2;
-
-
-
-                                                       if(keyselect==0)forwardkey=keynum;
-                                                       if(keyselect==1)backkey=keynum;
-                                                       if(keyselect==2)leftkey=keynum;
-                                                       if(keyselect==3)rightkey=keynum;
-                                                       if(keyselect==4)crouchkey=keynum;
-                                                       if(keyselect==5)jumpkey=keynum;
-                                                       if(keyselect==6)drawkey=keynum;
-                                                       if(keyselect==7)throwkey=keynum;
-                                                       if(keyselect==8)attackkey=keynum;
-                                                       keyselect=-1;
-                                               }
-                                       }
-                               }}
-                       if(Button()&&!oldbutton&&selected==9){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
-
-                               mainmenu=3;
-
-                               if(newdetail>2)newdetail=detail;
-                               if(newdetail<0)newdetail=detail;
-                               if(newscreenwidth>3000)newscreenwidth=screenwidth;
-                               if(newscreenwidth<0)newscreenwidth=screenwidth;
-                               if(newscreenheight>3000)newscreenheight=screenheight;
-                               if(newscreenheight<0)newscreenheight=screenheight;
+                       if(Input::Button()&&!oldbutton&&selected!=-1&&!waiting){
+                               fireSound();
+                               if(selected<9&&keyselect==-1)
+                                       keyselect=selected;
+                               if(keyselect!=-1)
+                                       setKeySelected();
+                               if(selected==9){
+                                       flash();
+
+                                       mainmenu=3;
+
+                                       if(newdetail>2)newdetail=detail;
+                                       if(newdetail<0)newdetail=detail;
+                                       if(newscreenwidth>3000)newscreenwidth=screenwidth;
+                                       if(newscreenwidth<0)newscreenwidth=screenwidth;
+                                       if(newscreenheight>3000)newscreenheight=screenheight;
+                                       if(newscreenheight<0)newscreenheight=screenheight;
+                               }
                        }
                }
 
                if(mainmenu==5){
 
                        if(endgame==2){
-                               accountcampaignchoicesmade[accountactive]=0;
-                               accountcampaignscore[accountactive]=0;
-                               accountcampaigntime[accountactive]=0;
+                               accountactive->endGame();
                                endgame=0;
                        }
 
-                       if(Button()&&!oldbutton&&selected==1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==1){
+                               fireSound();
+
+                               flash();
 
                                startbonustotal=0;
 
@@ -3257,30 +2725,18 @@ void    Game::Tick()
                                gameon=1;
                                OPENAL_SetPaused(channels[stream_music3], true);
                        }
-                       if(Button()&&!oldbutton&&selected-7>=accountcampaignchoicesmade[accountactive]){//selected>=7&&(selected-7<=campaignnumchoices)){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&(selected-7>=accountactive->getCampaignChoicesMade())){
+                               fireSound();
+
+                               flash();
 
                                startbonustotal=0;
 
                                loading=2;
                                loadtime=0;
                                targetlevel=7;
-                               if(firstload)TickOnceAfter();
-                               if(!firstload)LoadStuff();
-                               //else {
+                               if(firstload) TickOnceAfter();
+                               else LoadStuff();
                                for(i=0;i<255;i++){
                                        mapname[i]='\0';
                                }
@@ -3295,164 +2751,52 @@ void   Game::Tick()
                                mapname[8]='p';
                                mapname[9]='s';
                                mapname[10]=':';
-                               strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountcampaignchoicesmade[accountactive]]]);
-                               whichchoice=selected-7-accountcampaignchoicesmade[accountactive];
+                               strcat(mapname,campaignmapname[campaignchoicewhich[selected-7-accountactive->getCampaignChoicesMade()]]);
+                               whichchoice=selected-7-accountactive->getCampaignChoicesMade();
                                visibleloading=1;
                                stillloading=1;
                                Loadlevel(mapname);
                                //Loadlevel(campaignmapname[levelorder[selected-7]]);
-                               //}
                                campaign=1;
                                mainmenu=0;
                                gameon=1;
                                OPENAL_SetPaused(channels[stream_music3], true);
                        }
-                       if(Button()&&!oldbutton&&selected==4){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==4){
+                               fireSound();
+
+                               flash();
 
                                if(mainmenu==5&&gameon)mainmenu=2;
                                if(mainmenu==5&&!gameon)mainmenu=1;
                        }
-                       if(Button()&&!oldbutton&&selected==5){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==5){
+                               fireSound();
+
+                               flash();
 
                                mainmenu=7;
                        }
-                       if(Button()&&!oldbutton&&selected==3){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==3){
+                               fireSound();
+
+                               flash();
 
                                mainmenu=6;
                        }
-                       if(Button()&&!oldbutton&&selected==2){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==2){
+                               fireSound();
+
+                               flash();
 
                                mainmenu=9;
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
                if(mainmenu==9){
-                       if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
-
-                               startbonustotal=0;
-
-                               loading=2;
-                               loadtime=0;
-                               targetlevel=selected;
-                               if(firstload)TickOnceAfter();
-                               if(!firstload)LoadStuff();
-                               else {
-                                       Loadlevel(selected);
-                               }
-                               campaign=0;
-
-                               mainmenu=0;
-                               gameon=1;
-                               OPENAL_SetPaused(channels[stream_music3], true);
-                       }
-                       if(Button()&&!oldbutton&&selected==numchallengelevels){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountactive->getProgress()){
+                               fireSound();
 
-                               mainmenu=5;
-                       }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
-               }
-               if(mainmenu==11){
-                       if(Button()&&!oldbutton&&selected<numchallengelevels&&selected>=0&&selected<=accountprogress[accountactive]){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                               flash();
 
                                startbonustotal=0;
 
@@ -3470,213 +2814,80 @@ void   Game::Tick()
                                gameon=1;
                                OPENAL_SetPaused(channels[stream_music3], true);
                        }
-                       if(Button()&&!oldbutton&&selected==numchallengelevels){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==numchallengelevels){
+                               fireSound();
+
+                               flash();
 
                                mainmenu=5;
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
                if(mainmenu==10){
                        endgame=2;
-                       if(Button()&&!oldbutton&&selected==3){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==3){
+                               fireSound();
+
+                               flash();
 
                                mainmenu=5;
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
 
                if(mainmenu==6){
-                       if(Button()&&!oldbutton&&selected!=-1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-                       }
-                       if(Button()&&!oldbutton&&selected==1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
-
-                               for(i=accountactive;i<numaccounts-1;i++){
-                                       accountdifficulty[i]=accountdifficulty[i+1];
-                                       accountcampaignchoicesmade[i]=accountcampaignchoicesmade[i+1];
-                                       for(j=0;j<accountcampaignchoicesmade[i+1];j++){
-                                               accountcampaignchoices[i][j]=accountcampaignchoices[i+1][j];
-                                       }
-                                       accountpoints[i]=accountpoints[i+1];
-                                       for(j=0;j<50;j++){
-                                               accounthighscore[i][j]=accounthighscore[i+1][j];
-                                               accountfasttime[i][j]=accountfasttime[i+1][j];
+                       if(Input::Button()&&!oldbutton) {
+                               if(selected>-1){
+                                       fireSound();
+                                       if(selected==1) {
+                                               flash();
+                                               accountactive = Account::destroy(accountactive);
+                                               mainmenu=7;
+                                       } else if(selected==2) {
+                                               flash();
+                                               mainmenu=5;
                                        }
-                                       for(j=0;j<60;j++){
-                                               accountunlocked[i][j]=accountunlocked[i+1][j];
-                                       }
-                                       for(j=0;j<256;j++){
-                                               accountname[i][j]=accountname[i+1][j];
-                                       }
-                                       accountcampaignhighscore[i]=accountcampaignhighscore[i+1];
-                                       accountprogress[i]=accountprogress[i+1];
-                                       accountcampaignfasttime[i]=accountcampaignfasttime[i+1];
-                                       accountcampaignscore[i]=accountcampaignscore[i+1];
-                                       accountcampaigntime[i]=accountcampaigntime[i+1];
                                }
-
-                               numaccounts--;
-                               accountactive=-1;
-
-
-                               mainmenu=7;
-                       }
-                       if(Button()&&!oldbutton&&selected==2){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
-
-                               mainmenu=5;
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
                if(mainmenu==7){
-                       if(Button()&&!oldbutton&&selected!=-1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-                       }
-                       if(Button()&&!oldbutton&&selected==0&&numaccounts<8){
-                               entername=1;
-                       }
-                       if(Button()&&!oldbutton&&selected>0&&selected<numaccounts+1){
-                               accountactive=selected-1;
-                               mainmenu=5;
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
-                       }
-                       if(Button()&&!oldbutton&&selected==numaccounts+1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[fireendsound], 256);
-                               OPENAL_SetPaused(channels[fireendsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
-
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
-
-                               mainmenu=1;
-
-                               for(j=0;j<255;j++){
-                                       displaytext[0][j]=' ';
+                       if(Input::Button()&&!oldbutton) {
+                               if(selected!=-1){
+                                       fireSound();
+                                       if(selected==0&&Account::getNbAccounts()<8){
+                                               entername=1;
+                                       } else if (selected<Account::getNbAccounts()+1) {
+                                               accountactive=Account::get(selected-1);
+                                               mainmenu=5;
+                                               flash();
+                                       } else if (selected==Account::getNbAccounts()+1) {
+                                               flash();
+
+                                               mainmenu=1;
+
+                                               for(j=0;j<255;j++){
+                                                       displaytext[0][j]=' ';
+                                               }
+                                               displaychars[0]=0;
+                                               displayselected=0;
+                                               entername=0;
+                                       }
                                }
-                               displaychars[0]=0;
-                               displayselected=0;
-                               entername=0;
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
                if(mainmenu==8){
-                       if(Button()&&!oldbutton&&selected!=-1){
-                               float gLoc[3]={0,0,0};
-                               float vel[3]={0,0,0};
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                               OPENAL_SetVolume(channels[firestartsound], 256);
-                               OPENAL_SetPaused(channels[firestartsound], false);
-                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                               if(selected==0)accountdifficulty[accountactive]=0;
-                               if(selected==1)accountdifficulty[accountactive]=1;
-                               if(selected==2)accountdifficulty[accountactive]=2;
+                       if(Input::Button()&&!oldbutton&&selected>-1){
+                               fireSound();
+
+                               if(selected<=2)
+                                       accountactive->setDifficulty(selected);
 
                                mainmenu=5;
 
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                               flash();
 
                        }
-                       if(Button())oldbutton=1;
-                       else oldbutton=0;
                }
-               if (mainmenu==18) {
-                       if(Button()&&!oldbutton) {
-                               printf("Button %i pressed\n", selected);
-                       }
-                       
-                       if(Button()&&!oldbutton&&selected==0) {
+               if (mainmenu==18) {                     
+                       if(Input::Button()&&!oldbutton&&selected==0) {
                                newstereomode = (StereoMode)(newstereomode + 1);
                                while(!CanInitStereo(newstereomode)) {
                                        printf("Failed to initialize mode %s (%i)\n", StereoModeName(newstereomode), newstereomode);
@@ -3687,39 +2898,32 @@ void    Game::Tick()
                                }
                        }
                        
-                       if(buttons[0]&&!oldbutton&&selected==1) {
+                       if(Input::isKeyDown(MOUSEBUTTON1)&&!oldbutton&&selected==1) {
                                stereoseparation+=0.001;
                        }
-                       if(buttons[1]&&!oldbutton&&selected==1) {
+                       if(Input::isKeyDown(MOUSEBUTTON2)&&!oldbutton&&selected==1) {
                                stereoseparation-=0.001;
                        }
 
-                       if(Button()&&!oldbutton&&selected==2) {
+                       if(Input::Button()&&!oldbutton&&selected==2) {
                                stereoreverse =! stereoreverse;
                        }
                        
-                       if(Button()&&!oldbutton&&selected==3) {
-                               flashr=1;
-                               flashg=0;
-                               flashb=0;
-                               flashamount=1;
-                               flashdelay=1;
+                       if(Input::Button()&&!oldbutton&&selected==3) {
+                               flash();
 
                                stereomode = newstereomode;
                                InitStereo(stereomode);
                                
                                mainmenu=3;
                        }
-                       
-                       if(Button() || buttons[1])oldbutton=1;
-                       else oldbutton=0;
                }
 
 
-               if(Button()||buttons[1])oldbutton=1;
+               if(Input::Button()||Input::isKeyDown(MOUSEBUTTON2))oldbutton=1;
                else oldbutton=0;
 
-               if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
+               if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
                        tryquit=1;
                        if(mainmenu==3){
                                if(newdetail>2)newdetail=detail;
@@ -3742,130 +2946,30 @@ void   Game::Tick()
                }
                OPENAL_SetFrequency(channels[stream_music3], 22050);
 
-               if(entername){
-                       for(i=0;i<140;i++){
-                               if(IsKeyDown(theKeyMap, i)){
-                                       togglekeydelay[i]+=multiplier;
-                                       if(togglekeydelay[i]>.4){
-                                               togglekey[i]=0;
-                                               togglekeydelay[i]=.36;
-                                       }
-                                       if(!togglekey[i]){
-                                               if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
-                                                       for(j=255;j>=displayselected+1;j--){
-                                                               displaytext[0][j]=displaytext[0][j-1];
-                                                       }
-                                                       displaytext[0][displayselected]=KeyToSingleChar(i);
-                                                       if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
-                                                       displayselected++;
-                                                       displaychars[0]++;
-                                               }
-                                               if(i==MAC_DELETE_KEY&&displayselected!=0){
-                                                       for(j=displayselected-1;j<255;j++){
-                                                               displaytext[0][j]=displaytext[0][j+1];
-                                                       }
-                                                       displaytext[0][255]=' ';
-                                                       displayselected--;
-                                                       displaychars[0]--;
-                                               }
-                                               if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
-                                                       displayselected--;
-                                               }
-                                               if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
-                                                       displayselected++;
-                                               }
-                                               if(i==MAC_RETURN_KEY&&entername){
-                                                       if(displaychars[0]){
-                                                               numaccounts++;
-                                                               strcpy(accountname[numaccounts-1],displaytext[0]);
-                                                               accountactive=numaccounts-1;
-                                                               accountdifficulty[accountactive]=1;
-                                                               accountprogress[accountactive]=0;
-                                                               accountpoints[accountactive]=0;
-                                                               accountcampaigntime[accountactive]=0;
-                                                               accountcampaignscore[accountactive]=0;
-                                                               accountcampaignfasttime[accountactive]=0;
-                                                               accountcampaignhighscore[accountactive]=0;
-                                                               for(j=0;j<50;j++){
-                                                                       accounthighscore[accountactive][j]=0;
-                                                                       accountfasttime[accountactive][j]=0;
-                                                               }
-                                                               for(j=0;j<60;j++){
-                                                                       accountunlocked[accountactive][j]=0;
-                                                               }
-                                                               accountcampaignchoicesmade[accountactive]=0;
+               if(entername) {
+                       inputText(displaytext[0],&displayselected,&displaychars[0]);
+                       if(!waiting) { // the input as finished
+                               if(displaychars[0]){ // with enter
+                                       accountactive = Account::add(string(displaytext[0]));
 
-                                                               for(j=0;j<255;j++){
-                                                                       displaytext[0][j]=' ';
-                                                               }
-                                                               displaychars[0]=0;
-                                                               displayselected=0;
-                                                               entername=0;
-
-                                                               mainmenu=8;
-
-                                                               flashr=1;
-                                                               flashg=0;
-                                                               flashb=0;
-                                                               flashamount=1;
-                                                               flashdelay=1;
-
-                                                               float gLoc[3]={0,0,0};
-                                                               float vel[3]={0,0,0};
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                                                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                                                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                                                               OPENAL_SetVolume(channels[firestartsound], 256);
-                                                               OPENAL_SetPaused(channels[firestartsound], false);
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                                                               for(j=0;j<255;j++){
-                                                                       displaytext[0][j]=' ';
-                                                               }
-                                                               displaychars[0]=0;
-
-
-                                                               displayselected=0;
-                                                       }}
-
-                                               if(i==MAC_RETURN_KEY&&mainmenu==13){
-                                                       if(displaychars[0]){
-                                                               sprintf (registrationname, "%s", displaytext[0]);
-                                                               if(displaychars[0]<254)registrationname[displaychars[0]]='\0';
-
-                                                               mainmenu=5;
-                        
-                                                               flashr=1;
-                                                               flashg=0;
-                                                               flashb=0;
-                                                               flashamount=1;
-                                                               flashdelay=1;
-
-                                                               float gLoc[3]={0,0,0};
-                                                               float vel[3]={0,0,0};
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                                                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                                                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                                                               OPENAL_SetVolume(channels[firestartsound], 256);
-                                                               OPENAL_SetPaused(channels[firestartsound], false);
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                                                               for(j=0;j<255;j++){
-                                                                       displaytext[0][j]=' ';
-                                                               }
-                                                               displaychars[0]=0;
-                        
-                                                               displayselected=0;
-                                                       }}
+                                       mainmenu=8;
+
+                                       flash();
+
+                                       fireSound(firestartsound);
+
+                                       for(i=0;i<255;i++){
+                                               displaytext[0][i]=' ';
                                        }
-                                       togglekey[i]=1;
-                               }
-                               else {
-                                       togglekey[i]=0;
-                                       togglekeydelay[i]=0;
+                                       displaychars[0]=0;
+
+                                       displayselected=0;
+                               } else { // with escape or empty
+                                       mainmenutogglekeydown=1;
                                }
+                               entername=0;
                        }
-
+                       
                        displayblinkdelay-=multiplier;
                        if(displayblinkdelay<=0){
                                displayblinkdelay=.3;
@@ -3878,80 +2982,33 @@ void    Game::Tick()
                if(hostile==1)hostiletime+=multiplier;
                else hostiletime=0;
                if(!winfreeze)leveltime+=multiplier;
-               if(IsKeyDown(theKeyMap, MAC_ESCAPE_KEY)){
+               if(Input::isKeyDown(SDLK_ESCAPE)){
                        chatting=0;
                        console=0;
                        freeze=0;
                        displaychars[0]=0;
                }
 
-               if(IsKeyDown(theKeyMap, chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
+               if(Input::isKeyDown(chatkey)&&!chattogglekeydown&&!console&&!chatting&&debugmode){
                        chatting=1;
                        chattogglekeydown=1;
-                       togglekey[chatkey]=1;
-                       togglekeydelay[chatkey]=-20;
                }
 
-               if(!IsKeyDown(theKeyMap, chatkey)){
+               if(!Input::isKeyDown(chatkey)){
                        chattogglekeydown=0;
                }
 
                if(chatting){
-                       for(i=0;i<140;i++){
-                               if(IsKeyDown(theKeyMap, i)){
-                                       togglekeydelay[i]+=multiplier;
-                                       if(togglekeydelay[i]>.4){
-                                               togglekey[i]=0;
-                                               togglekeydelay[i]=.36;
-                                       }
-                                       if(!togglekey[i]){
-                                               if(KeyToSingleChar(i)!='\0'&&displaychars[0]<60){
-                                                       for(j=255;j>=displayselected+1;j--){
-                                                               displaytext[0][j]=displaytext[0][j-1];
-                                                       }
-                                                       displaytext[0][displayselected]=KeyToSingleChar(i);
-                                                       if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))displaytext[0][displayselected]=Shift(displaytext[0][displayselected]);
-                                                       displayselected++;
-                                                       displaychars[0]++;
-                                               }
-                                               if(i==MAC_DELETE_KEY&&displayselected!=0){
-                                                       for(j=displayselected-1;j<255;j++){
-                                                               displaytext[0][j]=displaytext[0][j+1];
-                                                       }
-                                                       displaytext[0][255]=' ';
-                                                       displayselected--;
-                                                       displaychars[0]--;
-                                               }
-                                               if(i==MAC_ARROW_LEFT_KEY&&displayselected!=0){
-                                                       displayselected--;
-                                               }
-                                               if(i==MAC_ARROW_RIGHT_KEY&&displayselected<displaychars[0]){
-                                                       displayselected++;
-                                               }
-                                               if(i==MAC_RETURN_KEY){
-                                                       if(displaychars[0]){
-                                                               /*for(j=0;j<displaychars[0];j++){
-                                                               talkname[j]=displaytext[0][j];
-                                                               }
-                                                               talkname[displaychars[0]]='\0';
-                                                               sprintf (chatname, "%s: %s",playerName,talkname);
-                                                               //NetworkSendInformation(chatname);
-                                                               */
-                                                               for(j=0;j<255;j++){
-                                                                       displaytext[0][j]=' ';
-                                                               }
-                                                               displaychars[0]=0;
-                                                               displayselected=0;
-                                                               chatting=0;
-                                                       }
-                                               }
+                       inputText(displaytext[0],&displayselected,&displaychars[0]);
+                       if(!waiting) {
+                               if(displaychars[0]){
+                                       for(int j=0;j<255;j++){
+                                               displaytext[0][j]=' ';
                                        }
-                                       togglekey[i]=1;
-                               }
-                               else {
-                                       togglekey[i]=0;
-                                       togglekeydelay[i]=0;
-                               }
+                                       displaychars[0]=0;
+                                       displayselected=0;
+                               }       
+                               chatting=0;             
                        }
 
                        displayblinkdelay-=multiplier;
@@ -3963,7 +3020,7 @@ void      Game::Tick()
 
                if(chatting)keyboardfrozen=1;
 
-               if(IsKeyDown(theKeyMap, MAC_V_KEY)&&!freezetogglekeydown&&debugmode){
+               if(Input::isKeyDown(SDLK_v)&&!freezetogglekeydown&&debugmode){
                        freeze=1-freeze;
                        if(freeze){
                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
@@ -3971,105 +3028,45 @@ void   Game::Tick()
                        freezetogglekeydown=1;
                }
 
-               if(!IsKeyDown(theKeyMap, MAC_V_KEY)&&!IsKeyDown(theKeyMap, MAC_F1_KEY)){
+               if(!Input::isKeyDown(SDLK_v)&&!Input::isKeyDown(SDLK_F1)){
                        freezetogglekeydown=0;
                }
 
-               if(IsKeyDown(theKeyMap, MAC_TILDE_KEY)&&!consoletogglekeydown&&debugmode){
+               if(Input::isKeyDown(SDLK_BACKQUOTE)&&!consoletogglekeydown&&debugmode){
                        console=1-console;
-                       if(!console)freeze=0;
                        if(console){
                                OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+                       } else {
+                               freeze=0;
+                               waiting=false;
                        }
                        consoletogglekeydown=1;
                }
 
-               if(!IsKeyDown(theKeyMap, MAC_TILDE_KEY)){
+               if(!Input::isKeyDown(SDLK_BACKQUOTE)){
                        consoletogglekeydown=0;
                }
 
                if(console)freeze=1;
 
-               if(console&&!IsKeyDown(theKeyMap,MAC_COMMAND_KEY)){
-                       for(i=0;i<140;i++){
-                               if(IsKeyDown(theKeyMap, i)){
-                                       togglekeydelay[i]+=multiplier;
-                                       if(togglekeydelay[i]>.4){
-                                               togglekey[i]=0;
-                                               togglekeydelay[i]=.36;
-                                       }
-                                       if(!togglekey[i]){
-                                               if(KeyToSingleChar(i)!='\0'&&consolechars[0]<255){
-                                                       for(j=255;j>=consoleselected+1;j--){
-                                                               consoletext[0][j]=consoletext[0][j-1];
-                                                       }
-                                                       consoletext[0][consoleselected]=KeyToSingleChar(i);
-                                                       if(IsKeyDown(theKeyMap, MAC_SHIFT_KEY))consoletext[0][consoleselected]=Shift(consoletext[0][consoleselected]);
-                                                       consoleselected++;
-                                                       consolechars[0]++;
-                                               }
-                                               else if(i==MAC_ENTER_KEY){
-                                                       for(j=255;j>=consoleselected+1;j--){
-                                                               consoletext[0][j]=consoletext[0][j-1];
-                                                       }
-                                                       consoletext[0][consoleselected]='\n';
-                                                       consoleselected++;
-                                                       consolechars[0]++;
-                                               }
-                                               if(i==MAC_DELETE_KEY&&consoleselected!=0){
-                                                       for(j=consoleselected-1;j<255;j++){
-                                                               consoletext[0][j]=consoletext[0][j+1];
-                                                       }
-                                                       consoletext[0][255]=' ';
-                                                       consoleselected--;
-                                                       consolechars[0]--;
-                                               }
-                                               if(i==MAC_ARROW_UP_KEY){
-                                                       if(archiveselected<14)archiveselected++;
-                                                       for(j=0;j<255;j++){
-                                                               consolechars[0]=consolechars[archiveselected];
-                                                               consoletext[0][j]=consoletext[archiveselected][j];
-                                                               consoleselected=consolechars[0];
-                                                       }
-                                               }
-                                               if(i==MAC_ARROW_DOWN_KEY){
-                                                       if(archiveselected>0)archiveselected--;
-                                                       for(j=0;j<255;j++){
-                                                               consolechars[0]=consolechars[archiveselected];
-                                                               consoletext[0][j]=consoletext[archiveselected][j];
-                                                               consoleselected=consolechars[0];
-                                                       }
-                                               }
-                                               if(i==MAC_ARROW_LEFT_KEY&&consoleselected!=0){
-                                                       consoleselected--;
-                                               }
-                                               if(i==MAC_ARROW_RIGHT_KEY&&consoleselected<consolechars[0]){
-                                                       consoleselected++;
-                                               }
-                                               if(i==MAC_RETURN_KEY){
-                                                       archiveselected=0;
-                                                       cmd_dispatch(this, consoletext[0]);
-
-                                                       if(consolechars[0]>0){
-                                                               for(k=14;k>=1;k--){
-                                                                       for(j=0;j<255;j++){
-                                                                               consoletext[k][j]=consoletext[k-1][j];
-                                                                       }
-                                                                       consolechars[k]=consolechars[k-1];
-                                                               }
-                                                               for(j=0;j<255;j++){
-                                                                       consoletext[0][j]=' ';
-                                                               }
-                                                               consolechars[0]=0;
-                                                               consoleselected=0;
-                                                       }
+               if(console&&!Input::isKeyDown(SDLK_LMETA)){
+                       inputText(consoletext[0],&consoleselected,&consolechars[0]);
+                       if(!waiting) {
+                               archiveselected=0;
+                               cmd_dispatch(this, consoletext[0]);
+                               if(consolechars[0]>0){
+
+                                       for(k=14;k>=1;k--){
+                                               for(j=0;j<255;j++){
+                                                       consoletext[k][j]=consoletext[k-1][j];
                                                }
+                                               consolechars[k]=consolechars[k-1];
                                        }
-                                       togglekey[i]=1;
-                               }
-                               else {
-                                       togglekey[i]=0;
-                                       togglekeydelay[i]=0;
+                                       for(j=0;j<255;j++){
+                                               consoletext[0][j]=' ';
+                                       }
+                                       consolechars[0]=0;
+                                       consoleselected=0;
                                }
                        }
 
@@ -4080,7 +3077,7 @@ void      Game::Tick()
                        }
                }
 
-               if(IsKeyDown(theKeyMap, MAC_Q_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)){
+               if(Input::isKeyDown(SDLK_q)&&Input::isKeyDown(SDLK_LMETA)){
                        tryquit=1;
                        if(mainmenu==3){
                                if(newdetail>2)newdetail=detail;
@@ -4102,20 +3099,20 @@ void    Game::Tick()
                if(winfreeze==0)oldwinfreeze=winfreeze;
                else oldwinfreeze++;
 
-               if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))&&!oldjumpkeydown&&!campaign){
+               if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))&&!oldjumpkeydown&&!campaign){
                        if(winfreeze)winfreeze=0;
                        oldjumpkeydown=1;
                }
-               if((IsKeyDown(theKeyMap, MAC_ESCAPE_KEY))&&!campaign&&gameon){
+               if((Input::isKeyDown(SDLK_ESCAPE))&&!campaign&&gameon){
                        if(winfreeze){
                                mainmenu=9;
                                gameon=0;
                        }
                }
-               if((IsKeyDown(theKeyMap, jumpkey)||IsKeyDown(theKeyMap, MAC_SPACE_KEY))){
+               if((Input::isKeyDown(jumpkey)||Input::isKeyDown(SDLK_SPACE))){
                        oldjumpkeydown=1;
                }
-               if(!IsKeyDown(theKeyMap, jumpkey)&&!IsKeyDown(theKeyMap, MAC_SPACE_KEY))oldjumpkeydown=0;
+               if(!Input::isKeyDown(jumpkey)&&!Input::isKeyDown(SDLK_SPACE))oldjumpkeydown=0;
 
                if(!freeze&&!winfreeze&&!(mainmenu&&gameon)&&(gameon||!gamestarted)){
 
@@ -4153,7 +3150,7 @@ void      Game::Tick()
                                                        realdialoguetype=dialoguetype[i];
                                                        special=0;
                                                }
-                                               if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue))){
+                                               if((!hostile||(dialoguetype[i]>40&&dialoguetype[i]<50))&&realdialoguetype<numplayers&&realdialoguetype>0&&(dialoguegonethrough[i]==0||!special)&&(special||(Input::isKeyDown(attackkey)&&!oldbuttondialogue))){
                                                        if(findDistancefast(&player[0].coords,&player[realdialoguetype].coords)<6||player[realdialoguetype].howactive>=typedead1||(dialoguetype[i]>40&&dialoguetype[i]<50)){
                                                                whichdialogue=i;
                                                                for(j=0;j<numdialogueboxes[whichdialogue];j++){
@@ -4208,7 +3205,7 @@ void      Game::Tick()
                                                                        OPENAL_SetVolume(channels[whichsoundplay], 256);
                                                                        OPENAL_SetPaused(channels[whichsoundplay], false);
                                                                }
-                                                               if(IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=1;
+                                                               if(Input::isKeyDown(attackkey))oldbuttondialogue=1;
                                                        }
                                                }
                                        }
@@ -4232,7 +3229,7 @@ void      Game::Tick()
                                                                hotspotsprite=DoRotation(hotspotsprite,0,0,Random()%360);
                                                                hotspotsprite=DoRotation(hotspotsprite,0,Random()%360,0);
                                                                hotspotsprite+=hotspot[i];
-                                                               sprites.MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
+                                                               Sprite::MakeSprite(breathsprite, hotspotsprite, hotspotsprite*0, 1,0.5,0, 7, 0.4);
                                                                hotspotvisual[i]+=0.1/hotspotsize[i]/hotspotsize[i]/hotspotsize[i];
                                                        }
                                                }
@@ -4255,44 +3252,31 @@ void    Game::Tick()
                                                }
                                                if(tutorialstage==1){
                                                        tutorialmaxtime=5;
-                                               }
-                                               if(tutorialstage==2){
+                                               } else if(tutorialstage==2){
                                                        tutorialmaxtime=2;
-                                               }
-                                               if(tutorialstage==3){
+                                               } else if(tutorialstage==3){
                                                        tutorialmaxtime=600;
-                                               }
-                                               if(tutorialstage==4){
+                                               } else if(tutorialstage==4){
                                                        tutorialmaxtime=1000;
-                                               }
-                                               if(tutorialstage==5){
+                                               } else if(tutorialstage==5){
                                                        tutorialmaxtime=600;
-                                               }
-                                               if(tutorialstage==6){
+                                               } else if(tutorialstage==6){
                                                        tutorialmaxtime=600;
-                                               }
-                                               if(tutorialstage==7){
+                                               } else if(tutorialstage==7){
                                                        tutorialmaxtime=600;
-                                               }
-                                               if(tutorialstage==8){
+                                               } else if(tutorialstage==8){
                                                        tutorialmaxtime=600;
-                                               }
-                                               if(tutorialstage==9){
+                                               } else if(tutorialstage==9){
                                                        tutorialmaxtime=600;
-                                               }
-                                               if(tutorialstage==10){
+                                               } else if(tutorialstage==10){
                                                        tutorialmaxtime=2;
-                                               }
-                                               if(tutorialstage==11){
+                                               } else if(tutorialstage==11){
                                                        tutorialmaxtime=1000;
-                                               }
-                                               if(tutorialstage==12){
+                                               } else if(tutorialstage==12){
                                                        tutorialmaxtime=1000;
-                                               }
-                                               if(tutorialstage==13){
+                                               } else if(tutorialstage==13){
                                                        tutorialmaxtime=2;
-                                               }
-                                               if(tutorialstage==14){
+                                               } else if(tutorialstage==14){
                                                        tutorialmaxtime=3;
 
                                                        XYZ temp,temp2;
@@ -4325,111 +3309,86 @@ void   Game::Tick()
                                                                        if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
                                                                        if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
                                                                        if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
+                                                                       Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                }
                                                        }
 
-                                               }
-                                               if(tutorialstage==15){
+                                               } else if(tutorialstage==15){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==16){
+                                               } else if(tutorialstage==16){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==17){
+                                               } else if(tutorialstage==17){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==18){
+                                               } else if(tutorialstage==18){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==19){
+                                               } else if(tutorialstage==19){
                                                        tutorialstage=20;
                                                        //tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==20){
+                                               } else if(tutorialstage==20){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==21){
+                                               } else if(tutorialstage==21){
                                                        tutorialmaxtime=500;
                                                        if(bonus==cannon){
                                                                bonus=Slicebonus;
                                                                againbonus=1;
                                                        }
                                                        else againbonus=0;
-                                               }
-                                               if(tutorialstage==22){
+                                               } else if(tutorialstage==22){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==23){
+                                               } else if(tutorialstage==23){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==24){
+                                               } else if(tutorialstage==24){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==25){
+                                               } else if(tutorialstage==25){
                                                        tutorialmaxtime=500;
-                                               }
-                                               if(tutorialstage==26){
+                                               } else if(tutorialstage==26){
                                                        tutorialmaxtime=2;
-                                               }
-                                               if(tutorialstage==27){
+                                               } else if(tutorialstage==27){
                                                        tutorialmaxtime=4;
                                                        reversaltrain=1;
                                                        cananger=1;
                                                        player[1].aitype=attacktypecutoff;
-                                               }
-                                               if(tutorialstage==28){
+                                               } else if(tutorialstage==28){
                                                        tutorialmaxtime=400;
-                                               }
-                                               if(tutorialstage==29){
+                                               } else if(tutorialstage==29){
                                                        tutorialmaxtime=400;
                                                        player[0].escapednum=0;
-                                               }
-                                               if(tutorialstage==30){
+                                               } else if(tutorialstage==30){
                                                        tutorialmaxtime=4;
                                                        reversaltrain=0;
                                                        cananger=0;
                                                        player[1].aitype=passivetype;
-                                               }
-                                               if(tutorialstage==31){
+                                               } else if(tutorialstage==31){
                                                        tutorialmaxtime=13;
-                                               }
-                                               if(tutorialstage==32){
+                                               } else if(tutorialstage==32){
                                                        tutorialmaxtime=8;
-                                               }
-                                               if(tutorialstage==33){
+                                               } else if(tutorialstage==33){
                                                        tutorialmaxtime=400;
                                                        cananger=1;
                                                        canattack=1;
                                                        player[1].aitype=attacktypecutoff;
-                                               }
-                                               if(tutorialstage==34){
+                                               } else if(tutorialstage==34){
                                                        tutorialmaxtime=400;
-                                               }
-                                               if(tutorialstage==35){
+                                               } else if(tutorialstage==35){
                                                        tutorialmaxtime=400;
-                                               }
-                                               if(tutorialstage==36){
+                                               } else if(tutorialstage==36){
                                                        tutorialmaxtime=2;
                                                        reversaltrain=0;
                                                        cananger=0;
                                                        player[1].aitype=passivetype;
-                                               }
-                                               if(tutorialstage==37){
+                                               } else if(tutorialstage==37){
                                                        damagedealt=0;
                                                        damagetaken=0;
                                                        tutorialmaxtime=50;
                                                        cananger=1;
                                                        canattack=1;
                                                        player[1].aitype=attacktypecutoff;
-                                               }
-                                               if(tutorialstage==38){
+                                               } else if(tutorialstage==38){
                                                        tutorialmaxtime=4;
                                                        canattack=0;
                                                        cananger=0;
                                                        player[1].aitype=passivetype;
-                                               }
-                                               if(tutorialstage==39){
+                                               } else if(tutorialstage==39){
                                                        XYZ temp,temp2;
 
                                                        temp.x=1011;
@@ -4458,20 +3417,15 @@ void    Game::Tick()
                                                        weapons.physics[weapons.numweapons]=1;
 
                                                        weapons.numweapons++;
-                                               }
-                                               if(tutorialstage==40){
+                                               } else if(tutorialstage==40){
                                                        tutorialmaxtime=300;
-                                               }
-                                               if(tutorialstage==41){
+                                               } else if(tutorialstage==41){
                                                        tutorialmaxtime=300;
-                                               }
-                                               if(tutorialstage==42){
+                                               } else if(tutorialstage==42){
                                                        tutorialmaxtime=8;
-                                               }
-                                               if(tutorialstage==43){
+                                               } else if(tutorialstage==43){
                                                        tutorialmaxtime=300;
-                                               }
-                                               if(tutorialstage==44){
+                                               } else if(tutorialstage==44){
                                                        weapons.owner[0]=1;
                                                        player[0].weaponactive=-1;
                                                        player[0].num_weapons=0;
@@ -4484,8 +3438,7 @@ void      Game::Tick()
                                                        player[1].aitype=attacktypecutoff;
 
                                                        tutorialmaxtime=300;
-                                               }
-                                               if(tutorialstage==45){
+                                               } else if(tutorialstage==45){
                                                        weapons.owner[0]=1;
                                                        player[0].weaponactive=-1;
                                                        player[0].num_weapons=0;
@@ -4494,8 +3447,7 @@ void      Game::Tick()
                                                        player[1].weaponids[0]=0;
 
                                                        tutorialmaxtime=300;
-                                               }
-                                               if(tutorialstage==46){
+                                               } else if(tutorialstage==46){
                                                        weapons.owner[0]=1;
                                                        player[0].weaponactive=-1;
                                                        player[0].num_weapons=0;
@@ -4506,9 +3458,7 @@ void      Game::Tick()
                                                        weapons.type[0]=sword;
 
                                                        tutorialmaxtime=300;
-                                               }
-
-                                               if(tutorialstage==47){
+                                               } else if(tutorialstage==47){
                                                        tutorialmaxtime=10;
 
                                                        XYZ temp,temp2;
@@ -4547,8 +3497,7 @@ void      Game::Tick()
                                                        player[1].weaponids[0]=0;
 
                                                        weapons.numweapons++;
-                                               }
-                                               if(tutorialstage==48){
+                                               } else if(tutorialstage==48){
                                                        canattack=0;
                                                        cananger=0;
                                                        player[1].aitype=passivetype;
@@ -4568,8 +3517,7 @@ void      Game::Tick()
                                                        else weapons.type[0]=staff;
 
                                                        weapons.numweapons++;
-                                               }
-                                               if(tutorialstage==49){
+                                               } else if(tutorialstage==49){
                                                        canattack=0;
                                                        cananger=0;
                                                        player[1].aitype=passivetype;
@@ -4590,8 +3538,7 @@ void      Game::Tick()
                                                        weapons.type[0]=knife;
 
                                                        weapons.numweapons++;
-                                               }
-                                               if(tutorialstage==50){
+                                               } else if(tutorialstage==50){
                                                        tutorialmaxtime=8;
 
                                                        XYZ temp,temp2;
@@ -4614,7 +3561,7 @@ void      Game::Tick()
                                                                        if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
                                                                        if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
                                                                        if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
+                                                                       Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                }
                                                        }
 
@@ -4632,8 +3579,7 @@ void      Game::Tick()
                                                        weapons.freetime[0]=0;
                                                        weapons.firstfree[0]=1;
                                                        weapons.physics[0]=1;
-                                               }
-                                               if(tutorialstage==51){
+                                               } else if(tutorialstage==51){
                                                        tutorialmaxtime=80000;
                                                }
                                                if(tutorialstage<=51)tutorialstagetime=0;
@@ -4803,7 +3749,7 @@ void      Game::Tick()
                                                                footpoint.y+=((float)abs(Random()%1200))/100-6;
                                                                footpoint.x+=((float)abs(Random()%1200))/100-6;
                                                                footpoint.z+=((float)abs(Random()%1200))/100-6;
-                                                               sprites.MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
+                                                               Sprite::MakeSprite(snowsprite, footpoint,footvel, 1,1,1, .1, 1);
                                                        }
                                                }
                                                for(k=0;k<numplayers;k++){
@@ -5231,14 +4177,14 @@ void    Game::Tick()
                                                static XYZ oldviewer;
 
                                                if(indialogue==-1){
-                                                       player[0].forwardkeydown=IsKeyDown(theKeyMap, forwardkey);
-                                                       player[0].leftkeydown=IsKeyDown(theKeyMap, leftkey);
-                                                       player[0].backkeydown=IsKeyDown(theKeyMap, backkey);
-                                                       player[0].rightkeydown=IsKeyDown(theKeyMap, rightkey);
-                                                       player[0].jumpkeydown=IsKeyDown(theKeyMap, jumpkey);
-                                                       player[0].crouchkeydown=IsKeyDown(theKeyMap, crouchkey);
-                                                       player[0].drawkeydown=IsKeyDown(theKeyMap, drawkey);
-                                                       player[0].throwkeydown=IsKeyDown(theKeyMap, throwkey);
+                                                       player[0].forwardkeydown=Input::isKeyDown(forwardkey);
+                                                       player[0].leftkeydown=Input::isKeyDown(leftkey);
+                                                       player[0].backkeydown=Input::isKeyDown(backkey);
+                                                       player[0].rightkeydown=Input::isKeyDown(rightkey);
+                                                       player[0].jumpkeydown=Input::isKeyDown(jumpkey);
+                                                       player[0].crouchkeydown=Input::isKeyDown(crouchkey);
+                                                       player[0].drawkeydown=Input::isKeyDown(drawkey);
+                                                       player[0].throwkeydown=Input::isKeyDown(throwkey);
                                                }
                                                else
                                                {
@@ -5270,27 +4216,27 @@ void    Game::Tick()
 
                                                                flatfacing=DoRotation(flatfacing,0,-rotation,0);
 
-                                                               if(IsKeyDown(theKeyMap, forwardkey))viewer+=facing*multiplier*4;
-                                                               if(IsKeyDown(theKeyMap, backkey))viewer-=facing*multiplier*4;
-                                                               if(IsKeyDown(theKeyMap, leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
-                                                               if(IsKeyDown(theKeyMap, rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
-                                                               if(IsKeyDown(theKeyMap, jumpkey))viewer.y+=multiplier*4;
-                                                               if(IsKeyDown(theKeyMap, crouchkey))viewer.y-=multiplier*4;
-                                                               if(!endkeydown&&(IsKeyDown(theKeyMap, MAC_1_KEY)||IsKeyDown(theKeyMap, MAC_2_KEY)||IsKeyDown(theKeyMap, MAC_3_KEY)||IsKeyDown(theKeyMap, MAC_4_KEY)||IsKeyDown(theKeyMap, MAC_5_KEY)
-                                                                       ||IsKeyDown(theKeyMap, MAC_6_KEY)||IsKeyDown(theKeyMap, MAC_7_KEY)||IsKeyDown(theKeyMap, MAC_8_KEY)||IsKeyDown(theKeyMap, MAC_9_KEY)||IsKeyDown(theKeyMap, MAC_0_KEY)
-                                                                       ||IsKeyDown(theKeyMap, MAC_MINUS_KEY))){
+                                                               if(Input::isKeyDown(forwardkey))viewer+=facing*multiplier*4;
+                                                               if(Input::isKeyDown(backkey))viewer-=facing*multiplier*4;
+                                                               if(Input::isKeyDown(leftkey))viewer+=DoRotation(flatfacing*multiplier,0,90,0)*4;
+                                                               if(Input::isKeyDown(rightkey))viewer+=DoRotation(flatfacing*multiplier,0,-90,0)*4;
+                                                               if(Input::isKeyDown(jumpkey))viewer.y+=multiplier*4;
+                                                               if(Input::isKeyDown(crouchkey))viewer.y-=multiplier*4;
+                                                               if(!endkeydown&&(Input::isKeyDown(SDLK_1)||Input::isKeyDown(SDLK_2)||Input::isKeyDown(SDLK_3)||Input::isKeyDown(SDLK_4)||Input::isKeyDown(SDLK_5)
+                                                                       ||Input::isKeyDown(SDLK_6)||Input::isKeyDown(SDLK_7)||Input::isKeyDown(SDLK_8)||Input::isKeyDown(SDLK_9)||Input::isKeyDown(SDLK_0)
+                                                                       ||Input::isKeyDown(SDLK_MINUS))){
                                                                                int whichend;
-                                                                               if(IsKeyDown(theKeyMap, MAC_1_KEY))whichend=1;
-                                                                               if(IsKeyDown(theKeyMap, MAC_2_KEY))whichend=2;
-                                                                               if(IsKeyDown(theKeyMap, MAC_3_KEY))whichend=3;
-                                                                               if(IsKeyDown(theKeyMap, MAC_4_KEY))whichend=4;
-                                                                               if(IsKeyDown(theKeyMap, MAC_5_KEY))whichend=5;
-                                                                               if(IsKeyDown(theKeyMap, MAC_6_KEY))whichend=6;
-                                                                               if(IsKeyDown(theKeyMap, MAC_7_KEY))whichend=7;
-                                                                               if(IsKeyDown(theKeyMap, MAC_8_KEY))whichend=8;
-                                                                               if(IsKeyDown(theKeyMap, MAC_9_KEY))whichend=9;
-                                                                               if(IsKeyDown(theKeyMap, MAC_0_KEY))whichend=0;
-                                                                               if(IsKeyDown(theKeyMap, MAC_MINUS_KEY))whichend=-1;
+                                                                               if(Input::isKeyDown(SDLK_1))whichend=1;
+                                                                               if(Input::isKeyDown(SDLK_2))whichend=2;
+                                                                               if(Input::isKeyDown(SDLK_3))whichend=3;
+                                                                               if(Input::isKeyDown(SDLK_4))whichend=4;
+                                                                               if(Input::isKeyDown(SDLK_5))whichend=5;
+                                                                               if(Input::isKeyDown(SDLK_6))whichend=6;
+                                                                               if(Input::isKeyDown(SDLK_7))whichend=7;
+                                                                               if(Input::isKeyDown(SDLK_8))whichend=8;
+                                                                               if(Input::isKeyDown(SDLK_9))whichend=9;
+                                                                               if(Input::isKeyDown(SDLK_0))whichend=0;
+                                                                               if(Input::isKeyDown(SDLK_MINUS))whichend=-1;
                                                                                if(whichend!=-1){
                                                                                        participantfocus[whichdialogue][indialogue]=whichend;
                                                                                        participantlocation[whichdialogue][whichend]=player[whichend].coords;
@@ -5357,25 +4303,25 @@ void    Game::Tick()
 
                                                                                endkeydown=1;
                                                                        }
-                                                                       if((IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY)
-                                                                               ||IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY)||IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY)
+                                                                       if((Input::isKeyDown(SDLK_KP1)||Input::isKeyDown(SDLK_KP2)||Input::isKeyDown(SDLK_KP3)||Input::isKeyDown(SDLK_KP4)||Input::isKeyDown(SDLK_KP5)
+                                                                               ||Input::isKeyDown(SDLK_KP6)||Input::isKeyDown(SDLK_KP7)||Input::isKeyDown(SDLK_KP8)||Input::isKeyDown(SDLK_KP9)||Input::isKeyDown(SDLK_KP0)
                                                                                )){
                                                                                        int whichend;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_1_KEY))whichend=1;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_2_KEY))whichend=2;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_3_KEY))whichend=3;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_4_KEY))whichend=4;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_5_KEY))whichend=5;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_6_KEY))whichend=6;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_7_KEY))whichend=7;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_8_KEY))whichend=8;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_9_KEY))whichend=9;
-                                                                                       if(IsKeyDown(theKeyMap, MAC_NUMPAD_0_KEY))whichend=0;
+                                                                                       if(Input::isKeyDown(SDLK_KP1))whichend=1;
+                                                                                       if(Input::isKeyDown(SDLK_KP2))whichend=2;
+                                                                                       if(Input::isKeyDown(SDLK_KP3))whichend=3;
+                                                                                       if(Input::isKeyDown(SDLK_KP4))whichend=4;
+                                                                                       if(Input::isKeyDown(SDLK_KP5))whichend=5;
+                                                                                       if(Input::isKeyDown(SDLK_KP6))whichend=6;
+                                                                                       if(Input::isKeyDown(SDLK_KP7))whichend=7;
+                                                                                       if(Input::isKeyDown(SDLK_KP8))whichend=8;
+                                                                                       if(Input::isKeyDown(SDLK_KP9))whichend=9;
+                                                                                       if(Input::isKeyDown(SDLK_KP0))whichend=0;
                                                                                        participantfacing[whichdialogue][indialogue][whichend]=facing;
                                                                                }
-                                                                               if(!IsKeyDown(theKeyMap, MAC_1_KEY)&&!IsKeyDown(theKeyMap, MAC_2_KEY)&&!IsKeyDown(theKeyMap, MAC_3_KEY)&&!IsKeyDown(theKeyMap, MAC_4_KEY)&&!IsKeyDown(theKeyMap, MAC_5_KEY)
-                                                                                       &&!IsKeyDown(theKeyMap, MAC_6_KEY)&&!IsKeyDown(theKeyMap, MAC_7_KEY)&&!IsKeyDown(theKeyMap, MAC_8_KEY)&&!IsKeyDown(theKeyMap, MAC_9_KEY)&&!IsKeyDown(theKeyMap, MAC_0_KEY)
-                                                                                       &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
+                                                                               if(!Input::isKeyDown(SDLK_1)&&!Input::isKeyDown(SDLK_2)&&!Input::isKeyDown(SDLK_3)&&!Input::isKeyDown(SDLK_4)&&!Input::isKeyDown(SDLK_5)
+                                                                                       &&!Input::isKeyDown(SDLK_6)&&!Input::isKeyDown(SDLK_7)&&!Input::isKeyDown(SDLK_8)&&!Input::isKeyDown(SDLK_9)&&!Input::isKeyDown(SDLK_0)
+                                                                                       &&!Input::isKeyDown(SDLK_MINUS)){
                                                                                                endkeydown=0;
                                                                                        }
                                                                                        if(indialogue>=numdialogueboxes[whichdialogue]){
@@ -5393,9 +4339,9 @@ void      Game::Tick()
                                                                rotation=dialoguecamerarotation[whichdialogue][indialogue];
                                                                rotation2=dialoguecamerarotation2[whichdialogue][indialogue];
                                                                if(dialoguetime>0.5)
-                                                                       if((!endkeydown&&(IsKeyDown(theKeyMap, MAC_1_KEY)||IsKeyDown(theKeyMap, MAC_2_KEY)||IsKeyDown(theKeyMap, MAC_3_KEY)||IsKeyDown(theKeyMap, MAC_4_KEY)||IsKeyDown(theKeyMap, MAC_5_KEY)
-                                                                               ||IsKeyDown(theKeyMap, MAC_6_KEY)||IsKeyDown(theKeyMap, MAC_7_KEY)||IsKeyDown(theKeyMap, MAC_8_KEY)||IsKeyDown(theKeyMap, MAC_9_KEY)||IsKeyDown(theKeyMap, MAC_0_KEY)
-                                                                               ||IsKeyDown(theKeyMap, MAC_MINUS_KEY)))||(IsKeyDown(theKeyMap, attackkey)&&!oldbuttondialogue)){
+                                                                       if((!endkeydown&&(Input::isKeyDown(SDLK_1)||Input::isKeyDown(SDLK_2)||Input::isKeyDown(SDLK_3)||Input::isKeyDown(SDLK_4)||Input::isKeyDown(SDLK_5)
+                                                                               ||Input::isKeyDown(SDLK_6)||Input::isKeyDown(SDLK_7)||Input::isKeyDown(SDLK_8)||Input::isKeyDown(SDLK_9)||Input::isKeyDown(SDLK_0)
+                                                                               ||Input::isKeyDown(SDLK_MINUS)))||(Input::isKeyDown(attackkey)&&!oldbuttondialogue)){
                                                                                        indialogue++;
                                                                                        endkeydown=1;
                                                                                        if(indialogue<numdialogueboxes[whichdialogue]){
@@ -5460,9 +4406,9 @@ void      Game::Tick()
                                                                                                }
                                                                                        }
                                                                                }
-                                                                               if(!IsKeyDown(theKeyMap, MAC_1_KEY)&&!IsKeyDown(theKeyMap, MAC_2_KEY)&&!IsKeyDown(theKeyMap, MAC_3_KEY)&&!IsKeyDown(theKeyMap, MAC_4_KEY)&&!IsKeyDown(theKeyMap, MAC_5_KEY)
-                                                                                       &&!IsKeyDown(theKeyMap, MAC_6_KEY)&&!IsKeyDown(theKeyMap, MAC_7_KEY)&&!IsKeyDown(theKeyMap, MAC_8_KEY)&&!IsKeyDown(theKeyMap, MAC_9_KEY)&&!IsKeyDown(theKeyMap, MAC_0_KEY)
-                                                                                       &&!IsKeyDown(theKeyMap, MAC_MINUS_KEY)){
+                                                                               if(!Input::isKeyDown(SDLK_1)&&!Input::isKeyDown(SDLK_2)&&!Input::isKeyDown(SDLK_3)&&!Input::isKeyDown(SDLK_4)&&!Input::isKeyDown(SDLK_5)
+                                                                                       &&!Input::isKeyDown(SDLK_6)&&!Input::isKeyDown(SDLK_7)&&!Input::isKeyDown(SDLK_8)&&!Input::isKeyDown(SDLK_9)&&!Input::isKeyDown(SDLK_0)
+                                                                                       &&!Input::isKeyDown(SDLK_MINUS)){
                                                                                                endkeydown=0;
                                                                                        }
                                                                                        if(indialogue>=numdialogueboxes[whichdialogue]){
@@ -5485,119 +4431,10 @@ void   Game::Tick()
                                                        }
                                                }
 
-                                               if(!IsKeyDown(theKeyMap, attackkey))oldbuttondialogue=0;
+                                               if(!Input::isKeyDown(attackkey))oldbuttondialogue=0;
                                                else oldbuttondialogue=1;
 
-                                               static float keyrefreshdelay=0,bigrefreshdelay=0;
-
-                                               //Net updates
-
-                                               /*keyrefreshdelay-=multiplier;
-                                               bigrefreshdelay-=multiplier;
-
-                                               if(keyrefreshdelay<=0){
-                                               static int concat[4];
-
-                                               concat[0]=player[0].forwardkeydown;
-                                               concat[0]=concat[0]*2+player[0].forwardstogglekeydown;
-                                               concat[0]=concat[0]*2+player[0].rightkeydown;
-                                               concat[0]=concat[0]*2+player[0].leftkeydown;
-                                               concat[0]=concat[0]*2+player[0].backkeydown;
-                                               concat[0]=concat[0]*2+player[0].jumpkeydown;
-                                               concat[0]=concat[0]*2+player[0].jumptogglekeydown;
-                                               concat[0]=concat[0]*2+player[0].crouchkeydown;
-
-                                               concat[1]=player[0].crouchtogglekeydown;
-                                               concat[1]=concat[1]*2+player[0].drawkeydown;
-                                               concat[1]=concat[1]*2+player[0].drawtogglekeydown;
-                                               concat[1]=concat[1]*2+player[0].throwkeydown;
-                                               concat[1]=concat[1]*2+player[0].throwtogglekeydown;
-                                               concat[1]=concat[1]*2+player[0].attackkeydown;
-
-                                               //concat[2]=(char)((int)(rotation/2)%180);
-
-                                               //concat[3]=(char)((int)(rotation2/2)%180);
-
-                                               chatname[0]=concat[0]-128;
-                                               chatname[1]=concat[1]-128;
-                                               //chatname[2]=concat[2]-128;
-                                               //chatname[3]=concat[3]-128;
-                                               int temppoint=2;
-                                               memcpy(chatname+temppoint,&rotation,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&rotation2,sizeof(float));
-                                               temppoint+=sizeof(float);
-
-                                               chatname[temppoint]='\0';
-
-                                               //if(!ishost)NetworkSendPlayerMessage( chatname, kMessageType_Keys );
-                                               //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_Keys );
-                                               //keyrefreshdelay=.01;
-                                               keyrefreshdelay=.03;
-                                               }
-
-                                               if(bigrefreshdelay<=0){
-                                               for(i=0;i<1;i++){
-                                               /*int temppoint=0;
-                                               memcpy(chatname+temppoint,&i,sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].coords.x,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].coords.y,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].coords.z,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].damage,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].target,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].targetanimation,sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].currentanimation,sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].velocity.x,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].velocity.y,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].velocity.z,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].targetframe,sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].currentframe,sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].rotation,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].targetrotation,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].bloodloss,sizeof(float));
-                                               temppoint+=sizeof(float);
-                                               memcpy(chatname+temppoint,&player[i].weaponactive,sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].num_weapons,sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].weaponids[0],sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].weaponids[1],sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].weaponids[2],sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               memcpy(chatname+temppoint,&player[i].weaponids[3],sizeof(int));
-                                               temppoint+=sizeof(int);
-                                               chatname[temppoint]='\0';
-
-                                               sprintf (chatname, "%d %f %f %f %f %f %d %d %f %f %f %d %d %f %f %f",i,player[i].coords.x,player[i].coords.y,player[i].coords.z,player[i].damage,player[i].target, player[i].targetanimation, player[i].currentanimation, player[i].velocity.x, player[i].velocity.y, player[i].velocity.z, player[i].targetframe, player[i].currentframe, player[i].rotation, player[i].targetrotation);
-                                               //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerState );
-                                               //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerState );
-
-                                               sprintf (chatname, "%d %f %d %d %d %d %d %d %d %d %f",i,player[i].bloodloss, player[i].weaponactive, player[i].num_weapons, player[i].weaponids[0], player[i].weaponids[1], player[i].weaponids[2], player[i].weaponids[3],player[i].dead,player[i].skeleton.free,player[i].permanentdamage);
-
-                                               //if(ishost)NetworkSendPlayerRelayMessage( chatname, kMessageType_PlayerStateMisc );
-                                               //else NetworkSendPlayerMessage( chatname, kMessageType_PlayerStateMisc );
-                                               }
-                                               //bigrefreshdelay=.02;
-                                               bigrefreshdelay=.1;
-                                               }
-                                               }*/
+                                               static float keyrefreshdelay=0,bigrefreshdelay=0;
 
                                                if(!player[0].jumpkeydown){
                                                        player[0].jumptogglekeydown=0;
@@ -5633,20 +4470,15 @@ void    Game::Tick()
                                                static float temptexdetail;
 
 
-                                               if(IsKeyDown(theKeyMap, MAC_H_KEY)&&debugmode){
+                                               if(Input::isKeyDown(SDLK_h)&&debugmode){
                                                        player[0].damagetolerance=200000;
                                                        player[0].damage=0;
                                                        player[0].burnt=0;
                                                        player[0].permanentdamage=0;
                                                        player[0].superpermanentdamage=0;
-                                                       /*
-                                                       int whichchar;
-                                                       whichchar = abs(Random()%7);
-                                                       registrationname[whichchar]+=1;
-                                                       */
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_J_KEY)&&!envtogglekeydown&&debugmode){
+                                               if(Input::isKeyDown(SDLK_j)&&!envtogglekeydown&&debugmode){
                                                        environment++;
                                                        if(environment>2)environment=0;
                                                        Setenvironment(environment);
@@ -5655,20 +4487,20 @@ void    Game::Tick()
                                                }
 
 
-                                               if(!IsKeyDown(theKeyMap, MAC_J_KEY)){
+                                               if(!Input::isKeyDown(SDLK_j)){
                                                        envtogglekeydown=0;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_C_KEY)&&!cameratogglekeydown&&debugmode){
+                                               if(Input::isKeyDown(SDLK_c)&&!cameratogglekeydown&&debugmode){
                                                        cameramode=1-cameramode;
                                                        cameratogglekeydown=1;
                                                }
 
-                                               if(!IsKeyDown(theKeyMap, MAC_C_KEY)){
+                                               if(!Input::isKeyDown(SDLK_c)){
                                                        cameratogglekeydown=0;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_X_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
+                                               if(Input::isKeyDown(SDLK_x)&&!Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){
                                                        if(player[0].num_weapons>0){
                                                                if(weapons.type[player[0].weaponids[0]]==sword)weapons.type[player[0].weaponids[0]]=staff;
                                                                else if(weapons.type[player[0].weaponids[0]]==staff)weapons.type[player[0].weaponids[0]]=knife;
@@ -5690,20 +4522,10 @@ void    Game::Tick()
                                                                        weapons.length[player[0].weaponids[0]]=.25;
                                                                }
                                                        }
-
-                                                       /*for(i=0;i<objects.numobjects;i++){
-                                                       if(objects.type[i]==treeleavestype){
-                                                       for(j=0;j<objects.numobjects;j++){
-                                                       if(objects.type[j]==treetrunktype)
-                                                       if(findDistancefast(&objects.position[i],&objects.position[j])<.5)
-                                                       objects.scale[i]=objects.scale[j];
-                                                       }
-                                                       }
-                                                       }*/
                                                        detailtogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_X_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!detailtogglekeydown&&debugmode){
+                                               if(Input::isKeyDown(SDLK_x)&&Input::isKeyDown(SDLK_LSHIFT)&&!detailtogglekeydown&&debugmode){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -5760,7 +4582,7 @@ void      Game::Tick()
                                                                detailtogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_U_KEY)&&debugmode){
+                                               if(Input::isKeyDown(SDLK_u)&&debugmode){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -5778,7 +4600,7 @@ void      Game::Tick()
                                                }
 
 
-                                               if(IsKeyDown(theKeyMap, MAC_O_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
+                                               if(Input::isKeyDown(SDLK_o)&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -5790,7 +4612,7 @@ void      Game::Tick()
                                                                                closest=i;
                                                                        }
                                                                }
-                                                               if(IsKeyDown(theKeyMap, MAC_CONTROL_KEY))closest=0;
+                                                               if(Input::isKeyDown(SDLK_LCTRL))closest=0;
 
                                                                if(closest!=-1){
                                                                        player[closest].whichskin++;
@@ -5814,7 +4636,7 @@ void      Game::Tick()
                                                                detailtogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_O_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
+                                               if(Input::isKeyDown(SDLK_o)&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -5895,18 +4717,18 @@ void    Game::Tick()
                                                                detailtogglekeydown=1;
                                                }
 
-                                               if(!IsKeyDown(theKeyMap, MAC_X_KEY)){
+                                               if(!Input::isKeyDown(SDLK_x)){
                                                        detailtogglekeydown=0;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_B_KEY)&&!slomotogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
+                                               if(Input::isKeyDown(SDLK_b)&&!slomotogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
                                                        slomo=1-slomo;
                                                        slomodelay=1000;
                                                        slomotogglekeydown=1;
                                                }
 
 
-                                               if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[1]*/)&&!explodetogglekeydown&&debugmode){
+                                               if(((Input::isKeyDown(SDLK_i)&&!Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -5936,11 +4758,11 @@ void    Game::Tick()
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
                                                                                headspurtdirection=player[closest].skeleton.joints[player[closest].skeleton.jointlabels[head]].position-player[closest].skeleton.joints[player[closest].skeleton.jointlabels[neck]].position;
                                                                                Normalise(&headspurtdirection);
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, .6, 1);
                                                                                flatvelocity2+=headspurtdirection*8;
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2/2, 1,1,1, .16, 1);
                                                                        }
-                                                                       sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
+                                                                       Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
 
                                                                        float gLoc[3];
                                                                        float vel[3];
@@ -5972,7 +4794,7 @@ void      Game::Tick()
                                                                explodetogglekeydown=1;
                                                }
 
-                                               if(((IsKeyDown(theKeyMap, MAC_I_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY))/*||buttons[2]*/)&&!explodetogglekeydown&&debugmode){
+                                               if(((Input::isKeyDown(SDLK_i)&&Input::isKeyDown(SDLK_LSHIFT)))&&!explodetogglekeydown&&debugmode){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -6017,9 +4839,9 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
-                                                                               sprites.MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .3, 1);
+                                                                               Sprite::MakeSprite(cloudsprite, flatfacing2,flatvelocity2*0, .6,0,0, 1, .5);
                                                                        }
 
                                                                        for(i=0;i<player[closest].skeleton.num_joints; i++){
@@ -6030,8 +4852,8 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2, 1,1,1, .4, 1);
                                                                        }
 
                                                                        for(i=0;i<player[closest].skeleton.num_joints; i++){
@@ -6042,8 +4864,8 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
                                                                        }
 
                                                                        for(i=0;i<player[closest].skeleton.num_joints; i++){
@@ -6054,8 +4876,8 @@ void      Game::Tick()
                                                                                flatvelocity2.x+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.y+=(float)(abs(Random()%100)-50)/10;
                                                                                flatvelocity2.z+=(float)(abs(Random()%100)-50)/10;
-                                                                               sprites.MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
-                                                                               sprites.MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
+                                                                               Sprite::MakeSprite(bloodflamesprite, flatfacing2,flatvelocity2*2, 1,1,1, 3, 1);
+                                                                               Sprite::MakeSprite(bloodsprite, flatfacing2,flatvelocity2*2, 1,1,1, .4, 1);
                                                                        }
 
                                                                        XYZ temppos;
@@ -6091,70 +4913,16 @@ void    Game::Tick()
                                                                explodetogglekeydown=1;
                                                }
 
-                                               if(!IsKeyDown(theKeyMap, MAC_I_KEY)){
+                                               if(!Input::isKeyDown(SDLK_i)){
                                                        explodetogglekeydown=0;
                                                }
 
-                                               /*
-                                               if(IsKeyDown(theKeyMap, MAC_S_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&!slomotogglekeydown){
-                                               FILE                    *tfile;
-                                               //tfile=fopen( ":Data:Maps:mapsave", "wb" );
-                                               if(whichlevel==0)tfile=fopen( ":Data:Maps:map1", "wb" );
-                                               else if(whichlevel==1)tfile=fopen( ":Data:Maps:map2", "wb" );
-                                               else if(whichlevel==2)tfile=fopen( ":Data:Maps:map3", "wb" );
-                                               else if(whichlevel==3)tfile=fopen( ":Data:Maps:map4", "wb" );
-                                               else if(whichlevel==4)tfile=fopen( ":Data:Maps:map5", "wb" );
-                                               else tfile=fopen( ":Data:Maps:mapsave", "wb" );
-
-                                               fwrite( &player[0].coords, 1, sizeof(XYZ), tfile );
-                                               fwrite( &player[0].rotation, 1, sizeof(float), tfile );
-                                               fwrite( &player[0].targetrotation, 1, sizeof(float), tfile );
-                                               fwrite( &player[0].num_weapons, 1, sizeof(int), tfile );
-                                               for(j=0;j<player[0].num_weapons;j++){
-                                               fwrite( &weapons.type[player[0].weaponids[j]], 1, sizeof(int), tfile );
-                                               }
-                                               fwrite( &environment, 1, sizeof(int), tfile );
-
-                                               fwrite( &objects.numobjects, 1, sizeof(int), tfile );
-                                               fwrite( &objects.type, 1, sizeof(int)*objects.numobjects, tfile );
-                                               fwrite( &objects.rotation, 1, sizeof(float)*objects.numobjects, tfile );
-                                               fwrite( &objects.position, 1, sizeof(XYZ)*objects.numobjects, tfile );
-                                               fwrite( &objects.scale, 1, sizeof(float)*objects.numobjects, tfile );
-
-                                               fwrite( &numplayers, 1, sizeof(int), tfile );
-                                               if(numplayers>1&&numplayers<maxplayers)
-                                               for(i=1;i<numplayers;i++){
-                                               fwrite( &player[i].coords, 1, sizeof(XYZ), tfile );
-                                               fwrite( &player[i].num_weapons, 1, sizeof(int), tfile );
-                                               for(j=0;j<player[i].num_weapons;j++){
-                                               fwrite( &weapons.type[player[i].weaponids[j]], 1, sizeof(int), tfile );
-                                               }
-                                               if(player[i].numwaypoints<30){
-                                               fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
-                                               fwrite( &player[i].waypoints, 1, sizeof(XYZ)*player[i].numwaypoints, tfile );
-                                               fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
-                                               //fwrite( &player[i].jumppath, 1, sizeof(bool), tfile );
-                                               }
-                                               else{
-                                               player[i].numwaypoints=0;
-                                               player[i].waypoint=0;
-                                               fwrite( &player[i].numwaypoints, 1, sizeof(int), tfile );
-                                               fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
-                                               fwrite( &player[i].waypoint, 1, sizeof(int), tfile );
-                                               }
-                                               }
-
-                                               fclose(tfile);
-
-                                               slomotogglekeydown=1;
-                                               }*/
-
-                                               if(!IsKeyDown(theKeyMap, MAC_B_KEY)&&!IsKeyDown(theKeyMap, MAC_F_KEY)&&!IsKeyDown(theKeyMap, MAC_K_KEY)&&!IsKeyDown(theKeyMap, MAC_S_KEY)){
+                                               if(!Input::isKeyDown(SDLK_b)&&!Input::isKeyDown(SDLK_f)&&!Input::isKeyDown(SDLK_k)&&!Input::isKeyDown(SDLK_s)){
                                                        slomotogglekeydown=0;
                                                }
 
 
-                                               if(IsKeyDown(theKeyMap, MAC_F_KEY)&&!slomotogglekeydown&&debugmode){
+                                               if(Input::isKeyDown(SDLK_f)&&!slomotogglekeydown&&debugmode){
                                                        player[0].onfire=1-player[0].onfire;
                                                        if(player[0].onfire){
                                                                player[0].CatchFire();
@@ -6176,14 +4944,8 @@ void     Game::Tick()
                                                        }
                                                        slomotogglekeydown=1;
                                                }
-                                               /*
-                                               if(IsKeyDown(theKeyMap, MAC_L_KEY)){
-                                               if(player[0].bleeding<=0)
-                                               player[0].DoBlood(1,255);
-                                               }*/
 
-
-                                               if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
+                                               if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -6203,7 +4965,7 @@ void      Game::Tick()
                                                                drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LCTRL)){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -6221,7 +4983,7 @@ void      Game::Tick()
                                                                drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled&&debugmode){
+                                               if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&editorenabled&&debugmode){
                                                        //drawmode++;
                                                        //if(drawmode>2)drawmode=0;
                                                        if(objects.numobjects<max_objects-1){
@@ -6246,7 +5008,7 @@ void      Game::Tick()
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
+                                               if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)&&editorenabled){
                                                        if(numplayers<maxplayers-1){
                                                                player[numplayers].scale=.2*5*player[0].scale;
                                                                player[numplayers].creature=rabbittype;
@@ -6338,7 +5100,7 @@ void      Game::Tick()
                                                                        player[numplayers].proportionlegs.z=0;
                                                                }
 
-                                                               player[numplayers].tempanimation.Load((char *)":Data:Animations:Tempanim",0,0);
+                                                               player[numplayers].tempanimation.Load((char *)"Tempanim",0,0);
 
                                                                player[numplayers].damagetolerance=200;
 
@@ -6394,7 +5156,7 @@ void      Game::Tick()
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&editorenabled){
+                                               if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)&&editorenabled){
                                                        if(player[numplayers-1].numwaypoints<90){
                                                                player[numplayers-1].waypoints[player[numplayers-1].numwaypoints]=player[0].coords;
                                                                player[numplayers-1].waypointtype[player[numplayers-1].numwaypoints]=editorpathtype;
@@ -6403,7 +5165,7 @@ void      Game::Tick()
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_P_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&editorenabled){
+                                               if(Input::isKeyDown(SDLK_p)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LCTRL)&&editorenabled){
                                                        if(numpathpoints<30){
                                                                bool connected,alreadyconnected;
                                                                connected=0;
@@ -6435,17 +5197,18 @@ void    Game::Tick()
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!drawmodetogglekeydown&&editorenabled){
+                                               if(Input::isKeyDown(SDLK_PERIOD)&&!drawmodetogglekeydown&&editorenabled){
                                                        pathpointselected++;
                                                        if(pathpointselected>=numpathpoints)pathpointselected=-1;
                                                        drawmodetogglekeydown=1;
                                                }
-                                               if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
+                                               if(Input::isKeyDown(SDLK_COMMA)&&!Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){
                                                        pathpointselected--;
-                                                       if(pathpointselected<=-2)pathpointselected=numpathpoints-1;
+                                                       if(pathpointselected<=-2)
+                                                               pathpointselected=numpathpoints-1;
                                                        drawmodetogglekeydown=1;
                                                }
-                                               if(IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!drawmodetogglekeydown&&editorenabled){
+                                               if(Input::isKeyDown(SDLK_COMMA)&&Input::isKeyDown(SDLK_LSHIFT)&&!drawmodetogglekeydown&&editorenabled){
                                                        if(pathpointselected!=-1){
                                                                numpathpoints--;
                                                                pathpoint[pathpointselected]=pathpoint[numpathpoints];
@@ -6469,96 +5232,74 @@ void    Game::Tick()
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_M_KEY)&&!drawmodetogglekeydown&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&debugmode){
+                                               if(Input::isKeyDown(SDLK_m)&&!drawmodetogglekeydown&&Input::isKeyDown(SDLK_LSHIFT)&&debugmode){
                                                        editorenabled=1-editorenabled;
                                                        if(editorenabled){
                                                                player[0].damagetolerance=100000;
-                                                               player[0].damage=0;
-                                                               player[0].superpermanentdamage=0;
-                                                               player[0].bloodloss=0;
-                                                               player[0].deathbleeding=0;
-                                                       }
-                                                       if(!editorenabled){
+                                                       } else {
                                                                player[0].damagetolerance=200;
-                                                               player[0].damage=0;
-                                                               player[0].permanentdamage=0;
-                                                               player[0].superpermanentdamage=0;
-                                                               player[0].bloodloss=0;
-                                                               player[0].deathbleeding=0;
                                                        }
+                                                       player[0].damage=0; // these lines were in both if and else, but I think they would better fit in the if
+                                                       player[0].permanentdamage=0;
+                                                       player[0].superpermanentdamage=0;
+                                                       player[0].bloodloss=0;
+                                                       player[0].deathbleeding=0;
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
                                                        editortype--;
                                                        if(editortype==treeleavestype||editortype==10)editortype--;
                                                        if(editortype<0)editortype=firetype;
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
                                                        editortype++;
                                                        if(editortype==treeleavestype||editortype==10)editortype++;
                                                        if(editortype>firetype)editortype=0;
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_LEFT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
                                                        editorrotation-=multiplier*100;
                                                        if(editorrotation<-.01)editorrotation=-.01;
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_RIGHT)&&editorenabled&&!Input::isKeyDown(SDLK_LSHIFT)&&!Input::isKeyDown(SDLK_LCTRL)){
                                                        editorrotation+=multiplier*100;
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_UP)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){
                                                        editorsize+=multiplier;
                                                        drawmodetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&!Input::isKeyDown(SDLK_LCTRL)){
                                                        editorsize-=multiplier;
                                                        if(editorsize<.1)editorsize=.1;
                                                        drawmodetogglekeydown=1;
                                                }
 
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_LEFT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
                                                        mapradius-=multiplier*10;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!drawmodetogglekeydown&&editorenabled&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_RIGHT)&&!drawmodetogglekeydown&&editorenabled&&Input::isKeyDown(SDLK_LSHIFT)&&Input::isKeyDown(SDLK_LCTRL)){
                                                        mapradius+=multiplier*10;
                                                }
-                                               /*
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
-                                               mapcenter.x+=multiplier*20;
-                                               }
-
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&editorenabled&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
-                                               mapcenter.x-=multiplier*20;
-                                               }
-
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
-                                               mapcenter.z+=multiplier*20;
-                                               }
-
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
-                                               mapcenter.z-=multiplier*20;
-                                               }
-                                               */
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_UP_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_UP)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){
                                                        editorrotation2+=multiplier*100;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_ARROW_DOWN_KEY)&&editorenabled&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)){
+                                               if(Input::isKeyDown(SDLK_DOWN)&&editorenabled&&Input::isKeyDown(SDLK_LCTRL)){
                                                        editorrotation2-=multiplier*100;
                                                        if(editorrotation2<-.01)editorrotation2=-.01;
                                                }
-                                               if(IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!IsKeyDown(theKeyMap, MAC_SHIFT_KEY)){
+                                               if(Input::isKeyDown(SDLK_DELETE)&&editorenabled&&objects.numobjects&&!drawmodetogglekeydown&&!Input::isKeyDown(SDLK_LSHIFT)){
                                                        int closest=-1;
                                                        float closestdist=-1;
                                                        float distance;
@@ -6574,11 +5315,11 @@ void    Game::Tick()
                                                }
 
 
-                                               if(!IsKeyDown(theKeyMap, MAC_M_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_LEFT_KEY)&&!IsKeyDown(theKeyMap, MAC_COMMA_KEY)&&!IsKeyDown(theKeyMap, MAC_PERIOD_KEY)&&!IsKeyDown(theKeyMap, MAC_ARROW_RIGHT_KEY)&&!IsKeyDown(theKeyMap, MAC_DELETE_KEY)&&!IsKeyDown(theKeyMap, MAC_P_KEY)){
+                                               if(!Input::isKeyDown(SDLK_m)&&!Input::isKeyDown(SDLK_LEFT)&&!Input::isKeyDown(SDLK_COMMA)&&!Input::isKeyDown(SDLK_PERIOD)&&!Input::isKeyDown(SDLK_RIGHT)&&!Input::isKeyDown(SDLK_DELETE)&&!Input::isKeyDown(SDLK_p)){
                                                        drawmodetogglekeydown=0;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_N_KEY)&&!IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
+                                               if(Input::isKeyDown(SDLK_n)&&!Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){
                                                        //if(!player[0].skeleton.free)player[0].damage+=500;
                                                        player[0].RagDoll(0);
                                                        //player[0].spurt=1;
@@ -6601,7 +5342,7 @@ void      Game::Tick()
                                                        texturesizetogglekeydown=1;
                                                }
 
-                                               if(IsKeyDown(theKeyMap, MAC_N_KEY)&&IsKeyDown(theKeyMap, MAC_CONTROL_KEY)&&!texturesizetogglekeydown&&debugmode){
+                                               if(Input::isKeyDown(SDLK_n)&&Input::isKeyDown(SDLK_LCTRL)&&!texturesizetogglekeydown&&debugmode){
 
                                                        int closest=-1;
                                                        float closestdist=-1;
@@ -6619,13 +5360,13 @@ void    Game::Tick()
                                                //Attack
                                                static bool playerrealattackkeydown=0;
 
-                                               if(!buttons[0])oldbutton=0;
-                                               if(!IsKeyDown(theKeyMap, attackkey))oldattackkey=0;
+                                               if(!Input::isKeyDown(MOUSEBUTTON1)&&!Input::isKeyDown(MOUSEBUTTON2))oldbutton=0;
+                                               if(!Input::isKeyDown(attackkey))oldattackkey=0;
                                                if(oldattackkey)player[0].attackkeydown=0;
                                                if(oldattackkey)playerrealattackkeydown=0;
-                                               if(!oldattackkey)playerrealattackkeydown=IsKeyDown(theKeyMap, attackkey);
-                                               if((player[0].parriedrecently<=0||player[0].weaponactive==-1)&&(!oldattackkey||(realthreat&&player[0].lastattack!=swordslashanim&&player[0].lastattack!=knifeslashstartanim&&player[0].lastattack!=staffhitanim&&player[0].lastattack!=staffspinhitanim)))player[0].attackkeydown=IsKeyDown(theKeyMap, attackkey);
-                                               if(IsKeyDown(theKeyMap, attackkey)&&!oldattackkey&&!player[0].backkeydown){
+                                               if(!oldattackkey)playerrealattackkeydown=Input::isKeyDown(attackkey);
+                                               if((player[0].parriedrecently<=0||player[0].weaponactive==-1)&&(!oldattackkey||(realthreat&&player[0].lastattack!=swordslashanim&&player[0].lastattack!=knifeslashstartanim&&player[0].lastattack!=staffhitanim&&player[0].lastattack!=staffspinhitanim)))player[0].attackkeydown=Input::isKeyDown(attackkey);
+                                               if(Input::isKeyDown(attackkey)&&!oldattackkey&&!player[0].backkeydown){
                                                        for(k=0;k<numplayers;k++){
                                                                if((player[k].targetanimation==swordslashanim||player[k].targetanimation==staffhitanim||player[k].targetanimation==staffspinhitanim)&&player[0].currentanimation!=dodgebackanim&&!player[k].skeleton.free)
                                                                        player[k].Reverse();
@@ -7211,78 +5952,7 @@ void     Game::Tick()
 
 
                                                        //pile
-                                                       /*
-                                                       XYZ tempdiff;
-                                                       XYZ tempoldpos;
-                                                       XYZ temp1,temp2;
-                                                       bool isgood;
-                                                       static float checkdelay;
-                                                       checkdelay-=multiplier;
-                                                       int m;
-                                                       static bool checkedcoll[maxplayers][maxplayers];
-                                                       static bool above[maxplayers];
-
-                                                       for(i=0;i<maxplayers;i++){
-                                                       for(j=0;j<maxplayers;j++){
-                                                       checkedcoll[i][j]=0;
-                                                       }
-                                                       }
-
-                                                       if(numplayers>1&&checkdelay<=0){
-                                                       checkdelay=.015;
-                                                       for(k=0;k<numplayers;k++){
-                                                       if(player[k].skeleton.free!=2)above[k]=-1;
-
-                                                       for(i=k;i<numplayers;i++){
-                                                       if(i==k)i++;
-                                                       if(i<numplayers)
-                                                       if(!checkedcoll[i][k]){
-                                                       checkedcoll[i][k]=1;
-                                                       checkedcoll[k][i]=1;
-                                                       if(player[i].skeleton.free&&player[k].skeleton.free)
-                                                       if(player[i].skeleton.free!=2||player[k].skeleton.free!=2)
-                                                       if(i!=k&&player[i].whichpatchx==player[k].whichpatchx&&player[i].whichpatchz==player[k].whichpatchz)
-                                                       if(player[i].coords.y>player[k].coords.y-3)
-                                                       if(player[i].coords.y<player[k].coords.y+3)
-                                                       if(player[i].coords.x>player[k].coords.x-3)
-                                                       if(player[i].coords.x<player[k].coords.x+3)
-                                                       if(player[i].coords.z>player[k].coords.z-3)
-                                                       if(player[i].coords.z<player[k].coords.z+3)
-                                                       if(findDistancefast(&player[i].coords,&player[k].coords)<3*((player[i].scale+player[k].scale)*2.5)*((player[i].scale+player[k].scale)*2.5)){
-                                                       int stuck,moving;
-                                                       if((player[i].skeleton.longdead>player[k].skeleton.longdead&&player[k].skeleton.free!=2)||player[i].skeleton.free==2){
-                                                       stuck=i;
-                                                       moving=k;
-                                                       }
-                                                       else
-                                                       {
-                                                       moving=i;
-                                                       stuck=k;
-                                                       }
-                                                       isgood=1;
-
-                                                       if(isgood){
-                                                       above[moving]=stuck;
-                                                       for(l=0;l<player[moving].skeleton.num_joints;l++){
-                                                       for(m=0;m<player[stuck].skeleton.num_joints;m++){
-                                                       while(findDistancefast(player[moving].skeleton.joints[l].position+player[moving].coords,player[stuck].skeleton.joints[m].position+player[stuck].coords)<.25)
-                                                       {
-                                                       player[moving].skeleton.joints[l].position.y+=.003;
-                                                       if(player[moving].skeleton.joints[l].velocity.y<-.05)player[moving].skeleton.joints[l].velocity.y+=.003/.015/2;
-
-                                                       }
-                                                       }
-                                                       }
-                                                       }
-                                                       }
-                                                       }
-                                                       }
-                                                       }
-                                                       }
-
-                                                       */
-
-                                                       if(!IsKeyDown(theKeyMap, MAC_N_KEY)){
+                                                       if(!Input::isKeyDown(SDLK_n)){
                                                                texturesizetogglekeydown=0;
                                                        }
 
@@ -7295,52 +5965,27 @@ void    Game::Tick()
                                                        }
 
                                                        static bool respawnkeydown;
-                                                       if(!editorenabled&&(whichlevel!=-2&&(IsKeyDown(theKeyMap, MAC_Z_KEY)&&IsKeyDown(theKeyMap, MAC_COMMAND_KEY)&&debugmode&&!editorenabled)||(IsKeyDown(theKeyMap, jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
+                                                       if(!editorenabled&&(whichlevel!=-2&&(Input::isKeyDown(SDLK_z)&&Input::isKeyDown(SDLK_LMETA)&&debugmode&&!editorenabled)||(Input::isKeyDown(jumpkey)&&!respawnkeydown&&!oldattackkey&&player[0].dead))){
                                                                targetlevel=whichlevel;
                                                                loading=1;
                                                                leveltime=5;
                                                        }
-                                                       if(!IsKeyDown(theKeyMap, jumpkey))respawnkeydown=0;
-                                                       if(IsKeyDown(theKeyMap, jumpkey))respawnkeydown=1;
+                                                       if(!Input::isKeyDown(jumpkey))respawnkeydown=0;
+                                                       if(Input::isKeyDown(jumpkey))respawnkeydown=1;
 
 
 
 
-                                                       if(whichlevel!=-2&&IsKeyDown(theKeyMap, MAC_K_KEY)&&IsKeyDown(theKeyMap, MAC_SHIFT_KEY)&&!slomotogglekeydown&&debugmode&&!editorenabled){
+                                                       if(whichlevel!=-2&&Input::isKeyDown(SDLK_k)&&Input::isKeyDown(SDLK_LSHIFT)&&!slomotogglekeydown&&debugmode&&!editorenabled){
                                                                targetlevel++;
                                                                if(targetlevel>numchallengelevels-1)targetlevel=0;
                                                                loading=1;
                                                                leveltime=5;
                                                                slomotogglekeydown=1;
                                                        }
-
-                                                       /*
-                                                       if(IsKeyDown(theKeyMap, MAC_Z_KEY)){
-                                                       //Respawn
-                                                       OPENAL_SetPaused(channels[whooshsound], true);
-                                                       changedelay=0;
-                                                       for(k=0;k<numplayers;k++){
-                                                       player[k].dead=0;
-                                                       player[k].damage=0;
-                                                       player[k].permanentdamage=0;
-                                                       if(player[k].skeleton.free==2)player[k].skeleton.free=1;
-                                                       player[k].aitype=passivetype;
-                                                       }
-                                                       player[0].aitype=playercontrolled;
-                                                       }
-                                                       */
-
                                                        static bool movekey;
                                                        static bool connected;
-                                                       /*player[0].forwardkeydown=IsKeyDown(theKeyMap, MAC_W_KEY);
-                                                       player[0].leftkeydown=IsKeyDown(theKeyMap, MAC_A_KEY);
-                                                       player[0].backkeydown=IsKeyDown(theKeyMap, MAC_S_KEY);
-                                                       player[0].rightkeydown=IsKeyDown(theKeyMap, MAC_D_KEY);
-                                                       player[0].jumpkeydown=IsKeyDown(theKeyMap, MAC_SPACE_KEY);
-                                                       player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_SHIFT_KEY);*/
-
-                                                       //if(!player[0].crouchkeydown)player[0].crouchkeydown=IsKeyDown(theKeyMap, MAC_CONTROL_KEY);
-
+                                                       
                for(int i=0;i<numplayers;i++){
                                                                if(!player[i].skeleton.free){
                                                                        oldtargetrotation=player[i].targetrotation;
@@ -8031,21 +6676,6 @@ void     Game::Tick()
                                                                                                                                        else player[i].targetrotation-=90;
                                                                                                                                }
                                                                                                                        }
-                                                                                                                       /*if(findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<3){
-                                                                                                                       if(abs(Random()%6)){
-                                                                                                                       player[i].crouchkeydown=1;
-                                                                                                                       if(!findDistancefast(&player[i].coords,&weapons.position[player[i].ally])<1){
-                                                                                                                       if(player[i].isRun()){
-                                                                                                                       player[i].targetframe=0;
-                                                                                                                       player[i].target=0;
-                                                                                                                       player[i].targetanimation=sneakanim;
-                                                                                                                       }
-                                                                                                                       }
-                                                                                                                       else player[i].forwardkeydown=0;
-                                                                                                                       }
-                                                                                                                       else player[i].crouchkeydown=0;
-                                                                                                                       }
-                                                                                                                       else player[i].crouchkeydown=0;*/
                                                                                                                }
 
                                                                                                                player[i].leftkeydown=0;
@@ -8187,21 +6817,9 @@ void     Game::Tick()
                                                                                                                                player[i].throwkeydown=0;
 
                                                                                                                                if(player[i].avoidcollided>.8&&!player[i].jumpkeydown&&player[i].collided<.8)player[i].targetrotation+=90*(player[i].whichdirection*2-1);
-                                                                                                                               /*for(j=0;j<numplayers;j++){
-                                                                                                                               if(player[j].victim->id==i&&(player[j].targetanimation==spinkickanim&&player[j].targetframe<3)){
-                                                                                                                               player[i].crouchkeydown=1;
-                                                                                                                               }
-                                                                                                                               }*/
                                                                                                                                if(Random()%2==0/*||player[0].weaponactive!=-1*/||player[i].weaponactive!=-1||player[i].creature==wolftype)player[i].attackkeydown=1;
                                                                                                                                else player[i].attackkeydown=0;
                                                                                                                                if((player[i].isRun())&&Random()%6&&findDistancefast(&player[i].coords,&player[0].coords)>7)player[i].attackkeydown=0;
-                                                                                                                               //if(player[i].attackkeydown&&findDistancefast(&player[i].coords,&player[0].coords)<3&&player[i].targetanimation!=runanim&&!player[0].skeleton.free)player[i].crouchkeydown=1;
-                                                                                                                               /*if(player[0].targetanimation==rabbitkickanim&&!player[0].skeleton.free){
-                                                                                                                               player[i].attackkeydown=0;
-                                                                                                                               if(player[i].isIdle())player[i].crouchkeydown=1;
-                                                                                                                               player[i].forwardkeydown=0;
-                                                                                                                               player[i].aiupdatedelay=.02;
-                                                                                                                               }*/
 
                                                                                                                                if(player[i].aitype!=playercontrolled&&(player[i].isIdle()||player[i].isCrouch()||player[i].isRun())){
                                                                                                                                        target=-2;
@@ -8534,7 +7152,7 @@ void      Game::Tick()
                                                                                                                                                                footpoint=weapons.position[k];
                                                                                                                                                                if(player[i].victim->weaponstuck!=-1){
                                                                                                                                                                        if(player[i].victim->weaponids[player[i].victim->weaponstuck]==k){
-                                                                                                                                                                               if(bloodtoggle)sprites.MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
+                                                                                                                                                                               if(bloodtoggle)Sprite::MakeSprite(cloudimpactsprite, footpoint,footvel, 1,0,0, .8, .3);
                                                                                                                                                                                weapons.bloody[k]=2;
                                                                                                                                                                                weapons.blooddrip[k]=5;
                                                                                                                                                                                player[i].victim->weaponstuck=-1;
@@ -9039,105 +7657,77 @@ void   Game::Tick()
                                                        }
 
                                                        objects.DoStuff();
-                                                       /*
-                                                       player[0].righthandmorphstart=0;
-                                                       player[0].righthandmorphend=1;
-                                                       player[0].lefthandmorphstart=0;
-                                                       player[0].lefthandmorphend=1;
-                                                       player[0].headmorphstart=0;
-                                                       player[0].headmorphend=2;*/
-
-                                                       /*
-                                                       if(IsKeyDown( theKeyMap, MAC_P_KEY )){
-                                                       if(player[0].righthandmorphend!=1)player[0].righthandmorphness=0;
-                                                       player[0].righthandmorphend=1;
-                                                       player[0].targetrighthandmorphness=1;
-
-                                                       if(player[0].lefthandmorphend!=0)player[0].lefthandmorphness=0;
-                                                       player[0].lefthandmorphend=0;
-                                                       player[0].targetlefthandmorphness=1;
-
-                                                       if(player[0].headmorphend!=2)player[0].headmorphness=0;
-                                                       player[0].headmorphend=2;
-                                                       player[0].targetheadmorphness=1;
-                                                       }
-                                                       if(IsKeyDown( theKeyMap, MAC_L_KEY )){
-                                                       if(player[0].righthandmorphend!=0)player[0].righthandmorphness=0;
-                                                       player[0].righthandmorphend=0;
-                                                       player[0].targetrighthandmorphness=1;
-
-                                                       if(player[0].lefthandmorphend!=1)player[0].lefthandmorphness=0;
-                                                       player[0].lefthandmorphend=1;
-                                                       player[0].targetlefthandmorphness=1;
-
-                                                       if(player[0].headmorphend!=0)player[0].headmorphness=0;
-                                                       player[0].headmorphend=0;
-                                                       player[0].targetheadmorphness=1;
+                                                       
+                                                       for(j=numenvsounds-1;j>=0;j--){
+                                                               envsoundlife[j]-=multiplier;
+                                                               if(envsoundlife[j]<0){
+                                                                       numenvsounds--;
+                                                                       envsoundlife[j]=envsoundlife[numenvsounds];
+                                                                       envsound[j]=envsound[numenvsounds];
+                                                               }
                                                        }
-                                                       */
-                                                       if(numenvsounds!=0)
-                                                               for(j=numenvsounds-1;j>=0;j--){
-                                                                       envsoundlife[j]-=multiplier;
-                                                                       if(envsoundlife[j]<0){
-                                                                               numenvsounds--;
-                                                                               envsoundlife[j]=envsoundlife[numenvsounds];
-                                                                               envsound[j]=envsound[numenvsounds];
+                                                       if(slomo) OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
+                                                       else OPENAL_SetFrequency(OPENAL_ALL, 22050);
+
+                                                       if(tutoriallevel==1){
+                                                               XYZ temp;
+                                                               XYZ temp2;
+                                                               XYZ temp3;
+                                                               XYZ oldtemp;
+                                                               XYZ oldtemp2;
+                                                               temp.x=1011;
+                                                               temp.y=84;
+                                                               temp.z=491;
+                                                               temp2.x=1025;
+                                                               temp2.y=75;
+                                                               temp2.z=447;
+                                                               temp3.x=1038;
+                                                               temp3.y=76;
+                                                               temp3.z=453;
+                                                               oldtemp=temp;
+                                                               oldtemp2=temp2;
+                                                               if(tutorialstage>=51)
+                                                                       if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
+                                                                               OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
+                                                                               OPENAL_SetFrequency(OPENAL_ALL, 0.001);
+
+                                                                               PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
+                                                                               OPENAL_SetPaused(channels[stream_music3], false);
+                                                                               OPENAL_SetVolume(channels[stream_music3], 256);
+
+                                                                               gameon=0;
+                                                                               mainmenu=5;
+
+                                                                               fireSound();
+
+                                                                               flash();
                                                                        }
-                                                               }
-                                                               if(!slomo)OPENAL_SetFrequency(OPENAL_ALL, 22050);
-                                                               if(slomo)OPENAL_SetFrequency(OPENAL_ALL, slomofreq);
-
-                                                               if(tutoriallevel==1){
-                                                                       XYZ temp;
-                                                                       XYZ temp2;
-                                                                       XYZ temp3;
-                                                                       XYZ oldtemp;
-                                                                       XYZ oldtemp2;
-                                                                       temp.x=1011;
-                                                                       temp.y=84;
-                                                                       temp.z=491;
-                                                                       temp2.x=1025;
-                                                                       temp2.y=75;
-                                                                       temp2.z=447;
-                                                                       temp3.x=1038;
-                                                                       temp3.y=76;
-                                                                       temp3.z=453;
-                                                                       oldtemp=temp;
-                                                                       oldtemp2=temp2;
-                                                                       if(tutorialstage>=51)
+                                                                       if(tutorialstage<51)
                                                                                if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
-                                                   OPENAL_StopSound(OPENAL_ALL);  // hack...OpenAL renderer isn't stopping music after tutorial goes to level menu...
-                                                                                       OPENAL_SetFrequency(OPENAL_ALL, 0.001);
-
-                                                                                       PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
-                                                                                       OPENAL_SetPaused(channels[stream_music3], false);
-                                                                                       OPENAL_SetVolume(channels[stream_music3], 256);
-
-                                                                                       gameon=0;
-                                                                                       mainmenu=5;
-
-                                                                                       float gLoc[3]={0,0,0};
-                                                                                       float vel[3]={0,0,0};
-                                                                                       OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
+                                                                                       float gLoc[3];
+                                                                                       float vel[3];
+                                                                                       gLoc[0]=player[0].coords.x;
+                                                                                       gLoc[1]=player[0].coords.y;
+                                                                                       gLoc[2]=player[0].coords.z;
+                                                                                       vel[0]=0;
+                                                                                       vel[1]=0;
+                                                                                       vel[2]=0;
                                                                                        PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
                                                                                        OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
                                                                                        OPENAL_SetVolume(channels[fireendsound], 256);
                                                                                        OPENAL_SetPaused(channels[fireendsound], false);
-                                                                                       OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
 
-                                                                                       flashr=1;
-                                                                                       flashg=0;
-                                                                                       flashb=0;
-                                                                                       flashamount=1;
-                                                                                       flashdelay=1;
+                                                                                       player[0].coords=(oldtemp+oldtemp2)/2;
+
+                                                                                       flash();
                                                                                }
-                                                                               if(tutorialstage<51)
-                                                                                       if(findDistancefast(&temp,&player[0].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[0].coords)<4){
+                                                                               if(tutorialstage>=14&&tutorialstage<50)
+                                                                                       if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
                                                                                                float gLoc[3];
                                                                                                float vel[3];
-                                                                                               gLoc[0]=player[0].coords.x;
-                                                                                               gLoc[1]=player[0].coords.y;
-                                                                                               gLoc[2]=player[0].coords.z;
+                                                                                               gLoc[0]=player[1].coords.x;
+                                                                                               gLoc[1]=player[1].coords.y;
+                                                                                               gLoc[2]=player[1].coords.z;
                                                                                                vel[0]=0;
                                                                                                vel[1]=0;
                                                                                                vel[2]=0;
@@ -9146,113 +7736,88 @@ void   Game::Tick()
                                                                                                OPENAL_SetVolume(channels[fireendsound], 256);
                                                                                                OPENAL_SetPaused(channels[fireendsound], false);
 
-                                                                                               player[0].coords=(oldtemp+oldtemp2)/2;
-
-                                                                                               flashr=1;
-                                                                                               flashg=1;
-                                                                                               flashb=1;
-                                                                                               flashamount=1;
-                                                                                               flashdelay=1;
-                                                                                       }
-                                                                                       if(tutorialstage>=14&&tutorialstage<50)
-                                                                                               if(findDistancefast(&temp,&player[1].coords)>=findDistancefast(&temp,&temp2)-1||findDistancefast(&temp3,&player[1].coords)<4){
-                                                                                                       float gLoc[3];
-                                                                                                       float vel[3];
-                                                                                                       gLoc[0]=player[1].coords.x;
-                                                                                                       gLoc[1]=player[1].coords.y;
-                                                                                                       gLoc[2]=player[1].coords.z;
-                                                                                                       vel[0]=0;
-                                                                                                       vel[1]=0;
-                                                                                                       vel[2]=0;
-                                                                                                       PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                                                                       OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                                                                       OPENAL_SetVolume(channels[fireendsound], 256);
-                                                                                                       OPENAL_SetPaused(channels[fireendsound], false);
-
-                                                                                                       for(int i=0;i<player[1].skeleton.num_joints;i++){
-                                                                                                               if(Random()%2==0){
-                                                                                                                       if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
-                                                                                                                       if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
-                                                                                                                       if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
-                                                                                                                       if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
-                                                                                                               }
+                                                                                               for(int i=0;i<player[1].skeleton.num_joints;i++){
+                                                                                                       if(Random()%2==0){
+                                                                                                               if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
+                                                                                                               if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
+                                                                                                               if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
+                                                                                                               if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
+                                                                                                               Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                                                        }
+                                                                                               }
 
-                                                                                                       player[1].coords=(oldtemp+oldtemp2)/2;
-                                                                                                       for(int i=0;i<player[1].skeleton.num_joints;i++){
-                                                                                                               player[1].skeleton.joints[i].velocity=0;
-                                                                                                               if(Random()%2==0){
-                                                                                                                       if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
-                                                                                                                       if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
-                                                                                                                       if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
-                                                                                                                       if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
-                                                                                                                       sprites.MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
-                                                                                                               }
+                                                                                               player[1].coords=(oldtemp+oldtemp2)/2;
+                                                                                               for(int i=0;i<player[1].skeleton.num_joints;i++){
+                                                                                                       player[1].skeleton.joints[i].velocity=0;
+                                                                                                       if(Random()%2==0){
+                                                                                                               if(!player[1].skeleton.free)temp2=(player[1].coords-player[1].oldcoords)/multiplier/2;//velocity/2;
+                                                                                                               if(player[1].skeleton.free)temp2=player[1].skeleton.joints[i].velocity*player[1].scale/2;
+                                                                                                               if(!player[1].skeleton.free)temp=DoRotation(DoRotation(DoRotation(player[1].skeleton.joints[i].position,0,0,player[1].tilt),player[1].tilt2,0,0),0,player[1].rotation,0)*player[1].scale+player[1].coords;
+                                                                                                               if(player[1].skeleton.free)temp=player[1].skeleton.joints[i].position*player[1].scale+player[1].coords;
+                                                                                                               Sprite::MakeSprite(breathsprite, temp,temp2, 1,1,1, .6+(float)abs(Random()%100)/200-.25, 1);
                                                                                                        }
                                                                                                }
-                                                               }
+                                                                                       }
+                                                       }
 
 
-                                                               //3d sound
-                                                               static float gLoc[3];
-                                                               gLoc[0]=viewer.x;
-                                                               gLoc[1]=viewer.y;
-                                                               gLoc[2]=viewer.z;
-                                                               static float vel[3];
-                                                               vel[0]=(viewer.x-oldviewer.x)/multiplier;
-                                                               vel[1]=(viewer.y-oldviewer.y)/multiplier;
-                                                               vel[2]=(viewer.z-oldviewer.z)/multiplier;
+                                                       //3d sound
+                                                       static float gLoc[3];
+                                                       gLoc[0]=viewer.x;
+                                                       gLoc[1]=viewer.y;
+                                                       gLoc[2]=viewer.z;
+                                                       static float vel[3];
+                                                       vel[0]=(viewer.x-oldviewer.x)/multiplier;
+                                                       vel[1]=(viewer.y-oldviewer.y)/multiplier;
+                                                       vel[2]=(viewer.z-oldviewer.z)/multiplier;
 
-                                                               //Set orientation with forward and up vectors
-                                                               static XYZ upvector;
-                                                               upvector=0;
-                                                               upvector.z=-1;
+                                                       //Set orientation with forward and up vectors
+                                                       static XYZ upvector;
+                                                       upvector=0;
+                                                       upvector.z=-1;
 
-                                                               upvector=DoRotation(upvector,-rotation2+90,0,0);
-                                                               upvector=DoRotation(upvector,0,0-rotation,0);
+                                                       upvector=DoRotation(upvector,-rotation2+90,0,0);
+                                                       upvector=DoRotation(upvector,0,0-rotation,0);
 
-                                                               facing=0;
-                                                               facing.z=-1;
+                                                       facing=0;
+                                                       facing.z=-1;
 
-                                                               facing=DoRotation(facing,-rotation2,0,0);
-                                                               facing=DoRotation(facing,0,0-rotation,0);
+                                                       facing=DoRotation(facing,-rotation2,0,0);
+                                                       facing=DoRotation(facing,0,0-rotation,0);
 
 
-                                                               static float ori[6];
-                                                               ori[0] = -facing.x;
-                                                               ori[1] = facing.y;
-                                                               ori[2] = -facing.z;
-                                                               ori[3] = -upvector.x;
-                                                               ori[4] = upvector.y;
-                                                               ori[5] = -upvector.z;
+                                                       static float ori[6];
+                                                       ori[0] = -facing.x;
+                                                       ori[1] = facing.y;
+                                                       ori[2] = -facing.z;
+                                                       ori[3] = -upvector.x;
+                                                       ori[4] = upvector.y;
+                                                       ori[5] = -upvector.z;
 
-                                                               OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
-                                                               OPENAL_Update();
+                                                       OPENAL_3D_Listener_SetAttributes(&gLoc[0], &vel[0], ori[0], ori[1], ori[2], ori[3], ori[4], ori[5]);
+                                                       OPENAL_Update();
 
-                                                               oldviewer=viewer;
+                                                       oldviewer=viewer;
                }
        }
 
-       if(IsKeyDown(theKeyMap, MAC_F1_KEY)&&!freezetogglekeydown){
+       if(Input::isKeyDown(SDLK_F1)&&!freezetogglekeydown){
                Screenshot();
                freezetogglekeydown=1;
        }
 }
 
 void   Game::TickOnce(){
-       //if(!console){
-       if(!mainmenu)
-               if(directing||indialogue==-1){
+       if(mainmenu)
+               rotation+=multiplier*5;
+       else
+               if(directing||indialogue==-1) {
                        rotation+=deltah*.7;
                        if(!invertmouse)rotation2+=deltav*.7;
                        if(invertmouse)rotation2-=deltav*.7;
                        if(rotation2>90)rotation2=90;
                        if(rotation2<-70)rotation2=-70;
                }
-               if(mainmenu)rotation+=multiplier*5;
-      
-               //}
 }
 
 void   Game::TickOnceAfter(){
@@ -9330,14 +7895,6 @@ void     Game::TickOnceAfter(){
                else musicvolume[1]-=multiplier*450;
                if(musicselected==stream_music3)musicvolume[2]+=multiplier*450;
                else musicvolume[2]-=multiplier*450;
-               /*
-               if(musicselected==music1)musicvolume[0]+=multiplier*100;
-               else musicvolume[0]-=multiplier*450;
-               if(musicselected==music2)musicvolume[1]+=multiplier*150;
-               else if(player[0].dead)musicvolume[1]-=multiplier*450;
-               else musicvolume[1]-=multiplier*100;
-               if(musicselected==music3)musicvolume[2]+=multiplier*450;
-               else musicvolume[2]-=multiplier*450;*/
 
                for(i=0;i<3;i++){
                        if(musicvolume[i]<0)musicvolume[i]=0;
@@ -9359,20 +7916,6 @@ void     Game::TickOnceAfter(){
                                PlayStreamEx( stream_music3, strm[stream_music3], NULL, true);
                                OPENAL_SetPaused(channels[stream_music3], false);
                        }
-               }
-
-               if(!musictoggle){
-                       OPENAL_SetPaused(channels[music1], true);
-                       OPENAL_SetPaused(channels[stream_music2], true);
-                       OPENAL_SetPaused(channels[stream_music3], true);
-
-                       for(i=0;i<4;i++){
-                               oldmusicvolume[i]=0;
-                               musicvolume[i]=0;
-                       }
-               }
-
-               if(musictoggle){
                        if(musicvolume[0]<=0&&oldmusicvolume[0]>0){
                                OPENAL_SetPaused(channels[music1], true);
                        }
@@ -9396,334 +7939,276 @@ void  Game::TickOnceAfter(){
                        for(i=0;i<3;i++){
                                oldmusicvolume[i]=musicvolume[i];
                        }
+               } else {
+                       OPENAL_SetPaused(channels[music1], true);
+                       OPENAL_SetPaused(channels[stream_music2], true);
+                       OPENAL_SetPaused(channels[stream_music3], true);
+
+                       for(i=0;i<4;i++){
+                               oldmusicvolume[i]=0;
+                               musicvolume[i]=0;
+                       }
                }
 
                killhotspot=2;
-               if(numhotspots)
-                       for(i=0;i<numhotspots;i++){
-                               if(hotspottype[i]>10&&hotspottype[i]<20){
-                                       if(player[hotspottype[i]-10].dead==0){
-                                               killhotspot=0;
-                                       }
-                                       else if(killhotspot==2)
-                                               killhotspot=1;
+               for(i=0;i<numhotspots;i++){
+                       if(hotspottype[i]>10&&hotspottype[i]<20){
+                               if(player[hotspottype[i]-10].dead==0){
+                                       killhotspot=0;
                                }
+                               else if(killhotspot==2)
+                                       killhotspot=1;
                        }
-                       if(killhotspot==2)killhotspot=0;
+               }
+               if(killhotspot==2)killhotspot=0;
 
 
-                       winhotspot=0;
-                       if(numhotspots)
-                               for(i=0;i<numhotspots;i++){
-                                       if(hotspottype[i]==-1){
-                                               if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
-                                                       winhotspot=1;
-                                       }
-                               }
+               winhotspot=0;
+               for(i=0;i<numhotspots;i++){
+                       if(hotspottype[i]==-1){
+                               if(findDistancefast(&player[0].coords,&hotspot[i])<hotspotsize[i])
+                                       winhotspot=1;
+                       }
+               }
 
-                               int numalarmed=0;
-                               if(numplayers>1)
-                                       for(i=1;i<numplayers;i++){
-                                               if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
-                                       }
-                                       if(numalarmed>maxalarmed)maxalarmed=numalarmed;
+               int numalarmed=0;
+               for(i=1;i<numplayers;i++){
+                       if(!player[i].dead&&player[i].aitype==attacktypecutoff&&player[i].surprised<=0)numalarmed++;
+               }
+               if(numalarmed>maxalarmed)maxalarmed=numalarmed;
 
-                                       if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
-                                               if(player[0].dead&&changedelay<=0){
-                                                       changedelay=1;
-                                                       targetlevel=whichlevel;
-                                               }
-                                               alldead=1;
-                                               if(numplayers>1)
-                                                       for(i=1;i<numplayers;i++){
-                                                               if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
-                                                       }
+               if(changedelay<=0&&!loading&&!editorenabled&&gameon&&!tutoriallevel&&changedelay!=-999&&!won){
+                       if(player[0].dead&&changedelay<=0){
+                               changedelay=1;
+                               targetlevel=whichlevel;
+                       }
+                       alldead=1;
+                       for(i=1;i<numplayers;i++){
+                               if(!player[i].dead&&player[i].howactive<typedead1)alldead=0;
+                       }
 
 
-                                                       if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
-                                                               changedelay=1;
-                                                               targetlevel=whichlevel+1;
-                                                               if(targetlevel>numchallengelevels-1)targetlevel=0;
-                                                       }
-                                                       if(winhotspot||windialogue){
-                                                               changedelay=0.1;
-                                                               targetlevel=whichlevel+1;
-                                                               if(targetlevel>numchallengelevels-1)targetlevel=0;
-                                                       }
+                       if(alldead&&!player[0].dead&&maptype==mapkilleveryone){
+                               changedelay=1;
+                               targetlevel=whichlevel+1;
+                               if(targetlevel>numchallengelevels-1)targetlevel=0;
+                       }
+                       if(winhotspot||windialogue){
+                               changedelay=0.1;
+                               targetlevel=whichlevel+1;
+                               if(targetlevel>numchallengelevels-1)targetlevel=0;
+                       }
 
 
-                                                       if(killhotspot){
-                                                               changedelay=1;
-                                                               targetlevel=whichlevel+1;
-                                                               if(targetlevel>numchallengelevels-1)targetlevel=0;
-                                                       }
+                       if(killhotspot){
+                               changedelay=1;
+                               targetlevel=whichlevel+1;
+                               if(targetlevel>numchallengelevels-1)targetlevel=0;
+                       }
 
-                                                       if(changedelay>0&&!player[0].dead&&!won){
-                                                               //high scores, awards, win
-                                                               if(campaign){
-                                                                       won=1;
-                                                                       accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
-                                                                       accountcampaignchoicesmade[accountactive]++;
-                                                                       accountcampaignscore[accountactive]+=bonustotal;
-                                                                       scoreadded=1;
-                                                                       accountcampaigntime[accountactive]+=leveltime;
-                                                                       if(accountcampaignscore[accountactive]>accountcampaignhighscore[accountactive])accountcampaignhighscore[accountactive]=accountcampaignscore[accountactive];
-
-                                                                       //if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
-                                                               }
-                                                               else
-                                                               {
-                                                                       won=1;
-                                                                       if(!debugmode){
-                                                                               if(bonustotal-startbonustotal>accounthighscore[accountactive][whichlevel])accounthighscore[accountactive][whichlevel]=bonustotal-startbonustotal;
-                                                                               if(accountfasttime[accountactive][whichlevel]==0||leveltime<accountfasttime[accountactive][whichlevel])accountfasttime[accountactive][whichlevel]=leveltime;
-                                                                       }
-                                                                       if(accountprogress[accountactive]<whichlevel+1)accountprogress[accountactive]=whichlevel+1;
+                       if(changedelay>0&&!player[0].dead&&!won){
+                               //high scores, awards, win
+                               if(campaign){
+                                       accountactive->winCampaignLevel(whichchoice, bonustotal, leveltime);
+                                       scoreadded=1;
+                               }
+                               else
+                               {
+                                       accountactive->winLevel(whichlevel,bonustotal-startbonustotal,leveltime);
+                               }
+                               won=1;
+                       }
+               }
 
-                                                               }
-                                                       }
+               if(!winfreeze){
+
+                       if(leveltime<1){
+                               loading=0;
+                               changedelay=.1;
+                               alldead=0;
+                               winhotspot=0;
+                               killhotspot=0;
+                       }
+
+                       if(!editorenabled&&gameon&&!mainmenu){
+                               if(changedelay!=-999)changedelay-=multiplier/7;
+                               if(player[0].dead)targetlevel=whichlevel;
+                               if(loading==2&&!campaign){
+                                       flash();
+
+                                       fireSound(firestartsound);
+
+                                       if(!player[0].dead&&targetlevel!=whichlevel){
+                                               startbonustotal=bonustotal;
                                        }
+                                       if(player[0].dead) Loadlevel(whichlevel);
+                                       else Loadlevel(targetlevel);
 
-                                       if(!winfreeze){
+                                       fireSound();
 
-                                               if(leveltime<1){
-                                                       loading=0;
-                                                       changedelay=.1;
-                                                       alldead=0;
-                                                       winhotspot=0;
-                                                       killhotspot=0;
-                                               }
+                                       loading=3;
+                               }
+                               if(loading==2&&targetlevel==whichlevel){
+                                       flash();
+                                       loadtime=0;
 
-                                               if(!editorenabled&&gameon&&!mainmenu){
-                                                       if(changedelay!=-999)changedelay-=multiplier/7;
-                                                       if(player[0].dead)targetlevel=whichlevel;
-                                                       if(loading==2&&!campaign){
-                                                               flashr=1;
-                                                               flashg=0;
-                                                               flashb=0;
-                                                               flashamount=1;
-                                                               flashdelay=1;
-                                                               loadtime=0;
-
-                                                               float gLoc[3]={0,0,0};
-                                                               float vel[3]={0,0,0};
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                                                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                                                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                                                               OPENAL_SetVolume(channels[firestartsound], 256);
-                                                               OPENAL_SetPaused(channels[firestartsound], false);
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                                                               if(!player[0].dead&&targetlevel!=whichlevel){
-                                                                       startbonustotal=bonustotal;
-                                                               }
-                                                               if(!player[0].dead)Loadlevel(targetlevel);
-                                                               if(player[0].dead)Loadlevel(whichlevel);
+                                       fireSound(firestartsound);
 
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                                                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                               OPENAL_SetVolume(channels[fireendsound], 256);
-                                                               OPENAL_SetPaused(channels[fireendsound], false);
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
+                                       for(i=0;i<255;i++){
+                                               mapname[i]='\0';
+                                       }
+                                       mapname[0]=':';
+                                       mapname[1]='D';
+                                       mapname[2]='a';
+                                       mapname[3]='t';
+                                       mapname[4]='a';
+                                       mapname[5]=':';
+                                       mapname[6]='M';
+                                       mapname[7]='a';
+                                       mapname[8]='p';
+                                       mapname[9]='s';
+                                       mapname[10]=':';
+                                       strcat(mapname,campaignmapname[levelorder[accountactive->getCampaignChoicesMade()]]);//[campaignchoicewhich[whichchoice]]);
+                                       Loadlevel(mapname);
 
-                                                               loading=3;
-                                                       }
-                                                       if(loading==2&&targetlevel==whichlevel){
-                                                               flashr=1;
-                                                               flashg=0;
-                                                               flashb=0;
-                                                               flashamount=1;
-                                                               flashdelay=1;
-                                                               loadtime=0;
-
-                                                               float gLoc[3]={0,0,0};
-                                                               float vel[3]={0,0,0};
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                                                               PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                                                               OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                                                               OPENAL_SetVolume(channels[firestartsound], 256);
-                                                               OPENAL_SetPaused(channels[firestartsound], false);
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                                                               for(i=0;i<255;i++){
-                                                                       mapname[i]='\0';
-                                                               }
-                                                               mapname[0]=':';
-                                                               mapname[1]='D';
-                                                               mapname[2]='a';
-                                                               mapname[3]='t';
-                                                               mapname[4]='a';
-                                                               mapname[5]=':';
-                                                               mapname[6]='M';
-                                                               mapname[7]='a';
-                                                               mapname[8]='p';
-                                                               mapname[9]='s';
-                                                               mapname[10]=':';
-                                                               strcat(mapname,campaignmapname[levelorder[accountcampaignchoicesmade[accountactive]]]);//[campaignchoicewhich[whichchoice]]);
-                                                               Loadlevel(mapname);
-
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 9999.0f, 99999.0f);
-                                                               PlaySoundEx( fireendsound, samp[fireendsound], NULL, true);
-                                                               OPENAL_3D_SetAttributes(channels[fireendsound], gLoc, vel);
-                                                               OPENAL_SetVolume(channels[fireendsound], 256);
-                                                               OPENAL_SetPaused(channels[fireendsound], false);
-                                                               OPENAL_Sample_SetMinMaxDistance(samp[fireendsound], 8.0f, 2000.0f);
+                                       fireSound();
 
-                                                               loading=3;
-                                                       }
-                                                       if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
-                                                       if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
-                        {
-                                                                       if(whichlevel!=-2&&!loading&&!player[0].dead){
-                                                                               winfreeze=1;
-                                                                               changedelay=-999;
-                                                                       }
-                                                                       if(player[0].dead)loading=1;
-                                                               }
-                                                       }
+                                       loading=3;
+                               }
+                               if(changedelay<=-999&&whichlevel!=-2&&!loading&&(player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(killhotspot))&&!winfreeze)loading=1;
+                               if((player[0].dead||(alldead&&maptype==mapkilleveryone)||(winhotspot)||(windialogue)||(killhotspot))&&changedelay<=0){
+                       {
+                                               if(whichlevel!=-2&&!loading&&!player[0].dead){
+                                                       winfreeze=1;
+                                                       changedelay=-999;
                                                }
+                                               if(player[0].dead)loading=1;
+                                       }
+                               }
+                       }
 
-                                               if(campaign)
-                                                       if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
-                                                               if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
-                                                                       endgame=1;
-                                                               }
-                                                       }
-                                                       else if(mainmenu==0&&winfreeze){
-                                                               if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
-                                                                       stealthloading=1;
-                                                               else stealthloading=0;
-
-                                                               if(!stealthloading){
-                                                                       float gLoc[3]={0,0,0};
-                                                                       float vel[3]={0,0,0};
-                                                                       OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 9999.0f, 99999.0f);
-                                                                       PlaySoundEx( firestartsound, samp[firestartsound], NULL, true);
-                                                                       OPENAL_3D_SetAttributes(channels[firestartsound], gLoc, vel);
-                                                                       OPENAL_SetVolume(channels[firestartsound], 256);
-                                                                       OPENAL_SetPaused(channels[firestartsound], false);
-                                                                       OPENAL_Sample_SetMinMaxDistance(samp[firestartsound], 8.0f, 2000.0f);
-
-                                                                       flashr=1;
-                                                                       flashg=0;
-                                                                       flashb=0;
-                                                                       flashamount=1;
-                                                                       flashdelay=1;
-                                                               }
+                       if(campaign)
+                               if(mainmenu==0&&winfreeze&&(campaignchoosenext[campaignchoicewhich[whichchoice]])==1){
+                                       if(campaignnumnext[campaignchoicewhich[whichchoice]]==0){
+                                               endgame=1;
+                                       }
+                               }
+                               else if(mainmenu==0&&winfreeze){
+                                       if(campaignchoosenext[campaignchoicewhich[whichchoice]]==2)
+                                               stealthloading=1;
+                                       else stealthloading=0;
 
-                                                               startbonustotal=0;
-
-                                                               ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
-                                                               //campaignnumlevels=0;
-                                                               //accountcampaignchoicesmade[accountactive]=0;
-                                                               ipstream.ignore(256,':');
-                                                               ipstream >> campaignnumlevels;
-                                                               for(i=0;i<campaignnumlevels;i++){
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream.ignore(256,' ');
-                                                                       ipstream >> campaignmapname[i];
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream >> campaigndescription[i];
-                                                                       for(j=0;j<256;j++){
-                                                                               if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
-                                                                       }
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream >> campaignchoosenext[i];
-                                                                       ipstream.ignore(256,':');
-                                                                       ipstream >> campaignnumnext[i];
-                                                                       if(campaignnumnext[i])
-                                                                               for(j=0;j<campaignnumnext[i];j++){
-                                                                                       ipstream.ignore(256,':');
-                                                                                       ipstream >> campaignnextlevel[i][j];
-                                                                                       campaignnextlevel[i][j]-=1;
-                                                                               }
-                                                                               ipstream.ignore(256,':');
-                                                                               ipstream >> campaignlocationx[i];
-                                                                               ipstream.ignore(256,':');
-                                                                               ipstream >> campaignlocationy[i];
-                                                               }
-                                                               ipstream.close();
+                                       if(!stealthloading){
+                                               float gLoc[3]={0,0,0};
+                                               float vel[3]={0,0,0};
+                                               fireSound(firestartsound);
 
-                                                               for(i=0;i<campaignnumlevels;i++){
-                                                                       levelvisible[i]=0;
-                                                                       levelhighlight[i]=0;
-                                                               }
+                                               flash();
+                                       }
 
+                                       startbonustotal=0;
 
-                                                               for(i=0;i<campaignnumlevels;i++){
-                                                                       levelvisible[i]=0;
-                                                                       levelhighlight[i]=0;
-                                                               }
+                                       ifstream ipstream(ConvertFileName(":Data:Campaigns:main.txt"));
+                                       ipstream.ignore(256,':');
+                                       ipstream >> campaignnumlevels;
+                                       for(i=0;i<campaignnumlevels;i++){
+                                               ipstream.ignore(256,':');
+                                               ipstream.ignore(256,':');
+                                               ipstream.ignore(256,' ');
+                                               ipstream >> campaignmapname[i];
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaigndescription[i];
+                                               for(j=0;j<256;j++){
+                                                       if(campaigndescription[i][j]=='_')campaigndescription[i][j]=' ';
+                                               }
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignchoosenext[i];
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignnumnext[i];
+                                               for(j=0;j<campaignnumnext[i];j++){
+                                                       ipstream.ignore(256,':');
+                                                       ipstream >> campaignnextlevel[i][j];
+                                                       campaignnextlevel[i][j]-=1;
+                                               }
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignlocationx[i];
+                                               ipstream.ignore(256,':');
+                                               ipstream >> campaignlocationy[i];
+                                       }
+                                       ipstream.close();
 
-                                                               levelorder[0]=0;
-                                                               levelvisible[0]=1;
-                                                               if(accountcampaignchoicesmade[accountactive])
-                                                                       for(i=0;i<accountcampaignchoicesmade[accountactive];i++){
-                                                                               levelorder[i+1]=campaignnextlevel[levelorder[i]][accountcampaignchoices[accountactive][i]];
-                                                                               levelvisible[levelorder[i+1]]=1;
-                                                                       }
-                                                                       int whichlevelstart;
-                                                                       whichlevelstart=accountcampaignchoicesmade[accountactive]-1;
-                                                                       if(whichlevelstart<0){
-                                                                               campaignchoicenum=1;
-                                                                               campaignchoicewhich[0]=0;
-                                                                       }
-                                                                       else
-                                                                       {
-                                                                               campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
-                                                                               if(campaignchoicenum)
-                                                                                       for(i=0;i<campaignchoicenum;i++){
-                                                                                               campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
-                                                                                               levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                                                                                               levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
-                                                                                       }
-                                                                       }
+                                       for(i=0;i<campaignnumlevels;i++){
+                                               levelvisible[i]=0;
+                                               levelhighlight[i]=0;
+                                       }
 
-                                                                       loading=2;
-                                                                       loadtime=0;
-                                                                       targetlevel=7;
-                                                                       //if(firstload)TickOnceAfter();
-                                                                       if(!firstload)LoadStuff();
-                                                                       //else {
-                                                                       for(i=0;i<255;i++){
-                                                                               mapname[i]='\0';
-                                                                       }
-                                                                       mapname[0]=':';
-                                                                       mapname[1]='D';
-                                                                       mapname[2]='a';
-                                                                       mapname[3]='t';
-                                                                       mapname[4]='a';
-                                                                       mapname[5]=':';
-                                                                       mapname[6]='M';
-                                                                       mapname[7]='a';
-                                                                       mapname[8]='p';
-                                                                       mapname[9]='s';
-                                                                       mapname[10]=':';
-
-                                                                       //accountcampaignchoices[accountactive][accountcampaignchoicesmade[accountactive]]=whichchoice;
-                                                                       //accountcampaignchoicesmade[accountactive]++;
-
-
-                                                                       strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
-                                                                       whichchoice=0;
-                                                                       visibleloading=1;
-                                                                       stillloading=1;
-                                                                       Loadlevel(mapname);
-                                                                       campaign=1;
-                                                                       mainmenu=0;
-                                                                       gameon=1;
-                                                                       OPENAL_SetPaused(channels[stream_music3], true);
-
-                                                                       stealthloading=0;
-                                                       }
 
-                                                       if(loading==3)loading=0;
+                                       for(i=0;i<campaignnumlevels;i++){
+                                               levelvisible[i]=0;
+                                               levelhighlight[i]=0;
+                                       }
+
+                                       levelorder[0]=0;
+                                       levelvisible[0]=1;
+                                       for(i=0;i<accountactive->getCampaignChoicesMade();i++){
+                                               levelorder[i+1]=campaignnextlevel[levelorder[i]][accountactive->getCampaignChoice(i)];
+                                               levelvisible[levelorder[i+1]]=1;
+                                       }
+                                       int whichlevelstart;
+                                       whichlevelstart=accountactive->getCampaignChoicesMade()-1;
+                                       if(whichlevelstart<0){
+                                               campaignchoicenum=1;
+                                               campaignchoicewhich[0]=0;
+                                       }
+                                       else
+                                       {
+                                               campaignchoicenum=campaignnumnext[levelorder[whichlevelstart]];
+                                               for(i=0;i<campaignchoicenum;i++){
+                                                       campaignchoicewhich[i]=campaignnextlevel[levelorder[whichlevelstart]][i];
+                                                       levelvisible[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
+                                                       levelhighlight[campaignnextlevel[levelorder[whichlevelstart]][i]]=1;
+                                               }
+                                       }
 
+                                       loading=2;
+                                       loadtime=0;
+                                       targetlevel=7;
+                                       //if(firstload)TickOnceAfter();
+                                       if(!firstload)LoadStuff();
+                                       //else {
+                                       for(i=0;i<255;i++){
+                                               mapname[i]='\0';
                                        }
+                                       mapname[0]=':';
+                                       mapname[1]='D';
+                                       mapname[2]='a';
+                                       mapname[3]='t';
+                                       mapname[4]='a';
+                                       mapname[5]=':';
+                                       mapname[6]='M';
+                                       mapname[7]='a';
+                                       mapname[8]='p';
+                                       mapname[9]='s';
+                                       mapname[10]=':';
+
+                                       strcat(mapname,campaignmapname[campaignchoicewhich[0]]);
+                                       whichchoice=0;
+                                       visibleloading=1;
+                                       stillloading=1;
+                                       Loadlevel(mapname);
+                                       campaign=1;
+                                       mainmenu=0;
+                                       gameon=1;
+                                       OPENAL_SetPaused(channels[stream_music3], true);
+
+                                       stealthloading=0;
+                               }
+
+                               if(loading==3)loading=0;
+
+                       }
 
-                                       oldmusictype=musictype;
+                       oldmusictype=musictype;
        }
 
        facing=0;