summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--gamestate.cpp104
-rw-r--r--hslist.cpp144
-rw-r--r--hslist.h16
-rw-r--r--mazeoflife.cpp10
-rw-r--r--titlestate.cpp12
-rw-r--r--util.cpp8
6 files changed, 147 insertions, 147 deletions
diff --git a/gamestate.cpp b/gamestate.cpp index 3ff08c4..18e41c2 100644 --- a/gamestate.cpp +++ b/gamestate.cpp
@@ -22,12 +22,12 @@ class GameBoard {
22 void render(SDL_Renderer* renderer, int level) const; 22 void render(SDL_Renderer* renderer, int level) const;
23 bool isObstructed(int x, int y) const; 23 bool isObstructed(int x, int y) const;
24 bool operator<(const GameBoard& other) const; 24 bool operator<(const GameBoard& other) const;
25 25
26 private: 26 private:
27 void initialize(int level); 27 void initialize(int level);
28 int solve(int playerx, int playery) const; 28 int solve(int playerx, int playery) const;
29 std::string dump() const; 29 std::string dump() const;
30 30
31 std::bitset<WIDTH*HEIGHT> blocks; 31 std::bitset<WIDTH*HEIGHT> blocks;
32 std::bitset<WIDTH*HEIGHT> updateable; 32 std::bitset<WIDTH*HEIGHT> updateable;
33 int oldx; 33 int oldx;
@@ -38,7 +38,7 @@ class LoadGameState : public State {
38 public: 38 public:
39 LoadGameState(int level); 39 LoadGameState(int level);
40 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 40 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
41 41
42 private: 42 private:
43 int level; 43 int level;
44}; 44};
@@ -47,7 +47,7 @@ class PlayGameState : public State {
47 public: 47 public:
48 PlayGameState(int level, GameBoard* board, int playerx, int playery); 48 PlayGameState(int level, GameBoard* board, int playerx, int playery);
49 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 49 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
50 50
51 private: 51 private:
52 bool move(int x, int y); 52 bool move(int x, int y);
53 int level; 53 int level;
@@ -111,7 +111,7 @@ State* LoadGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
111 char* wintitle = new char[50]; 111 char* wintitle = new char[50];
112 sprintf(wintitle, "Maze Of Life - Level %d", level); 112 sprintf(wintitle, "Maze Of Life - Level %d", level);
113 SDL_SetWindowTitle(window, wintitle); 113 SDL_SetWindowTitle(window, wintitle);
114 114
115 // Randomly place the player in a corner 115 // Randomly place the player in a corner
116 int playerx, playery; 116 int playerx, playery;
117 switch (rand()%4) 117 switch (rand()%4)
@@ -121,11 +121,11 @@ State* LoadGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
121 case 2: playerx = WIDTH-2; playery = HEIGHT-2; break; 121 case 2: playerx = WIDTH-2; playery = HEIGHT-2; break;
122 case 3: playerx = WIDTH-2; playery = 1; break; 122 case 3: playerx = WIDTH-2; playery = 1; break;
123 } 123 }
124 124
125 // Display the level number 125 // Display the level number
126 setRendererDeadColor(renderer, level); 126 setRendererDeadColor(renderer, level);
127 SDL_RenderClear(renderer); 127 SDL_RenderClear(renderer);
128 128
129 TTF_Font* font = loadFont(100); 129 TTF_Font* font = loadFont(100);
130 SDL_Color fontColor = {0, 0, 0, 0}; 130 SDL_Color fontColor = {0, 0, 0, 0};
131 char levelnum[8]; 131 char levelnum[8];
@@ -133,21 +133,21 @@ State* LoadGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
133 SDL_Surface* dispsurf = TTF_RenderText_Solid(font, levelnum, fontColor); 133 SDL_Surface* dispsurf = TTF_RenderText_Solid(font, levelnum, fontColor);
134 SDL_Texture* disptext = SDL_CreateTextureFromSurface(renderer, dispsurf); 134 SDL_Texture* disptext = SDL_CreateTextureFromSurface(renderer, dispsurf);
135 SDL_FreeSurface(dispsurf); 135 SDL_FreeSurface(dispsurf);
136 136
137 SDL_Rect pos; 137 SDL_Rect pos;
138 SDL_QueryTexture(disptext, NULL, NULL, &pos.w, &pos.h); 138 SDL_QueryTexture(disptext, NULL, NULL, &pos.w, &pos.h);
139 pos.x = 240-(pos.w/2); 139 pos.x = 240-(pos.w/2);
140 pos.y = 240-(pos.h/2); 140 pos.y = 240-(pos.h/2);
141 141
142 SDL_RenderCopy(renderer, disptext, NULL, &pos); 142 SDL_RenderCopy(renderer, disptext, NULL, &pos);
143 SDL_RenderPresent(renderer); 143 SDL_RenderPresent(renderer);
144 144
145 // Do 50 gens of Conway 145 // Do 50 gens of Conway
146 GameBoard* board = new GameBoard(level, playerx, playery); 146 GameBoard* board = new GameBoard(level, playerx, playery);
147 147
148 // Wait a bit 148 // Wait a bit
149 SDL_Delay(500); 149 SDL_Delay(500);
150 150
151 // Start the level 151 // Start the level
152 return new PlayGameState(level, board, playerx, playery); 152 return new PlayGameState(level, board, playerx, playery);
153} 153}
@@ -163,15 +163,15 @@ PlayGameState::PlayGameState(int m_level, GameBoard* m_board, int m_playerx, int
163State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer) 163State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
164{ 164{
165 SDL_Event e; 165 SDL_Event e;
166 166
167 for (;;) 167 for (;;)
168 { 168 {
169 // Tick board 169 // Tick board
170 board->tick(playerx, playery); 170 board->tick(playerx, playery);
171 171
172 // Paint board 172 // Paint board
173 board->render(renderer, level); 173 board->render(renderer, level);
174 174
175 // Paint event 175 // Paint event
176 SDL_Rect block; 176 SDL_Rect block;
177 block.w = 16; 177 block.w = 16;
@@ -180,15 +180,15 @@ State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
180 block.y = 15*16; 180 block.y = 15*16;
181 SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255); 181 SDL_SetRenderDrawColor(renderer, 0, 0, 255, 255);
182 SDL_RenderFillRect(renderer, &block); 182 SDL_RenderFillRect(renderer, &block);
183 183
184 // Paint player 184 // Paint player
185 block.x = playerx*16; 185 block.x = playerx*16;
186 block.y = playery*16; 186 block.y = playery*16;
187 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); 187 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
188 SDL_RenderFillRect(renderer, &block); 188 SDL_RenderFillRect(renderer, &block);
189 189
190 SDL_RenderPresent(renderer); 190 SDL_RenderPresent(renderer);
191 191
192 while (SDL_PollEvent(&e)) 192 while (SDL_PollEvent(&e))
193 { 193 {
194 if (e.type == SDL_QUIT) 194 if (e.type == SDL_QUIT)
@@ -205,7 +205,7 @@ State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
205 } else { 205 } else {
206 break; 206 break;
207 } 207 }
208 208
209 case SDLK_RIGHT: 209 case SDLK_RIGHT:
210 if (move(playerx+1, playery)) 210 if (move(playerx+1, playery))
211 { 211 {
@@ -213,7 +213,7 @@ State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
213 } else { 213 } else {
214 break; 214 break;
215 } 215 }
216 216
217 case SDLK_UP: 217 case SDLK_UP:
218 if (move(playerx, playery-1)) 218 if (move(playerx, playery-1))
219 { 219 {
@@ -221,7 +221,7 @@ State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
221 } else { 221 } else {
222 break; 222 break;
223 } 223 }
224 224
225 case SDLK_DOWN: 225 case SDLK_DOWN:
226 if (move(playerx, playery+1)) 226 if (move(playerx, playery+1))
227 { 227 {
@@ -229,10 +229,10 @@ State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
229 } else { 229 } else {
230 break; 230 break;
231 } 231 }
232 232
233 case SDLK_ESCAPE: 233 case SDLK_ESCAPE:
234 SDL_SetWindowTitle(window, ""); 234 SDL_SetWindowTitle(window, "");
235 235
236 std::ifstream exists(getDataFile()); 236 std::ifstream exists(getDataFile());
237 if (exists) 237 if (exists)
238 { 238 {
@@ -278,7 +278,7 @@ State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
278 } 278 }
279 } 279 }
280 } 280 }
281 281
282 SDL_Delay(5); 282 SDL_Delay(5);
283 } 283 }
284} 284}
@@ -286,7 +286,7 @@ State* PlayGameState::operator() (SDL_Window* window, SDL_Renderer* renderer)
286bool PlayGameState::move(int x, int y) 286bool PlayGameState::move(int x, int y)
287{ 287{
288 wrap(&x, &y); 288 wrap(&x, &y);
289 289
290 // Are we at the event? 290 // Are we at the event?
291 if ((x==15)&&(y==15)) 291 if ((x==15)&&(y==15))
292 { 292 {
@@ -299,7 +299,7 @@ bool PlayGameState::move(int x, int y)
299 playerx = x; 299 playerx = x;
300 playery = y; 300 playery = y;
301 } 301 }
302 302
303 return false; 303 return false;
304} 304}
305 305
@@ -311,12 +311,12 @@ GameBoard::GameBoard(int level, int playerx, int playery)
311 updateable.set(); 311 updateable.set();
312 oldx = playerx; 312 oldx = playerx;
313 oldy = playery; 313 oldy = playery;
314 314
315 for (int i=0; i<50; i++) 315 for (int i=0; i<50; i++)
316 { 316 {
317 tick(playerx, playery); 317 tick(playerx, playery);
318 } 318 }
319 319
320 int states = solve(playerx, playery); 320 int states = solve(playerx, playery);
321 if (states != 0) 321 if (states != 0)
322 { 322 {
@@ -341,7 +341,7 @@ void GameBoard::tick(int playerx, int playery)
341 int tdy = oldy+dy; 341 int tdy = oldy+dy;
342 wrap(&tdx, &tdy); 342 wrap(&tdx, &tdy);
343 tempdateable.set(tdx+tdy*WIDTH); 343 tempdateable.set(tdx+tdy*WIDTH);
344 344
345 tdx = playerx+dx; 345 tdx = playerx+dx;
346 tdy = playery+dy; 346 tdy = playery+dy;
347 wrap(&tdx, &tdy); 347 wrap(&tdx, &tdy);
@@ -349,10 +349,10 @@ void GameBoard::tick(int playerx, int playery)
349 } 349 }
350 } 350 }
351 } 351 }
352 352
353 oldx = playerx; 353 oldx = playerx;
354 oldy = playery; 354 oldy = playery;
355 355
356 updateable.reset(); 356 updateable.reset();
357 357
358 for (int y=0;y<HEIGHT;y++) 358 for (int y=0;y<HEIGHT;y++)
@@ -381,7 +381,7 @@ void GameBoard::tick(int playerx, int playery)
381 } else { 381 } else {
382 blocks[x+y*WIDTH] = (neighbors == 3); 382 blocks[x+y*WIDTH] = (neighbors == 3);
383 } 383 }
384 384
385 if (temp[x+y*WIDTH] != blocks[x+y*WIDTH]) 385 if (temp[x+y*WIDTH] != blocks[x+y*WIDTH])
386 { 386 {
387 for (int dy = -1; dy <= 1; dy++) 387 for (int dy = -1; dy <= 1; dy++)
@@ -404,21 +404,21 @@ void GameBoard::render(SDL_Renderer* renderer, int level) const
404 SDL_Rect block; 404 SDL_Rect block;
405 block.w = 16; 405 block.w = 16;
406 block.h = 16; 406 block.h = 16;
407 407
408 for (int y=0; y<HEIGHT; y++) 408 for (int y=0; y<HEIGHT; y++)
409 { 409 {
410 for (int x=0; x<WIDTH; x++) 410 for (int x=0; x<WIDTH; x++)
411 { 411 {
412 block.x = x*16; 412 block.x = x*16;
413 block.y = y*16; 413 block.y = y*16;
414 414
415 if (blocks[x+y*WIDTH]) 415 if (blocks[x+y*WIDTH])
416 { 416 {
417 setRendererAliveColor(renderer, level); 417 setRendererAliveColor(renderer, level);
418 } else { 418 } else {
419 setRendererDeadColor(renderer, level); 419 setRendererDeadColor(renderer, level);
420 } 420 }
421 421
422 SDL_RenderFillRect(renderer, &block); 422 SDL_RenderFillRect(renderer, &block);
423 } 423 }
424 } 424 }
@@ -436,7 +436,7 @@ void GameBoard::initialize(int level)
436 for (int x=0; x<WIDTH; x++) 436 for (int x=0; x<WIDTH; x++)
437 { 437 {
438 blocks[x+y*WIDTH] = false; 438 blocks[x+y*WIDTH] = false;
439 439
440 switch (level/10+1) 440 switch (level/10+1)
441 { 441 {
442 case 1: 442 case 1:
@@ -464,7 +464,7 @@ void GameBoard::initialize(int level)
464 } 464 }
465 } 465 }
466 } 466 }
467 467
468 blocks[15+15*WIDTH] = false; 468 blocks[15+15*WIDTH] = false;
469} 469}
470 470
@@ -477,7 +477,7 @@ bool GameBoard::operator<(const GameBoard& other) const
477 return other.blocks[i]; 477 return other.blocks[i];
478 } 478 }
479 } 479 }
480 480
481 return false; 481 return false;
482} 482}
483 483
@@ -486,32 +486,32 @@ int GameBoard::solve(int playerx, int playery) const
486 std::deque<std::tuple<int, int, GameBoard, int>> search; 486 std::deque<std::tuple<int, int, GameBoard, int>> search;
487 std::set<std::tuple<int, int, GameBoard>> done; 487 std::set<std::tuple<int, int, GameBoard>> done;
488 search.push_front(std::make_tuple(playerx, playery, *this, 0)); 488 search.push_front(std::make_tuple(playerx, playery, *this, 0));
489 489
490 bool exists = false; 490 bool exists = false;
491 while (!search.empty()) 491 while (!search.empty())
492 { 492 {
493 auto cur = search.front(); 493 auto cur = search.front();
494 search.pop_front(); 494 search.pop_front();
495 495
496 int cpx = std::get<0>(cur); 496 int cpx = std::get<0>(cur);
497 int cpy = std::get<1>(cur); 497 int cpy = std::get<1>(cur);
498 GameBoard& cbr = std::get<2>(cur); 498 GameBoard& cbr = std::get<2>(cur);
499 int cns = std::get<3>(cur); 499 int cns = std::get<3>(cur);
500 500
501 auto cdn = std::make_tuple(cpx, cpy, cbr); 501 auto cdn = std::make_tuple(cpx, cpy, cbr);
502 done.insert(cdn); 502 done.insert(cdn);
503 503
504 if (((cpx == 15) && ((cpy == 14) || (cpy == 16))) || ((cpy == 15) && ((cpx == 14) || (cpx == 16)))) 504 if (((cpx == 15) && ((cpy == 14) || (cpy == 16))) || ((cpy == 15) && ((cpx == 14) || (cpx == 16))))
505 { 505 {
506 exists = true; 506 exists = true;
507 break; 507 break;
508 } 508 }
509 509
510 if (cns >= 100) 510 if (cns >= 100)
511 { 511 {
512 continue; 512 continue;
513 } 513 }
514 514
515 GameBoard immnext {cbr}; 515 GameBoard immnext {cbr};
516 immnext.tick(cpx, cpy); 516 immnext.tick(cpx, cpy);
517 if (immnext.blocks != cbr.blocks) 517 if (immnext.blocks != cbr.blocks)
@@ -519,30 +519,30 @@ int GameBoard::solve(int playerx, int playery) const
519 if (done.count(std::make_tuple(cpx, cpy, immnext)) == 0) 519 if (done.count(std::make_tuple(cpx, cpy, immnext)) == 0)
520 { 520 {
521 search.push_front(std::make_tuple(cpx, cpy, immnext, cns)); 521 search.push_front(std::make_tuple(cpx, cpy, immnext, cns));
522 522
523 continue; 523 continue;
524 } 524 }
525 } 525 }
526 526
527 std::vector<std::pair<int, int>> dirchanges {{cpx-1,cpy}, {cpx,cpy-1}, {cpx+1,cpy}, {cpx,cpy+1}}; 527 std::vector<std::pair<int, int>> dirchanges {{cpx-1,cpy}, {cpx,cpy-1}, {cpx+1,cpy}, {cpx,cpy+1}};
528 std::sort(std::begin(dirchanges), std::end(dirchanges), [] (const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) { 528 std::sort(std::begin(dirchanges), std::end(dirchanges), [] (const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) {
529 int lhd = sqrt(pow(15 - lhs.first, 2.0) + pow(15 - lhs.second, 2.0)); 529 int lhd = sqrt(pow(15 - lhs.first, 2.0) + pow(15 - lhs.second, 2.0));
530 int rhd = sqrt(pow(15 - rhs.first, 2.0) + pow(15 - rhs.second, 2.0)); 530 int rhd = sqrt(pow(15 - rhs.first, 2.0) + pow(15 - rhs.second, 2.0));
531 531
532 return lhd > rhd; 532 return lhd > rhd;
533 }); 533 });
534 534
535 for (auto& dirchange : dirchanges) 535 for (auto& dirchange : dirchanges)
536 { 536 {
537 GameBoard next {cbr}; 537 GameBoard next {cbr};
538 int npx = cpx + dirchange.first; 538 int npx = cpx + dirchange.first;
539 int npy = cpy + dirchange.second; 539 int npy = cpy + dirchange.second;
540 wrap(&npx, &npy); 540 wrap(&npx, &npy);
541 541
542 if (!next.isObstructed(npx, npy)) 542 if (!next.isObstructed(npx, npy))
543 { 543 {
544 next.tick(npx, npy); 544 next.tick(npx, npy);
545 545
546 if (done.count(std::make_tuple(npx, npy, next)) == 0) 546 if (done.count(std::make_tuple(npx, npy, next)) == 0)
547 { 547 {
548 search.push_front(std::make_tuple(npx, npy, next, cns+1)); 548 search.push_front(std::make_tuple(npx, npy, next, cns+1));
@@ -550,7 +550,7 @@ int GameBoard::solve(int playerx, int playery) const
550 } 550 }
551 } 551 }
552 } 552 }
553 553
554 if (exists) 554 if (exists)
555 { 555 {
556 return done.size(); 556 return done.size();
@@ -568,6 +568,6 @@ std::string GameBoard::dump() const
568 int chunk = (8 * blocks[i*4]) + (4 * blocks[i*4+1]) + (2 * blocks[i*4+2]) + blocks[i*4+3]; 568 int chunk = (8 * blocks[i*4]) + (4 * blocks[i*4+1]) + (2 * blocks[i*4+2]) + blocks[i*4+3];
569 output << chunk; 569 output << chunk;
570 } 570 }
571 571
572 return output.str(); 572 return output.str();
573} 573}
diff --git a/hslist.cpp b/hslist.cpp index ed7f3ca..f71d8be 100644 --- a/hslist.cpp +++ b/hslist.cpp
@@ -40,7 +40,7 @@ SDL_Surface* HighscoreList::render()
40 for (hslist_t::iterator it = hslist.begin(); it != hslist.end(); ++it, ++i) 40 for (hslist_t::iterator it = hslist.begin(); it != hslist.end(); ++it, ++i)
41 { 41 {
42 Highscore* h = *it; 42 Highscore* h = *it;
43 43
44 int posw, posh; 44 int posw, posh;
45 char pos[4]; // 2 max characters in rank plus the colon at the end, plus terminator 45 char pos[4]; // 2 max characters in rank plus the colon at the end, plus terminator
46 sprintf(pos, "%d:", h->getRank()); 46 sprintf(pos, "%d:", h->getRank());
@@ -196,12 +196,12 @@ int LocalHighscoreList::addHighscore(Highscore* h)
196 hslist.push_back(h); 196 hslist.push_back(h);
197 std::sort(hslist.begin(), hslist.end(), hslist_comp_i); 197 std::sort(hslist.begin(), hslist.end(), hslist_comp_i);
198 resetRanks(hslist); 198 resetRanks(hslist);
199 199
200 if (hslist.size() > 10) 200 if (hslist.size() > 10)
201 { 201 {
202 hslist.resize(10); 202 hslist.resize(10);
203 } 203 }
204 204
205 return h->getRank(); 205 return h->getRank();
206} 206}
207 207
@@ -236,7 +236,7 @@ GlobalHighscoreList::GlobalHighscoreList()
236GlobalHighscoreList::GlobalHighscoreList(Highscore* h) 236GlobalHighscoreList::GlobalHighscoreList(Highscore* h)
237{ 237{
238 fail = false; 238 fail = false;
239 239
240 try 240 try
241 { 241 {
242 IPaddress ipaddress; 242 IPaddress ipaddress;
@@ -302,7 +302,7 @@ GlobalHighscoreList::GlobalHighscoreList(Highscore* h)
302 this->hslist.push_back(h); 302 this->hslist.push_back(h);
303 std::sort(this->hslist.begin(), this->hslist.end(), hslist_comp_i); 303 std::sort(this->hslist.begin(), this->hslist.end(), hslist_comp_i);
304 resetRanks(this->hslist); 304 resetRanks(this->hslist);
305 305
306 if (this->hslist.size() > 10) 306 if (this->hslist.size() > 10)
307 { 307 {
308 this->hslist.resize(10); 308 this->hslist.resize(10);
@@ -345,14 +345,14 @@ State* ChooseHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* r
345 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 345 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
346 int selection = 0; 346 int selection = 0;
347 SDL_Event e; 347 SDL_Event e;
348 348
349 for (;;) 349 for (;;)
350 { 350 {
351 SDL_RenderClear(renderer); 351 SDL_RenderClear(renderer);
352 SDL_RenderCopy(renderer, background, NULL, NULL); 352 SDL_RenderCopy(renderer, background, NULL, NULL);
353 applyTexture(renderer, pointer, 127, selection==0?306:(selection==1?336:396)); 353 applyTexture(renderer, pointer, 127, selection==0?306:(selection==1?336:396));
354 SDL_RenderPresent(renderer); 354 SDL_RenderPresent(renderer);
355 355
356 while (SDL_PollEvent(&e)) 356 while (SDL_PollEvent(&e))
357 { 357 {
358 if (e.type == SDL_QUIT) 358 if (e.type == SDL_QUIT)
@@ -383,7 +383,7 @@ State* ChooseHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* r
383State* DisplayLocalHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* renderer) 383State* DisplayLocalHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* renderer)
384{ 384{
385 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 385 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
386 386
387 LocalHighscoreList* lhl = new LocalHighscoreList(); 387 LocalHighscoreList* lhl = new LocalHighscoreList();
388 SDL_Surface* list_s = lhl->render(); 388 SDL_Surface* list_s = lhl->render();
389 SDL_Color fontColor = {0, 0, 0, 0}; 389 SDL_Color fontColor = {0, 0, 0, 0};
@@ -396,12 +396,12 @@ State* DisplayLocalHighscoreListState::operator() (SDL_Window* window, SDL_Rende
396 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h}; 396 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h};
397 SDL_BlitSurface(options_s, NULL, list_s, &oSpace); 397 SDL_BlitSurface(options_s, NULL, list_s, &oSpace);
398 SDL_FreeSurface(options_s); 398 SDL_FreeSurface(options_s);
399 399
400 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s); 400 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s);
401 SDL_FreeSurface(list_s); 401 SDL_FreeSurface(list_s);
402 402
403 SDL_Event e; 403 SDL_Event e;
404 404
405 for (;;) 405 for (;;)
406 { 406 {
407 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 407 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
@@ -409,7 +409,7 @@ State* DisplayLocalHighscoreListState::operator() (SDL_Window* window, SDL_Rende
409 SDL_RenderCopy(renderer, list, NULL, NULL); 409 SDL_RenderCopy(renderer, list, NULL, NULL);
410 applyTexture(renderer, pointer, 137, 449); 410 applyTexture(renderer, pointer, 137, 449);
411 SDL_RenderPresent(renderer); 411 SDL_RenderPresent(renderer);
412 412
413 while (SDL_PollEvent(&e)) 413 while (SDL_PollEvent(&e))
414 { 414 {
415 if (e.type == SDL_QUIT) 415 if (e.type == SDL_QUIT)
@@ -429,7 +429,7 @@ State* DisplayLocalHighscoreListState::operator() (SDL_Window* window, SDL_Rende
429State* DisplayAndReturnLocalHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* renderer) 429State* DisplayAndReturnLocalHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* renderer)
430{ 430{
431 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 431 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
432 432
433 LocalHighscoreList* lhl = new LocalHighscoreList(); 433 LocalHighscoreList* lhl = new LocalHighscoreList();
434 SDL_Surface* list_s = lhl->render(); 434 SDL_Surface* list_s = lhl->render();
435 SDL_Color fontColor = {0, 0, 0, 0}; 435 SDL_Color fontColor = {0, 0, 0, 0};
@@ -442,13 +442,13 @@ State* DisplayAndReturnLocalHighscoreListState::operator() (SDL_Window* window,
442 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h}; 442 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h};
443 SDL_BlitSurface(options_s, NULL, list_s, &oSpace); 443 SDL_BlitSurface(options_s, NULL, list_s, &oSpace);
444 SDL_FreeSurface(options_s); 444 SDL_FreeSurface(options_s);
445 445
446 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s); 446 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s);
447 SDL_FreeSurface(list_s); 447 SDL_FreeSurface(list_s);
448 448
449 int selection = 0; 449 int selection = 0;
450 SDL_Event e; 450 SDL_Event e;
451 451
452 for (;;) 452 for (;;)
453 { 453 {
454 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 454 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
@@ -456,7 +456,7 @@ State* DisplayAndReturnLocalHighscoreListState::operator() (SDL_Window* window,
456 SDL_RenderCopy(renderer, list, NULL, NULL); 456 SDL_RenderCopy(renderer, list, NULL, NULL);
457 applyTexture(renderer, pointer, selection==0?52:225, 447); 457 applyTexture(renderer, pointer, selection==0?52:225, 447);
458 SDL_RenderPresent(renderer); 458 SDL_RenderPresent(renderer);
459 459
460 while (SDL_PollEvent(&e)) 460 while (SDL_PollEvent(&e))
461 { 461 {
462 if (e.type == SDL_QUIT) 462 if (e.type == SDL_QUIT)
@@ -486,11 +486,11 @@ State* DisplayAndReturnLocalHighscoreListState::operator() (SDL_Window* window,
486State* DisplayGlobalHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* renderer) 486State* DisplayGlobalHighscoreListState::operator() (SDL_Window* window, SDL_Renderer* renderer)
487{ 487{
488 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 488 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
489 489
490 // Display loading message 490 // Display loading message
491 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 491 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
492 SDL_RenderClear(renderer); 492 SDL_RenderClear(renderer);
493 493
494 SDL_Surface* list_s = SDL_CreateRGBSurface(0, 480, 480, 32, 0,0,0,0); 494 SDL_Surface* list_s = SDL_CreateRGBSurface(0, 480, 480, 32, 0,0,0,0);
495 Uint32 bgColor = SDL_MapRGB(list_s->format, 255, 255, 255); 495 Uint32 bgColor = SDL_MapRGB(list_s->format, 255, 255, 255);
496 SDL_FillRect(list_s, NULL, bgColor); 496 SDL_FillRect(list_s, NULL, bgColor);
@@ -511,18 +511,18 @@ State* DisplayGlobalHighscoreListState::operator() (SDL_Window* window, SDL_Rend
511 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h}; 511 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h};
512 SDL_BlitSurface(options_s, NULL, list_s, &oSpace); 512 SDL_BlitSurface(options_s, NULL, list_s, &oSpace);
513 SDL_FreeSurface(options_s); 513 SDL_FreeSurface(options_s);
514 514
515 list = SDL_CreateTextureFromSurface(renderer, list_s); 515 list = SDL_CreateTextureFromSurface(renderer, list_s);
516 SDL_FreeSurface(list_s); 516 SDL_FreeSurface(list_s);
517 517
518 m = SDL_CreateMutex(); 518 m = SDL_CreateMutex();
519 519
520 // Start downloading scores 520 // Start downloading scores
521 SDL_CreateThread(&LoadHighscoreList, "LoadHighscoreList", this); 521 SDL_CreateThread(&LoadHighscoreList, "LoadHighscoreList", this);
522 522
523 // Parse keyboard events 523 // Parse keyboard events
524 SDL_Event e; 524 SDL_Event e;
525 525
526 for (;;) 526 for (;;)
527 { 527 {
528 if (SDL_LockMutex(m) == 0) 528 if (SDL_LockMutex(m) == 0)
@@ -541,35 +541,35 @@ State* DisplayGlobalHighscoreListState::operator() (SDL_Window* window, SDL_Rend
541 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h}; 541 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h};
542 SDL_BlitSurface(options_s, NULL, list_s, &oSpace); 542 SDL_BlitSurface(options_s, NULL, list_s, &oSpace);
543 SDL_FreeSurface(options_s); 543 SDL_FreeSurface(options_s);
544 544
545 list = SDL_CreateTextureFromSurface(renderer, list_s); 545 list = SDL_CreateTextureFromSurface(renderer, list_s);
546 SDL_FreeSurface(list_s); 546 SDL_FreeSurface(list_s);
547 547
548 lhl = NULL; 548 lhl = NULL;
549 } 549 }
550 550
551 SDL_UnlockMutex(m); 551 SDL_UnlockMutex(m);
552 } 552 }
553 553
554 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 554 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
555 SDL_RenderClear(renderer); 555 SDL_RenderClear(renderer);
556 SDL_RenderCopy(renderer, list, NULL, NULL); 556 SDL_RenderCopy(renderer, list, NULL, NULL);
557 applyTexture(renderer, pointer, 137, 449); 557 applyTexture(renderer, pointer, 137, 449);
558 SDL_RenderPresent(renderer); 558 SDL_RenderPresent(renderer);
559 559
560 while (SDL_PollEvent(&e)) 560 while (SDL_PollEvent(&e))
561 { 561 {
562 if (e.type == SDL_QUIT) 562 if (e.type == SDL_QUIT)
563 { 563 {
564 SDL_DestroyMutex(m); 564 SDL_DestroyMutex(m);
565 565
566 return NULL; 566 return NULL;
567 } else if (e.type == SDL_KEYDOWN) 567 } else if (e.type == SDL_KEYDOWN)
568 { 568 {
569 if (e.key.keysym.sym == SDLK_RETURN) 569 if (e.key.keysym.sym == SDLK_RETURN)
570 { 570 {
571 SDL_DestroyMutex(m); 571 SDL_DestroyMutex(m);
572 572
573 return new ChooseHighscoreListState(); 573 return new ChooseHighscoreListState();
574 } 574 }
575 } 575 }
@@ -583,7 +583,7 @@ int DisplayGlobalHighscoreListState::LoadHighscoreList(void* pParam)
583 if (SDL_LockMutex(parent->m) == 0) 583 if (SDL_LockMutex(parent->m) == 0)
584 { 584 {
585 parent->lhl = new GlobalHighscoreList(); 585 parent->lhl = new GlobalHighscoreList();
586 586
587 SDL_UnlockMutex(parent->m); 587 SDL_UnlockMutex(parent->m);
588 } else { 588 } else {
589 printf("Couldn't lock mutex: %s\n", SDL_GetError()); 589 printf("Couldn't lock mutex: %s\n", SDL_GetError());
@@ -598,16 +598,16 @@ EnterHighscoreState::EnterHighscoreState(int level)
598State* EnterHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer) 598State* EnterHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer)
599{ 599{
600 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 600 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
601 601
602 // Render highscore list 602 // Render highscore list
603 LocalHighscoreList* lhl = new LocalHighscoreList(); 603 LocalHighscoreList* lhl = new LocalHighscoreList();
604 char* emp = new char[1]; 604 char* emp = new char[1];
605 emp[0] = 0; 605 emp[0] = 0;
606 Highscore* h = new Highscore(emp, level); 606 Highscore* h = new Highscore(emp, level);
607 int newpos = lhl->addHighscore(h); 607 int newpos = lhl->addHighscore(h);
608 608
609 SDL_Surface* list_s = lhl->render(); 609 SDL_Surface* list_s = lhl->render();
610 610
611 SDL_Color fontColor = {0, 0, 0, 0}; 611 SDL_Color fontColor = {0, 0, 0, 0};
612 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor); 612 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor);
613 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; 613 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h};
@@ -621,13 +621,13 @@ State* EnterHighscoreState::operator() (SDL_Window* window, SDL_Renderer* render
621 SDL_Rect oSpace = {240-(text->w/2), 440, text->w, text->h}; 621 SDL_Rect oSpace = {240-(text->w/2), 440, text->w, text->h};
622 SDL_BlitSurface(text, NULL, list_s, &oSpace); 622 SDL_BlitSurface(text, NULL, list_s, &oSpace);
623 SDL_FreeSurface(text); 623 SDL_FreeSurface(text);
624 624
625 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s); 625 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s);
626 SDL_FreeSurface(list_s); 626 SDL_FreeSurface(list_s);
627 627
628 int selection = 0; 628 int selection = 0;
629 SDL_Event e; 629 SDL_Event e;
630 630
631 int posw, posh; 631 int posw, posh;
632 char pos[3]; // 2 max characters in rank plus the colon at the end 632 char pos[3]; // 2 max characters in rank plus the colon at the end
633 sprintf(pos, "%d:", newpos); 633 sprintf(pos, "%d:", newpos);
@@ -642,7 +642,7 @@ State* EnterHighscoreState::operator() (SDL_Window* window, SDL_Renderer* render
642 rntSpace.h = newName_s->h; 642 rntSpace.h = newName_s->h;
643 newName = SDL_CreateTextureFromSurface(renderer, newName_s); 643 newName = SDL_CreateTextureFromSurface(renderer, newName_s);
644 SDL_FreeSurface(newName_s); 644 SDL_FreeSurface(newName_s);
645 645
646 for (;;) 646 for (;;)
647 { 647 {
648 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 648 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
@@ -651,12 +651,12 @@ State* EnterHighscoreState::operator() (SDL_Window* window, SDL_Renderer* render
651 SDL_Rect eSpace = {0, newpos*40, 480, 40}; 651 SDL_Rect eSpace = {0, newpos*40, 480, 40};
652 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); 652 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
653 SDL_RenderFillRect(renderer, &eSpace); 653 SDL_RenderFillRect(renderer, &eSpace);
654 654
655 SDL_RenderCopy(renderer, list, NULL, NULL); 655 SDL_RenderCopy(renderer, list, NULL, NULL);
656 SDL_RenderCopy(renderer, newName, NULL, &rntSpace); 656 SDL_RenderCopy(renderer, newName, NULL, &rntSpace);
657 657
658 SDL_RenderPresent(renderer); 658 SDL_RenderPresent(renderer);
659 659
660 while (SDL_PollEvent(&e)) 660 while (SDL_PollEvent(&e))
661 { 661 {
662 if (e.type == SDL_QUIT) 662 if (e.type == SDL_QUIT)
@@ -682,7 +682,7 @@ State* EnterHighscoreState::operator() (SDL_Window* window, SDL_Renderer* render
682 Highscore* h2 = new Highscore(hsname, level); 682 Highscore* h2 = new Highscore(hsname, level);
683 lhl->addHighscore(h2); 683 lhl->addHighscore(h2);
684 lhl->writeHighscores(); 684 lhl->writeHighscores();
685 685
686 return new NewHighscoreState(h2); 686 return new NewHighscoreState(h2);
687 } 687 }
688 } else if (e.type == SDL_TEXTINPUT) 688 } else if (e.type == SDL_TEXTINPUT)
@@ -714,17 +714,17 @@ NewHighscoreState::NewHighscoreState(Highscore* h)
714State* NewHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer) 714State* NewHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer)
715{ 715{
716 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 716 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
717 717
718 // Render highscore list 718 // Render highscore list
719 LocalHighscoreList* lhl = new LocalHighscoreList(); 719 LocalHighscoreList* lhl = new LocalHighscoreList();
720 SDL_Surface* list_s = lhl->render(); 720 SDL_Surface* list_s = lhl->render();
721 721
722 SDL_Color fontColor = {0, 0, 0, 0}; 722 SDL_Color fontColor = {0, 0, 0, 0};
723 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor); 723 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "New Highscore!", fontColor);
724 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; 724 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h};
725 SDL_BlitSurface(title, NULL, list_s, &tSpace); 725 SDL_BlitSurface(title, NULL, list_s, &tSpace);
726 SDL_FreeSurface(title); 726 SDL_FreeSurface(title);
727 727
728 SDL_Surface* options_s = SDL_LoadBMP("resources/hlo_passartm.bmp"); 728 SDL_Surface* options_s = SDL_LoadBMP("resources/hlo_passartm.bmp");
729 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h}; 729 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h};
730 SDL_BlitSurface(options_s, NULL, list_s, &oSpace); 730 SDL_BlitSurface(options_s, NULL, list_s, &oSpace);
@@ -732,10 +732,10 @@ State* NewHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer
732 732
733 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s); 733 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s);
734 SDL_FreeSurface(list_s); 734 SDL_FreeSurface(list_s);
735 735
736 int selection = 0; 736 int selection = 0;
737 SDL_Event e; 737 SDL_Event e;
738 738
739 for (;;) 739 for (;;)
740 { 740 {
741 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 741 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
@@ -744,11 +744,11 @@ State* NewHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer
744 SDL_Rect eSpace = {0, h->getRank()*40, 480, 40}; 744 SDL_Rect eSpace = {0, h->getRank()*40, 480, 40};
745 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); 745 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
746 SDL_RenderFillRect(renderer, &eSpace); 746 SDL_RenderFillRect(renderer, &eSpace);
747 747
748 SDL_RenderCopy(renderer, list, NULL, NULL); 748 SDL_RenderCopy(renderer, list, NULL, NULL);
749 applyTexture(renderer, pointer, selection==0?13:(selection==1?138:284), 448); 749 applyTexture(renderer, pointer, selection==0?13:(selection==1?138:284), 448);
750 SDL_RenderPresent(renderer); 750 SDL_RenderPresent(renderer);
751 751
752 while (SDL_PollEvent(&e)) 752 while (SDL_PollEvent(&e))
753 { 753 {
754 if (e.type == SDL_QUIT) 754 if (e.type == SDL_QUIT)
@@ -798,30 +798,30 @@ State* SubmitHighscoreState::operator() (SDL_Window* window, SDL_Renderer* rende
798 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; 798 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h};
799 SDL_BlitSurface(title, NULL, list_s, &tSpace); 799 SDL_BlitSurface(title, NULL, list_s, &tSpace);
800 SDL_FreeSurface(title); 800 SDL_FreeSurface(title);
801 801
802 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s); 802 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s);
803 SDL_FreeSurface(list_s); 803 SDL_FreeSurface(list_s);
804 804
805 // Start submitting score 805 // Start submitting score
806 m = SDL_CreateMutex(); 806 m = SDL_CreateMutex();
807 SDL_CreateThread(&SubmitHighscore, "SubmitHighscore", this); 807 SDL_CreateThread(&SubmitHighscore, "SubmitHighscore", this);
808 808
809 SDL_Event e; 809 SDL_Event e;
810 810
811 for (;;) 811 for (;;)
812 { 812 {
813 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 813 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
814 SDL_RenderClear(renderer); 814 SDL_RenderClear(renderer);
815 SDL_RenderCopy(renderer, list, NULL, NULL); 815 SDL_RenderCopy(renderer, list, NULL, NULL);
816 SDL_RenderPresent(renderer); 816 SDL_RenderPresent(renderer);
817 817
818 if (SDL_LockMutex(m) == 0) 818 if (SDL_LockMutex(m) == 0)
819 { 819 {
820 if (lhl != NULL) 820 if (lhl != NULL)
821 { 821 {
822 SDL_UnlockMutex(m); 822 SDL_UnlockMutex(m);
823 SDL_DestroyMutex(m); 823 SDL_DestroyMutex(m);
824 824
825 if (lhl->didFail()) 825 if (lhl->didFail())
826 { 826 {
827 return new FailedSubmittingHighscoreState(h); 827 return new FailedSubmittingHighscoreState(h);
@@ -832,13 +832,13 @@ State* SubmitHighscoreState::operator() (SDL_Window* window, SDL_Renderer* rende
832 SDL_UnlockMutex(m); 832 SDL_UnlockMutex(m);
833 } 833 }
834 } 834 }
835 835
836 while (SDL_PollEvent(&e)) 836 while (SDL_PollEvent(&e))
837 { 837 {
838 if (e.type == SDL_QUIT) 838 if (e.type == SDL_QUIT)
839 { 839 {
840 SDL_DestroyMutex(m); 840 SDL_DestroyMutex(m);
841 841
842 return NULL; 842 return NULL;
843 } 843 }
844 } 844 }
@@ -851,7 +851,7 @@ int SubmitHighscoreState::SubmitHighscore(void* pParam)
851 if (SDL_LockMutex(parent->m) == 0) 851 if (SDL_LockMutex(parent->m) == 0)
852 { 852 {
853 parent->lhl = new GlobalHighscoreList(parent->h); 853 parent->lhl = new GlobalHighscoreList(parent->h);
854 854
855 SDL_UnlockMutex(parent->m); 855 SDL_UnlockMutex(parent->m);
856 } else { 856 } else {
857 printf("Could not lock mutex: %s\n", SDL_GetError()); 857 printf("Could not lock mutex: %s\n", SDL_GetError());
@@ -875,7 +875,7 @@ State* FailedSubmittingHighscoreState::operator() (SDL_Window* window, SDL_Rende
875 SDL_Rect tSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h}; 875 SDL_Rect tSpace = {240-(text->w/2), 240-(text->h/2), text->w, text->h};
876 SDL_BlitSurface(text, NULL, list_s, &tSpace); 876 SDL_BlitSurface(text, NULL, list_s, &tSpace);
877 SDL_FreeSurface(text); 877 SDL_FreeSurface(text);
878 878
879 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); 879 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor);
880 SDL_Rect aSpace = {240-(title->w/2), 0, title->w, title->h}; 880 SDL_Rect aSpace = {240-(title->w/2), 0, title->w, title->h};
881 SDL_BlitSurface(title, NULL, list_s, &aSpace); 881 SDL_BlitSurface(title, NULL, list_s, &aSpace);
@@ -885,14 +885,14 @@ State* FailedSubmittingHighscoreState::operator() (SDL_Window* window, SDL_Rende
885 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h}; 885 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h};
886 SDL_BlitSurface(options_s, NULL, list_s, &oSpace); 886 SDL_BlitSurface(options_s, NULL, list_s, &oSpace);
887 SDL_FreeSurface(options_s); 887 SDL_FreeSurface(options_s);
888 888
889 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s); 889 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s);
890 SDL_FreeSurface(list_s); 890 SDL_FreeSurface(list_s);
891 891
892 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 892 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
893 int selection = 0; 893 int selection = 0;
894 SDL_Event e; 894 SDL_Event e;
895 895
896 for (;;) 896 for (;;)
897 { 897 {
898 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 898 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
@@ -900,7 +900,7 @@ State* FailedSubmittingHighscoreState::operator() (SDL_Window* window, SDL_Rende
900 SDL_RenderCopy(renderer, list, NULL, NULL); 900 SDL_RenderCopy(renderer, list, NULL, NULL);
901 applyTexture(renderer, pointer, selection==0?13:(selection==1?138:284), 448); 901 applyTexture(renderer, pointer, selection==0?13:(selection==1?138:284), 448);
902 SDL_RenderPresent(renderer); 902 SDL_RenderPresent(renderer);
903 903
904 while (SDL_PollEvent(&e)) 904 while (SDL_PollEvent(&e))
905 { 905 {
906 if (e.type == SDL_QUIT) 906 if (e.type == SDL_QUIT)
@@ -937,44 +937,44 @@ SubmittedHighscoreState::SubmittedHighscoreState(GlobalHighscoreList* lhl, Highs
937State* SubmittedHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer) 937State* SubmittedHighscoreState::operator() (SDL_Window* window, SDL_Renderer* renderer)
938{ 938{
939 SDL_Surface* list_s = lhl->render(); 939 SDL_Surface* list_s = lhl->render();
940 940
941 SDL_Color fontColor = {0, 0, 0, 0}; 941 SDL_Color fontColor = {0, 0, 0, 0};
942 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor); 942 SDL_Surface* title = TTF_RenderText_Blended(loadFont(40), "Highscore List", fontColor);
943 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h}; 943 SDL_Rect tSpace = {240-(title->w/2), 0, title->w, title->h};
944 SDL_BlitSurface(title, NULL, list_s, &tSpace); 944 SDL_BlitSurface(title, NULL, list_s, &tSpace);
945 SDL_FreeSurface(title); 945 SDL_FreeSurface(title);
946 946
947 SDL_Surface* options_s = SDL_LoadBMP("resources/hlo_paartm.bmp"); 947 SDL_Surface* options_s = SDL_LoadBMP("resources/hlo_paartm.bmp");
948 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h}; 948 SDL_Rect oSpace = {0, 440, options_s->w, options_s->h};
949 SDL_BlitSurface(options_s, NULL, list_s, &oSpace); 949 SDL_BlitSurface(options_s, NULL, list_s, &oSpace);
950 SDL_FreeSurface(options_s); 950 SDL_FreeSurface(options_s);
951 951
952 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s); 952 SDL_Texture* list = SDL_CreateTextureFromSurface(renderer, list_s);
953 SDL_FreeSurface(list_s); 953 SDL_FreeSurface(list_s);
954 954
955 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 955 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
956 int selection = 0; 956 int selection = 0;
957 SDL_Event e; 957 SDL_Event e;
958 958
959 int newpos = h->getRank(); 959 int newpos = h->getRank();
960 if (newpos > 10) 960 if (newpos > 10)
961 { 961 {
962 newpos = 10; 962 newpos = 10;
963 } 963 }
964 964
965 for (;;) 965 for (;;)
966 { 966 {
967 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); 967 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
968 SDL_RenderClear(renderer); 968 SDL_RenderClear(renderer);
969 969
970 SDL_Rect eSpace = {0, newpos*40, 480, 40}; 970 SDL_Rect eSpace = {0, newpos*40, 480, 40};
971 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255); 971 SDL_SetRenderDrawColor(renderer, 255, 255, 0, 255);
972 SDL_RenderFillRect(renderer, &eSpace); 972 SDL_RenderFillRect(renderer, &eSpace);
973 973
974 SDL_RenderCopy(renderer, list, NULL, NULL); 974 SDL_RenderCopy(renderer, list, NULL, NULL);
975 applyTexture(renderer, pointer, selection==0?52:225, 447); 975 applyTexture(renderer, pointer, selection==0?52:225, 447);
976 SDL_RenderPresent(renderer); 976 SDL_RenderPresent(renderer);
977 977
978 while (SDL_PollEvent(&e)) 978 while (SDL_PollEvent(&e))
979 { 979 {
980 if (e.type == SDL_QUIT) 980 if (e.type == SDL_QUIT)
diff --git a/hslist.h b/hslist.h index 844bf37..291a526 100644 --- a/hslist.h +++ b/hslist.h
@@ -61,13 +61,13 @@ class DisplayAndReturnLocalHighscoreListState : public State {
61class DisplayGlobalHighscoreListState : public State { 61class DisplayGlobalHighscoreListState : public State {
62 public: 62 public:
63 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 63 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
64 64
65 protected: 65 protected:
66 SDL_Surface* list_s; 66 SDL_Surface* list_s;
67 SDL_Texture* list; 67 SDL_Texture* list;
68 GlobalHighscoreList* lhl; 68 GlobalHighscoreList* lhl;
69 SDL_mutex* m; 69 SDL_mutex* m;
70 70
71 private: 71 private:
72 static int LoadHighscoreList(void* pParam); 72 static int LoadHighscoreList(void* pParam);
73}; 73};
@@ -76,7 +76,7 @@ class EnterHighscoreState : public State {
76 public: 76 public:
77 EnterHighscoreState(int level); 77 EnterHighscoreState(int level);
78 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 78 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
79 79
80 private: 80 private:
81 int level; 81 int level;
82 int lp; 82 int lp;
@@ -88,7 +88,7 @@ class NewHighscoreState : public State {
88 public: 88 public:
89 NewHighscoreState(Highscore* h); 89 NewHighscoreState(Highscore* h);
90 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 90 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
91 91
92 private: 92 private:
93 Highscore* h; 93 Highscore* h;
94}; 94};
@@ -97,12 +97,12 @@ class SubmitHighscoreState : public State {
97 public: 97 public:
98 SubmitHighscoreState(Highscore* h); 98 SubmitHighscoreState(Highscore* h);
99 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 99 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
100 100
101 protected: 101 protected:
102 Highscore* h; 102 Highscore* h;
103 SDL_mutex* m; 103 SDL_mutex* m;
104 GlobalHighscoreList* lhl; 104 GlobalHighscoreList* lhl;
105 105
106 private: 106 private:
107 static int SubmitHighscore(void* pParam); 107 static int SubmitHighscore(void* pParam);
108}; 108};
@@ -111,7 +111,7 @@ class FailedSubmittingHighscoreState : public State {
111 public: 111 public:
112 FailedSubmittingHighscoreState(Highscore* h); 112 FailedSubmittingHighscoreState(Highscore* h);
113 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 113 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
114 114
115 private: 115 private:
116 Highscore* h; 116 Highscore* h;
117}; 117};
@@ -120,7 +120,7 @@ class SubmittedHighscoreState : public State {
120 public: 120 public:
121 SubmittedHighscoreState(GlobalHighscoreList* lhl, Highscore* h); 121 SubmittedHighscoreState(GlobalHighscoreList* lhl, Highscore* h);
122 State* operator() (SDL_Window* window, SDL_Renderer* renderer); 122 State* operator() (SDL_Window* window, SDL_Renderer* renderer);
123 123
124 private: 124 private:
125 GlobalHighscoreList* lhl; 125 GlobalHighscoreList* lhl;
126 Highscore* h; 126 Highscore* h;
diff --git a/mazeoflife.cpp b/mazeoflife.cpp index da19908..cf21d2a 100644 --- a/mazeoflife.cpp +++ b/mazeoflife.cpp
@@ -13,7 +13,7 @@ int main(int argc, char *argv[])
13 srand(time(NULL)); 13 srand(time(NULL));
14 14
15 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) 15 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1)
16 { 16 {
17 printf("Could not initialize SDL: %s.\n", SDL_GetError()); 17 printf("Could not initialize SDL: %s.\n", SDL_GetError());
18 exit(-1); 18 exit(-1);
19 } 19 }
@@ -29,17 +29,17 @@ int main(int argc, char *argv[])
29 printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError()); 29 printf("Cound not initalize SDL_net: %s.\n", SDLNet_GetError());
30 exit(-1); 30 exit(-1);
31 } 31 }
32 32
33 SDL_Window* window = SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN); 33 SDL_Window* window = SDL_CreateWindow("Maze of Life", 100, 100, 480, 480, SDL_WINDOW_SHOWN);
34 if (window == NULL) 34 if (window == NULL)
35 { 35 {
36 std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl; 36 std::cout << "SDL_CreateWindow Error: " << SDL_GetError() << std::endl;
37 return 1; 37 return 1;
38 } 38 }
39 39
40 SDL_Surface* icon = SDL_LoadBMP("resources/icon.bmp"); 40 SDL_Surface* icon = SDL_LoadBMP("resources/icon.bmp");
41 SDL_SetWindowIcon(window, icon); 41 SDL_SetWindowIcon(window, icon);
42 42
43 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); 43 SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
44 if (renderer == NULL) 44 if (renderer == NULL)
45 { 45 {
@@ -52,7 +52,7 @@ int main(int argc, char *argv[])
52 { 52 {
53 state = (*state)(window, renderer); 53 state = (*state)(window, renderer);
54 } 54 }
55 55
56 SDL_DestroyRenderer(renderer); 56 SDL_DestroyRenderer(renderer);
57 SDL_DestroyWindow(window); 57 SDL_DestroyWindow(window);
58 SDLNet_Quit(); 58 SDLNet_Quit();
diff --git a/titlestate.cpp b/titlestate.cpp index 2b85fbe..014b138 100644 --- a/titlestate.cpp +++ b/titlestate.cpp
@@ -9,14 +9,14 @@ State* TitleState::operator() (SDL_Window* window, SDL_Renderer* renderer)
9 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 9 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
10 int selection = 0; 10 int selection = 0;
11 SDL_Event e; 11 SDL_Event e;
12 12
13 for (;;) 13 for (;;)
14 { 14 {
15 SDL_RenderClear(renderer); 15 SDL_RenderClear(renderer);
16 SDL_RenderCopy(renderer, background, NULL, NULL); 16 SDL_RenderCopy(renderer, background, NULL, NULL);
17 applyTexture(renderer, pointer, 136, selection==0?316:(selection==1?350:(selection==2?381:417))); 17 applyTexture(renderer, pointer, 136, selection==0?316:(selection==1?350:(selection==2?381:417)));
18 SDL_RenderPresent(renderer); 18 SDL_RenderPresent(renderer);
19 19
20 while (SDL_PollEvent(&e)) 20 while (SDL_PollEvent(&e))
21 { 21 {
22 if (e.type == SDL_QUIT) 22 if (e.type == SDL_QUIT)
@@ -51,14 +51,14 @@ State* HowToPlayState::operator() (SDL_Window* window, SDL_Renderer* renderer)
51 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 51 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
52 int selection = 0; 52 int selection = 0;
53 SDL_Event e; 53 SDL_Event e;
54 54
55 for (;;) 55 for (;;)
56 { 56 {
57 SDL_RenderClear(renderer); 57 SDL_RenderClear(renderer);
58 SDL_RenderCopy(renderer, background, NULL, NULL); 58 SDL_RenderCopy(renderer, background, NULL, NULL);
59 applyTexture(renderer, pointer, selection==0?74:216, 430); 59 applyTexture(renderer, pointer, selection==0?74:216, 430);
60 SDL_RenderPresent(renderer); 60 SDL_RenderPresent(renderer);
61 61
62 while (SDL_PollEvent(&e)) 62 while (SDL_PollEvent(&e))
63 { 63 {
64 if (e.type == SDL_QUIT) 64 if (e.type == SDL_QUIT)
@@ -95,14 +95,14 @@ State* HowToPlayPageTwoState::operator() (SDL_Window* window, SDL_Renderer* rend
95 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp"); 95 SDL_Texture* pointer = loadImage(renderer, "resources/pointer.bmp");
96 int selection = 0; 96 int selection = 0;
97 SDL_Event e; 97 SDL_Event e;
98 98
99 for (;;) 99 for (;;)
100 { 100 {
101 SDL_RenderClear(renderer); 101 SDL_RenderClear(renderer);
102 SDL_RenderCopy(renderer, background, NULL, NULL); 102 SDL_RenderCopy(renderer, background, NULL, NULL);
103 applyTexture(renderer, pointer, selection==0?45:238, 430); 103 applyTexture(renderer, pointer, selection==0?45:238, 430);
104 SDL_RenderPresent(renderer); 104 SDL_RenderPresent(renderer);
105 105
106 while (SDL_PollEvent(&e)) 106 while (SDL_PollEvent(&e))
107 { 107 {
108 if (e.type == SDL_QUIT) 108 if (e.type == SDL_QUIT)
diff --git a/util.cpp b/util.cpp index 868161f..5ccfe51 100644 --- a/util.cpp +++ b/util.cpp
@@ -11,7 +11,7 @@ void wrap(int* x, int* y)
11 { 11 {
12 *x = *x-WIDTH; 12 *x = *x-WIDTH;
13 } 13 }
14 14
15 if (*y < 0) 15 if (*y < 0)
16 { 16 {
17 *y = HEIGHT-(0-*y); 17 *y = HEIGHT-(0-*y);
@@ -53,10 +53,10 @@ SDL_Texture* loadImage(SDL_Renderer* renderer, std::string file)
53 std::cout << SDL_GetError() << std::endl; 53 std::cout << SDL_GetError() << std::endl;
54 return NULL; 54 return NULL;
55 } 55 }
56 56
57 SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface); 57 SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);
58 SDL_FreeSurface(surface); 58 SDL_FreeSurface(surface);
59 59
60 return texture; 60 return texture;
61} 61}
62 62
@@ -66,6 +66,6 @@ void applyTexture(SDL_Renderer* renderer, SDL_Texture* tex, int x, int y)
66 pos.x = x; 66 pos.x = x;
67 pos.y = y; 67 pos.y = y;
68 SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h); 68 SDL_QueryTexture(tex, NULL, NULL, &pos.w, &pos.h);
69 69
70 SDL_RenderCopy(renderer, tex, NULL, &pos); 70 SDL_RenderCopy(renderer, tex, NULL, &pos);
71} \ No newline at end of file 71} \ No newline at end of file