]> git.jsancho.org Git - lugaru.git/commitdiff
oops, I forgot to add some files.
authorCôme BERNIGAUD <come.bernigaud@gmail.com>
Fri, 4 Jun 2010 10:08:12 +0000 (12:08 +0200)
committerCôme BERNIGAUD <come.bernigaud@gmail.com>
Fri, 4 Jun 2010 10:08:12 +0000 (12:08 +0200)
Source/Account.cpp [new file with mode: 0644]
Source/Account.h [new file with mode: 0644]
Source/Game.cpp [new file with mode: 0644]
Source/Input.cpp [new file with mode: 0644]
Source/Input.h [new file with mode: 0644]

diff --git a/Source/Account.cpp b/Source/Account.cpp
new file mode 100644 (file)
index 0000000..31e99af
--- /dev/null
@@ -0,0 +1,221 @@
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010 - MCMic
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#include "Account.h"
+#include "binio.h"
+#include <fstream>
+#include "MacCompatibility.h"
+#include "string.h"
+
+using namespace std;
+
+extern bool debugmode;
+
+vector<Account*> Account::accounts = vector<Account*>();
+
+Account::Account(string n) {
+       name = string(n);
+       difficulty = 0;
+       progress = 0;
+       points = 0;
+       for(int i=0;i<50;highscore[i++] = 0);
+       for(int i=0;i<50;fasttime[i++] = 0);
+       for(int i=0;i<60;unlocked[i++] = 0);
+       campaignhighscore = 0;
+       campaignfasttime = 0;
+       campaignscore = 0;
+       campaigntime = 0;
+       campaignchoicesmade = 0;
+       for(int i=0;i<5000;campaignchoices[i++] = 0);
+}
+
+Account* Account::add(string name) {
+       accounts.push_back(new Account(name));
+       return accounts.back();
+}
+
+Account* Account::get(int i) {
+       if(i<accounts.size()) {
+               return accounts[i];
+       } else
+               return NULL;
+}
+
+void Account::destroy(int i) {
+       accounts.erase(accounts.begin()+i);
+}
+Account* Account::destroy(Account* a) {
+       for(int i=0; i<accounts.size(); i++) {
+               if(accounts[i]==a) {
+                       accounts.erase(accounts.begin()+i);
+                       return NULL;
+               }
+       }
+       printf("Unexpected error : User %s not found %d\n",a->getName(),a);
+       return accounts.front();
+}
+
+int Account::getDifficulty() {
+       return difficulty;
+}
+
+void Account::endGame() {
+       campaignchoicesmade=0;
+       campaignscore=0;
+       campaigntime=0;
+}
+
+void Account::winCampaignLevel(int choice, float score, float time) {
+       campaignchoices[campaignchoicesmade++] = choice;
+       setCampaignScore(campaignscore+score);
+       campaigntime = time;
+}
+
+void Account::winLevel(int level, float score, float time) {
+       if(!debugmode) {
+               if(score>highscore[level])
+                       highscore[level]=score;
+               if(time<fasttime[level]||fasttime[level]==0)
+                       fasttime[level]=time;
+       }
+       if(progress<level+1)
+               progress=level+1;
+}
+
+Account* Account::loadFile(string filename) {
+       FILE *tfile;
+       int numaccounts;
+       int accountactive;
+       int j;
+       
+       tfile=fopen(ConvertFileName(filename.c_str()), "rb" );
+       
+       if(tfile)
+       {
+               funpackf(tfile, "Bi", &numaccounts);
+               funpackf(tfile, "Bi", &accountactive);
+               printf("number of accounts %d\n",numaccounts);
+               for(int i=0;i<numaccounts;i++)
+               {
+                       printf("loading account %d/%d\n",i,numaccounts);
+                       Account* acc = new Account();
+                       funpackf(tfile, "Bf", &(acc->campaigntime));
+                       funpackf(tfile, "Bf", &(acc->campaignscore));
+                       funpackf(tfile, "Bf", &(acc->campaignfasttime));
+                       funpackf(tfile, "Bf", &(acc->campaignhighscore));
+                       funpackf(tfile, "Bi", &(acc->difficulty));
+                       funpackf(tfile, "Bi", &(acc->progress));
+                       funpackf(tfile, "Bi", &(acc->campaignchoicesmade));
+                       for(j=0;j<acc->campaignchoicesmade;j++)
+                       {
+                               funpackf(tfile, "Bi", &(acc->campaignchoices[j]));
+                               if (acc->campaignchoices[j] >= 10)
+                               {
+                                       acc->campaignchoices[j] = 0;
+                               }
+                       }
+                       funpackf(tfile, "Bf", &(acc->points));
+                       for(j=0;j<50;j++)
+                       {
+                               funpackf(tfile, "Bf", &(acc->highscore[j]));
+                               funpackf(tfile, "Bf", &(acc->fasttime[j]));
+                       }
+                       for(j=0;j<60;j++)
+                       {
+                               funpackf(tfile, "Bb",  &(acc->unlocked[j]));
+                       }
+                       int temp;
+                       char ctemp;
+                       funpackf(tfile, "Bi",  &temp);
+                       for(j=0;j<temp;j++)
+                       {
+                               funpackf(tfile, "Bb",  &ctemp);
+                               acc->name.append(1,ctemp);
+                       }
+                       if(!strcmp(acc->name.c_str(),""))
+                               acc->name="Lugaru Player"; // no empty player name security.
+                       accounts.push_back(acc);
+               }
+
+               fclose(tfile);
+               return get(accountactive);
+       } else {
+               printf("filenotfound\n");
+               return NULL;
+       }
+}
+
+void Account::saveFile(string filename, Account* accountactive) {
+       FILE *tfile;
+       int numaccounts;
+       int j;
+       
+       tfile=fopen(ConvertFileName(filename.c_str()), "wb" );
+       if(tfile)
+       {
+               printf("writing %d accounts :\n",getNbAccounts());
+               fpackf(tfile, "Bi", getNbAccounts());
+               fpackf(tfile, "Bi", indice(accountactive));
+               
+               for(int i=0;i<getNbAccounts();i++)
+               {
+                       Account* a = Account::get(i);
+                       printf("writing account %d/%d (%s)\n",i+1,getNbAccounts(),a->getName());
+                       fpackf(tfile, "Bf", a->campaigntime);
+                       fpackf(tfile, "Bf", a->campaignscore);
+                       fpackf(tfile, "Bf", a->campaignfasttime);
+                       fpackf(tfile, "Bf", a->campaignhighscore);
+                       fpackf(tfile, "Bi", a->difficulty);
+                       fpackf(tfile, "Bi", a->progress);
+                       fpackf(tfile, "Bi", a->campaignchoicesmade);
+                       for(j=0;j<a->campaignchoicesmade;j++)
+                       {
+                               fpackf(tfile, "Bi", a->campaignchoices[j]);
+                       }
+                       fpackf(tfile, "Bf", a->points);
+                       for(j=0;j<50;j++)
+                       {
+                               fpackf(tfile, "Bf", a->highscore[j]);
+                               fpackf(tfile, "Bf", a->fasttime[j]);
+                       }
+                       for(j=0;j<60;j++)
+                       {
+                               fpackf(tfile, "Bb",  a->unlocked[j]);
+                       }
+                       fpackf(tfile, "Bi",  a->name.size());
+                       for(j=0;j<a->name.size();j++)
+                       {
+                               fpackf(tfile, "Bb",  a->name[j]);
+                       }
+               }
+
+               fclose(tfile);
+       }
+}
+
+int Account::indice(Account* a) {
+       for(int i=0; i < accounts.size(); i++) {
+               if(accounts[i]==a)
+                       return i;
+       }
+       return -1;
+}
diff --git a/Source/Account.h b/Source/Account.h
new file mode 100644 (file)
index 0000000..3cf94dd
--- /dev/null
@@ -0,0 +1,90 @@
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010 - MCMic
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#ifndef _Account_H_
+#define _Account_H_
+
+#include <vector>
+#include <string>
+#include <fstream>
+
+
+class Account {
+       public:
+               static void destroy(int i);
+               static Account* destroy(Account* a);
+               static Account* add(std::string name);
+               static Account* get(int i);
+               static Account* loadFile(std::string filename);
+               static void saveFile(std::string filename, Account* accountactive);
+               static int indice(Account* a);
+               
+               void endGame();
+               void winCampaignLevel(int choice, float score, float time);
+               void winLevel(int level, float score, float time);
+               
+               // getter and setters
+               int getDifficulty();
+               void setDifficulty(int i) { difficulty = i; };
+               const char* getName() { return name.c_str(); };
+               float getCampaignScore() { return campaignscore; };
+               int getCampaignChoicesMade() { return campaignchoicesmade; };
+               int getCampaignChoice(int i) { return campaignchoices[i]; };
+               void setCampaignScore(int s) {
+                       campaignscore=s;
+                       if(s>campaignhighscore)
+                               campaignhighscore=s;
+               };
+               void setCampaignFinalTime(float t) {
+                               campaigntime = t;
+                               if((t<campaignfasttime) || (campaignfasttime==0) && (t!=0))
+                                       campaignfasttime = t;
+               };
+               float getCampaignFasttime() { return campaignfasttime; };
+               void resetFasttime() { campaignfasttime = 0; };
+               float getCampaignHighScore() { return campaignhighscore; };
+               float getHighScore(int i) { return highscore[i]; };
+               float getFastTime(int i) { return fasttime[i]; };
+               int getProgress() { return progress; };
+               
+               static int getNbAccounts() { return accounts.size(); };
+       private:
+               Account(std::string n="");
+               int difficulty;
+               int progress;
+               float points;
+               float highscore[50];
+               float fasttime[50];
+               bool unlocked[60];
+               std::string name;
+               float campaignhighscore;
+               float campaignfasttime;
+               float campaignscore;
+               float campaigntime;
+               int campaignchoicesmade;
+               int campaignchoices[5000]; // should really disappear. I'd use a vector or something like that.
+       
+       //statics
+               static std::vector<Account*> accounts;
+};
+
+#endif
diff --git a/Source/Game.cpp b/Source/Game.cpp
new file mode 100644 (file)
index 0000000..776a0e7
--- /dev/null
@@ -0,0 +1,380 @@
+#include "Game.h"
+#include "openal_wrapper.h"
+#include "SDL_thread.h"
+
+extern int mainmenu;
+extern OPENAL_SAMPLE *samp[100];
+extern int channels[100];
+extern "C" void PlaySoundEx(int channel, OPENAL_SAMPLE *sptr, OPENAL_DSPUNIT *dsp, signed char startpaused);
+
+
+
+Game::Game()
+{
+       terraintexture = 0;
+       terraintexture2 = 0;
+       terraintexture3 = 0;
+       screentexture = 0;
+       screentexture2 = 0;
+       logotexture = 0;
+       loadscreentexture = 0;
+       Maparrowtexture = 0;
+       Mapboxtexture = 0;
+       Mapcircletexture = 0;
+       cursortexture = 0;
+
+       memset(Mainmenuitems, 0, sizeof(Mainmenuitems));
+
+       nummenuitems = 0;
+
+       memset(startx, 0, sizeof(startx));
+       memset(starty, 0, sizeof(starty));
+       memset(endx, 0, sizeof(endx));
+       memset(endy, 0, sizeof(endy));
+
+       memset(selectedlong, 0, sizeof(selectedlong));
+       memset(offsetx, 0, sizeof(offsetx));
+       memset(offsety, 0, sizeof(offsety));
+       memset(movex, 0, sizeof(movex));
+       memset(movey, 0, sizeof(movey));
+       memset(endy, 0, sizeof(endy));
+
+       transition = 0;
+       anim = 0;
+       selected = 0;
+       loaddistrib = 0;
+       keyselect = 0;
+       indemo = 0;
+
+       won = 0;
+
+       entername = 0;
+
+       memset(menustring, 0, sizeof(menustring));
+       memset(registrationname, 0, sizeof(registrationname));
+       registrationnumber = 0;
+
+       newdetail = 0;
+       newscreenwidth = 0;
+       newscreenheight = 0;
+
+       gameon = 0;
+       deltah = 0,deltav = 0;
+       mousecoordh = 0,mousecoordv = 0;
+       oldmousecoordh = 0,oldmousecoordv = 0;
+       rotation = 0,rotation2 = 0;
+
+//     SkyBox skybox;
+
+       cameramode = 0;
+       cameratogglekeydown = 0;
+       chattogglekeydown = 0;
+       olddrawmode = 0;
+       drawmode = 0;
+       drawmodetogglekeydown = 0;
+       explodetogglekeydown = 0;
+       detailtogglekeydown = 0;
+       firstload = 0;
+       oldbutton = 0;
+
+       leveltime = 0;
+       loadtime = 0;
+
+//     Model hawk;
+
+//     XYZ hawkcoords;
+//     XYZ realhawkcoords;
+
+       hawktexture = 0;
+       hawkrotation = 0;
+       hawkcalldelay = 0;
+/*
+       Model eye;
+       Model iris;
+       Model cornea;
+*/
+       stealthloading = 0;
+
+       campaignnumlevels = 0;
+
+       memset(campaignmapname, 0, sizeof(campaignmapname));
+       memset(campaigndescription, 0, sizeof(campaigndescription));
+       memset(campaignchoosenext, 0, sizeof(campaignchoosenext));
+       memset(campaignnumnext, 0, sizeof(campaignnumnext));
+       memset(campaignnextlevel, 0, sizeof(campaignnextlevel));
+       int campaignchoicesmade;
+       memset(campaignchoices, 0, sizeof(campaignchoices));
+       memset(campaignlocationx, 0, sizeof(campaignlocationx));
+       memset(campaignlocationy, 0, sizeof(campaignlocationy));
+       memset(campaignlocationy, 0, sizeof(campaignlocationy));
+
+       campaignchoicenum = 0;
+
+       memset(campaignchoicewhich, 0, sizeof(campaignchoicewhich));
+
+       whichchoice = 0;
+
+       numlevelspassed = 0;
+
+       memset(levelorder, 0, sizeof(levelorder));
+       memset(levelvisible, 0, sizeof(levelvisible));
+       memset(levelhighlight, 0, sizeof(levelhighlight));
+
+       minimap = 0;
+
+       musictype = 0,oldmusictype = 0,oldoldmusictype = 0;
+       realthreat = 0;
+
+//     Model rabbit;
+//     XYZ rabbitcoords;
+
+//     XYZ mapcenter;
+       mapradius = 0;
+
+//     Text text;
+       fps = 0;
+
+//     XYZ cameraloc;
+       cameradist = 0;
+
+       envtogglekeydown = 0;
+       slomotogglekeydown = 0;
+       texturesizetogglekeydown = 0;
+       freezetogglekeydown = 0;
+       drawtoggle = 0;
+
+       editorenabled = 0;
+       editortype = 0;
+       editorsize = 0;
+       editorrotation = 0;
+       editorrotation2 = 0;
+
+       brightness = 0;
+
+       quit = 0;
+       tryquit = 0;
+
+//     XYZ pathpoint[30];
+       numpathpoints = 0;
+       memset(numpathpointconnect, 0, sizeof(numpathpointconnect));
+       memset(pathpointconnect, 0, sizeof(pathpointconnect));
+       pathpointselected = 0;
+
+       endgame = 0;
+       scoreadded = 0;
+       numchallengelevels = 0;
+
+       console = 0;
+       archiveselected = 0;
+
+       memset(consoletext, 0, sizeof(consoletext));
+       memset(consolechars, 0, sizeof(consolechars));
+       chatting = 0;
+       memset(displaytext, 0, sizeof(displaytext));
+       memset(displaychars, 0, sizeof(displaychars));
+       memset(displaytime, 0, sizeof(displaytime));
+       displayblinkdelay = 0;
+       displayblink = 0;
+       displayselected = 0;
+       consolekeydown = 0;
+       consoletogglekeydown = 0;
+       consoleblinkdelay = 0;
+       consoleblink = 0;
+       consoleselected = 0;
+       memset(togglekey, 0, sizeof(togglekey));
+       memset(togglekeydelay, 0, sizeof(togglekeydelay));
+       registernow = 0;
+       autocam = 0;
+
+       crouchkey = 0,jumpkey = 0,forwardkey = 0,chatkey = 0,backkey = 0,leftkey = 0,rightkey = 0,drawkey = 0,throwkey = 0,attackkey = 0;
+       oldattackkey = 0;
+
+       loading = 0;
+       talkdelay = 0;
+
+       numboundaries = 0;
+//     XYZ boundary[360];
+
+       whichlevel = 0;
+       oldenvironment = 0;
+       targetlevel = 0;
+       changedelay = 0;
+
+       memset(musicvolume, 0, sizeof(musicvolume));
+       memset(oldmusicvolume, 0, sizeof(oldmusicvolume));
+       musicselected = 0;
+       change = 0;
+       
+//------------
+
+       waiting = false;
+       mainmenu = 0;
+       
+       accountactive = NULL;
+}
+
+typedef struct {
+       Game* game;
+       void (Game::*method)();
+} params_thread;
+
+void Game::fireSound(int sound) {
+       float gLoc[3]={0,0,0};
+       float vel[3]={0,0,0};
+       OPENAL_Sample_SetMinMaxDistance(samp[sound], 9999.0f, 99999.0f);
+       PlaySoundEx( sound, samp[sound], NULL, true);
+       OPENAL_3D_SetAttributes(channels[sound], gLoc, vel);
+       OPENAL_SetVolume(channels[sound], 256);
+       OPENAL_SetPaused(channels[sound], false);
+       OPENAL_Sample_SetMinMaxDistance(samp[sound], 8.0f, 2000.0f);
+}
+
+void Game::inputText() {
+       waiting=true;
+       params_thread* data = new params_thread;
+    data->game = this;
+    data->method = &Game::inputText_thread;
+       SDL_Thread* thread = SDL_CreateThread(Game::thread, data);
+    if ( thread == NULL ) {
+        fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
+               waiting=false;
+        return;
+    }
+}
+
+void Game::inputText_thread() {
+       SDL_Event evenement;
+       SDL_EnableKeyRepeat(400, 40);
+       SDL_EnableUNICODE(true);
+
+       while(waiting) {
+               int i;
+               SDL_WaitEvent(&evenement);
+               
+               switch(evenement.type) {
+                       case SDL_KEYDOWN:
+                               if(evenement.key.keysym.sym == SDLK_ESCAPE) {
+                                       for(i=0;i<255;i++){
+                                               displaytext[0][i]=' ';
+                                       }
+                                       displaychars[0]=0;
+                                       displayselected=0;
+                                       mainmenutogglekeydown=1;
+                                       waiting=false;
+                               } else if(evenement.key.keysym.sym==SDLK_BACKSPACE&&displayselected!=0){
+                                       for(i=displayselected-1;i<255;i++){
+                                               displaytext[0][i]=displaytext[0][i+1];
+                                       }
+                                       displaytext[0][255]=' ';
+                                       displayselected--;
+                                       displaychars[0]--;
+                               } else if(evenement.key.keysym.sym==SDLK_DELETE&&displayselected!=0){
+                                       for(i=displayselected;i<255;i++){
+                                               displaytext[0][i]=displaytext[0][i+1];
+                                       }
+                                       displaytext[0][255]=' ';
+                                       displaychars[0]--;
+                               } else if(evenement.key.keysym.sym==SDLK_LEFT&&displayselected!=0){
+                                       displayselected--;
+                               } else if(evenement.key.keysym.sym==SDLK_RIGHT&&displayselected<displaychars[0]){
+                                       displayselected++;
+                               } else if(evenement.key.keysym.sym==SDLK_RETURN) {
+                                       if(displaychars[0]){
+                                               accountactive = Account::add(string(displaytext[0]));
+
+                                               mainmenu=8;
+
+                                               flash();
+
+                                               fireSound(firestartsound);
+
+                                               for(i=0;i<255;i++){
+                                                       displaytext[0][i]=' ';
+                                               }
+                                               displaychars[0]=0;
+
+                                               displayselected=0;
+                                       }
+                                       waiting=false;
+                               } else if(evenement.key.keysym.unicode&&displaychars[0]<60) {
+                                       for(i=255;i>=displayselected+1;i--){
+                                               displaytext[0][i]=displaytext[0][i-1];
+                                       }
+                                       displaytext[0][displayselected]=evenement.key.keysym.unicode;
+                                       displayselected++;
+                                       displaychars[0]++;
+                                       printf("%c\n",evenement.key.keysym.unicode);
+                               }
+                       break;
+               }
+       }
+       entername=0;
+       SDL_EnableKeyRepeat(0,0); // disable key repeat
+       SDL_EnableUNICODE(false);
+}
+
+void Game::setKeySelected() {
+       waiting=true;
+       params_thread* data = new params_thread;
+    data->game = this;
+    data->method = &Game::setKeySelected_thread;
+    printf("launch thread\n");
+       SDL_Thread* thread = SDL_CreateThread(Game::thread, data);
+    if ( thread == NULL ) {
+        fprintf(stderr, "Unable to create thread: %s\n", SDL_GetError());
+               waiting=false;
+        return;
+    }
+}
+
+void Game::setKeySelected_thread() {
+       int keycode=-1;
+       SDL_Event evenement;
+       while(keycode==-1) {
+               SDL_WaitEvent(&evenement);
+               switch(evenement.type) {
+                       case SDL_KEYDOWN:
+                               keycode = evenement.key.keysym.sym;
+                       break;
+                       case SDL_MOUSEBUTTONDOWN:
+                               keycode = SDLK_LAST+evenement.button.button;
+                       break;
+                       default:
+                       break;
+               }
+       }
+       if(keycode != SDLK_ESCAPE) {
+               fireSound();
+               switch(keyselect) {
+                       case 0:forwardkey=keycode;
+                       break;
+                       case 1:backkey=keycode;
+                       break;
+                       case 2:leftkey=keycode;
+                       break;
+                       case 3:rightkey=keycode;
+                       break;
+                       case 4:crouchkey=keycode;
+                       break;
+                       case 5:jumpkey=keycode;
+                       break;
+                       case 6:drawkey=keycode;
+                       break;
+                       case 7:throwkey=keycode;
+                       break;
+                       case 8:attackkey=keycode;
+                       break;
+                       default:
+                       break;
+               }
+       }
+       keyselect=-1;
+       waiting=false;
+}
+
+int Game::thread(void *data) {
+       params_thread* pt = (params_thread*)data;
+    if(pt) {
+        (pt->game->*(pt->method))();
+    }
+}
diff --git a/Source/Input.cpp b/Source/Input.cpp
new file mode 100644 (file)
index 0000000..41229e3
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010 - MCMic
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+/**> HEADER FILES <**/
+#include "Input.h"
+
+extern bool keyboardfrozen;
+
+bool Input::isKeyDown(int k) {
+       if(keyboardfrozen)return 0; // vraiment utile? à vérifier
+       Uint8 *keystate = SDL_GetKeyState(NULL);
+       if(k<SDLK_LAST)
+               return keystate[k];
+       else
+               return SDL_GetMouseState(NULL,NULL)&SDL_BUTTON(k-SDLK_LAST);
+}
+
+const char* Input::keyToChar(unsigned short i) {
+       if(i<SDLK_LAST)
+               return SDL_GetKeyName(SDLKey(i));
+       else if(i==SDLK_LAST+SDL_BUTTON_LEFT)
+               return "mouse1";
+       else if(i==SDLK_LAST+SDL_BUTTON_RIGHT)
+               return "mouse2";
+       else if(i==SDLK_LAST+SDL_BUTTON_MIDDLE)
+               return "mouse3";
+       else
+               return "unknown";
+}
+
diff --git a/Source/Input.h b/Source/Input.h
new file mode 100644 (file)
index 0000000..571f33e
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+Copyright (C) 2003, 2010 - Wolfire Games
+Copyright (C) 2010 - MCMic
+
+This file is part of Lugaru.
+
+Lugaru is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License
+as published by the Free Software Foundation; either version 2
+of the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+
+See the GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+*/
+
+#ifndef _Input_H_
+#define _Input_H_
+
+/**> HEADER FILES <**/
+#include "SDL.h"
+#include "Game.h"
+
+class Input {
+       public:
+               static bool isKeyDown(int k);
+               static const char* keyToChar(unsigned short which);
+               static void setKeyFor(Game* g);
+};
+
+#endif