]> git.mxchange.org Git - quix0rs-blobwars.git/blobdiff - src/player.cpp
Don't link pak tool with SDL.
[quix0rs-blobwars.git] / src / player.cpp
index bb0c202c0df8ad833bd165fef1b6b851dafb45b2..cc793b9faa67d9970c9c8275ecb096a54e425d4a 100644 (file)
@@ -1,5 +1,5 @@
 /*
-Copyright (C) 2004 Parallel Realities
+Copyright (C) 2004-2011 Parallel Realities
 
 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
@@ -20,6 +20,83 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "player.h"
 
+int medalWorker(void *data)
+{
+       char *tname = (char*)data;
+       
+       SDL_mutexP(medalServer.lock);
+       
+       int type = medalServer.postMedal(tname);
+       
+       while (!graphics.canShowMedalMessage())
+       {
+               SDL_Delay(100);
+       }
+       
+       SDL_Delay(100);
+       
+       if (type >= 1 && type <= 3)
+       {
+               audio.playSound(SND_ITEM, CH_ANY);
+               graphics.showMedalMessage(type, medalServer.getMessage());
+               
+               if (medalServer.hasRuby())
+               {
+                       while (!graphics.canShowMedalMessage())
+                       {
+                               SDL_Delay(100);
+                       }
+                       
+                       SDL_Delay(100);
+                       
+                       audio.playSound(SND_ITEM, CH_ANY);
+                       graphics.showMedalMessage(4, medalServer.getRubyMessage());
+               }
+       }
+       
+       SDL_mutexV(medalServer.lock);
+       
+       delete[] tname;
+       
+       return type;
+}
+
+void presentPlayerMedal(const char *tname)
+{
+       // Copy the input, so that threading
+       // doesn't trip us up!
+       char *data = new char[128];
+       strlcpy(data, tname, 128);
+       
+       SDL_Thread *thread = SDL_CreateThread(medalWorker, (void*)data);
+       
+       if (thread == NULL)
+       {
+               printf("Unable to create thread: %s\n", SDL_GetError());
+               printf("Calling medal server directly\n");
+               medalWorker((void*)data);
+               return;
+       }
+}
+
+void addPlayerScore(int score)
+{
+       if (game.score < 100000 && game.score + score >= 100000)
+       {
+               presentPlayerMedal("Score_100000");
+       }
+       else if (game.score < 250000 && game.score + score >= 250000)
+       {
+               presentPlayerMedal("Score_250000");
+       }
+       else if (game.score < 500000 && game.score + score >= 500000)
+       {
+               presentPlayerMedal("Score_500000");
+       }
+       
+       game.score += score;
+}
+
 void resetPlayer()
 {
        game.getCheckPoint(&player.x, &player.y);
@@ -352,7 +429,7 @@ void doPlayer()
                }
        }
        
-       #if !USEPAK
+       #if DEBUG
        if (engine.keyState[SDLK_1])
                player.currentWeapon = &weapon[WP_PISTOL];
        else if (engine.keyState[SDLK_2])