Skip to content
This repository was archived by the owner on May 2, 2019. It is now read-only.

Commit d37a91a

Browse files
author
Patrick Rye
committed
Update to v0.6.0
## [0.6.0] - 2015-09-10 ### Added * Restarting of map * Switching tile by num keys 1 - 6 * Prompt to replace a map save ### Fixed * Drawing map on being messed being I forgot to factor in offset
1 parent c81545e commit d37a91a

File tree

4 files changed

+186
-31
lines changed

4 files changed

+186
-31
lines changed

Documentation/ChangeLog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
All notable changes to this project will be documented here.
44
This project adheres to [Semantic Versioning](http://semver.org/)
55

6+
## [0.6.0] - 2015-09-10
7+
### Added
8+
* Restarting of map
9+
* Switching tile by num keys 1 - 6
10+
* Prompt to replace a map save
11+
12+
### Fixed
13+
* Drawing map on being messed being I forgot to factor in offset
14+
15+
616
## [0.5.0] - 2015-09-10
717
### Added
818
* Save icon, Close icon, left and right arrows to tile map (not implemented yet)

Source/main.cpp

Lines changed: 166 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ int main(int argc, char *argv[]) {
5050
Toolbar::make_buttons();
5151

5252
while ( quit == false) {
53-
//TODO scrolling with arrows keys.
5453
Screen::show();
5554
if (SDL_PollEvent( &event ) ) {
5655
Toolbar::check_events( &event );
@@ -61,7 +60,7 @@ int main(int argc, char *argv[]) {
6160
//Clean up the screen
6261
Screen::cleanup();
6362
//TODO ask if should save
64-
Map::save();
63+
//Map::save();
6564
return 0;
6665
}
6766
/**********************************************************************************************************************************************/
@@ -299,21 +298,20 @@ void Screen::show() {
299298
SDL_Rect dst;
300299

301300
//Do a few checks on the offset so we aren't accessing a non-existing part of the map array.
302-
OFFST modoffset;
303301

304-
if (Screen::offset.y < 0) {modoffset.y = 0;}
305-
else if (Screen::offset.y > (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height) {modoffset.y = (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height;}
306-
else {modoffset.y = Screen::offset.y;}
302+
if (Screen::offset.y < 0) {Screen::modoffset.y = 0;}
303+
else if (Screen::offset.y > (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height) {Screen::modoffset.y = (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height;}
304+
else {Screen::modoffset.y = Screen::offset.y;}
307305

308-
if (Screen::offset.x < 0) {modoffset.x = 0;}
309-
else if (Screen::offset.x > (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width) {modoffset.x = (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width;}
310-
else {modoffset.x = Screen::offset.x;}
306+
if (Screen::offset.x < 0) {Screen::modoffset.x = 0;}
307+
else if (Screen::offset.x > (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width) {Screen::modoffset.x = (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width;}
308+
else {Screen::modoffset.x = Screen::offset.x;}
311309

312310
for (uint y = 0; (y < DEFINED_MAP_HEIGHT); y++) {
313311
for (uint x = 0; (x < DEFINED_MAP_WIDTH); x++) {
314312
//update where we're trying to put the texture.
315-
dst.x = (x * Global::pic_size) - modoffset.x;
316-
dst.y = (y * Global::pic_size) - modoffset.y;
313+
dst.x = (x * Global::pic_size) - Screen::modoffset.x;
314+
dst.y = (y * Global::pic_size) - Screen::modoffset.y;
317315
dst.h = Global::pic_size;
318316
dst.w = Global::pic_size;
319317

@@ -340,7 +338,102 @@ void Screen::show() {
340338
char Screen::promptuser(uchar prompttype, std::string message) {
341339
//Prompt the user for something, prompt the user for something.
342340
//returns what they say.
343-
return 'F';
341+
342+
//Clear the Renderer
343+
SDL_RenderClear(Screen::window.ren);
344+
345+
//Copy the sky
346+
SDL_RenderCopy(Screen::window.ren, Textures::tilemap, &Textures::clips[tileSpace], NULL);
347+
348+
SDL_Surface* surmessage = TTF_RenderText_Solid(Screen::window.MessageFont, message.c_str(), Screen::colors.Black);
349+
if (surmessage == nullptr) {
350+
Screen::error();
351+
return 'F';
352+
}
353+
354+
SDL_Rect dst;
355+
356+
Textures::texmessage = SDL_CreateTextureFromSurface(Screen::window.ren, surmessage);
357+
if (Textures::texmessage == nullptr) {
358+
Screen::error();
359+
return 'F';
360+
} else {Screen::blnload.blnMessage = true;}
361+
362+
SDL_QueryTexture(Textures::texmessage, NULL, NULL, &dst.w, &dst.h);
363+
//figure out x and y so that message is in the middle
364+
365+
dst.x = (uint) ((Screen::window.width / 2) - (dst.w / 2));
366+
dst.y = (uint) ((Screen::window.height / 2) - (dst.h / 2));
367+
368+
SDL_RenderCopy(Screen::window.ren, Textures::texmessage, NULL, &dst);
369+
370+
std::string message2;
371+
372+
switch (prompttype) {
373+
case promptYesNo:
374+
message2 = "Please hit Y for yes, or N for no.";
375+
break;
376+
case promptOkay:
377+
message2 = "Please hit any button to close.";
378+
break;
379+
default :
380+
message2 = " ";
381+
break;
382+
}
383+
384+
surmessage = TTF_RenderText_Solid(Screen::window.MessageFont, message2.c_str(), Screen::colors.Black);
385+
if (surmessage == nullptr) {
386+
Screen::error();
387+
return 'F';
388+
}
389+
390+
Textures::texmessage = SDL_CreateTextureFromSurface(Screen::window.ren, surmessage);
391+
if (Textures::texmessage == nullptr) {
392+
Screen::error();
393+
return 'F';
394+
} else {Screen::blnload.blnMessage = true;}
395+
396+
SDL_QueryTexture(Textures::texmessage, NULL, NULL, &dst.w, &dst.h);
397+
//figure out x and y so that message is in the middle, but below the first message
398+
dst.x = (uint) ((Screen::window.width / 2) - (dst.w / 2));
399+
dst.y = (uint) ((Screen::window.height / 2) + (dst.h / 2));
400+
401+
SDL_RenderCopy(Screen::window.ren, Textures::texmessage, NULL, &dst);
402+
403+
bool blnStopLoop = false;
404+
char keyPress;
405+
SDL_Event event;
406+
407+
//Start looping while wait for a response.
408+
do {
409+
SDL_RenderPresent(Screen::window.ren);
410+
if (SDL_PollEvent( &event ) ) {
411+
if (event.type == SDL_QUIT) {
412+
//player wants to quit leave the loop
413+
keyPress = 'N';
414+
blnStopLoop = true;
415+
} else if (event.type == SDL_KEYDOWN) {
416+
switch (prompttype) {
417+
case promptOkay:
418+
keyPress = 'O';
419+
blnStopLoop = true;
420+
break;
421+
case promptYesNo:
422+
switch (event.key.keysym.sym) {
423+
case SDLK_y:
424+
keyPress = 'Y';
425+
blnStopLoop = true;
426+
break;
427+
case SDLK_n:
428+
keyPress = 'N';
429+
blnStopLoop = true;
430+
break;
431+
} //end switch key
432+
}//end switch prompt type
433+
} // end if event type
434+
} //end if poll event
435+
} while (blnStopLoop == false);
436+
return keyPress;
344437
}
345438
/**********************************************************************************************************************************************/
346439
void Toolbar::make_buttons() {
@@ -403,9 +496,9 @@ void Toolbar::check_events(SDL_Event* e) {
403496
//user did not click on any buttons therefore change the map tile.
404497
//convert to map coordinates
405498
uint mapx, mapy;
406-
407-
mapx = (uint) (x / Global::pic_size);
408-
mapy = (uint) (y / Global::pic_size);
499+
/* TODO (GamerMan7799#1#): Add drag ability */
500+
mapx = (uint) ( (x + Screen::modoffset.x) / Global::pic_size);
501+
mapy = (uint) ( (y + Screen::modoffset.y) / Global::pic_size);
409502

410503
Global::map[mapy][mapx] = paintbrush.CurrentTile;
411504
} else if (e->type == SDL_KEYDOWN) {
@@ -449,24 +542,67 @@ void Toolbar::check_events(SDL_Event* e) {
449542
return;
450543
break;
451544

452-
//Saving cases.
545+
//Menu cases
453546
case SDLK_v:
454547
Map::save();
455548
break;
456-
549+
case SDLK_n:
550+
Map::newmap();
551+
break;
552+
case SDLK_l:
553+
Map::load();
554+
break;
555+
//Switch tile
556+
case SDLK_1:
557+
Toolbar::paintbrush.CurrentTile = tileSpace;
558+
break;
559+
case SDLK_2:
560+
Toolbar::paintbrush.CurrentTile = tileWall;
561+
break;
562+
case SDLK_3:
563+
Toolbar::paintbrush.CurrentTile = tilePlayer;
564+
break;
565+
case SDLK_4:
566+
Toolbar::paintbrush.CurrentTile = tilePole;
567+
break;
568+
case SDLK_5:
569+
Toolbar::paintbrush.CurrentTile = tileMonster;
570+
break;
571+
case SDLK_6:
572+
Toolbar::paintbrush.CurrentTile = tileCoin;
573+
break;
457574
} //end switch
458575
} //end if event type
459576
}
460577
/**********************************************************************************************************************************************/
461578
void Map::save() {
462-
/* TODO (GamerMan7799#1#): Prompt to overwrite if saves exists */
463-
FILE* savemap = fopen("map.sav","w");
464-
for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) {
465-
for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) {
466-
fprintf(savemap,"%u ", Global::map[y][x]);
467-
}
468-
fprintf(savemap, "\n");
469-
}
579+
FILE* savemap;
580+
savemap = fopen("map.sav", "r");
581+
if (savemap == NULL) {
582+
// save does not exist make a new one.
583+
if (Global::blnDebugMode) {printf("No save found.\n");}
584+
savemap = fopen("map.sav","w");
585+
for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) {
586+
for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) {
587+
fprintf(savemap,"%u ", Global::map[y][x]);
588+
} //end for x
589+
fprintf(savemap, "\n");
590+
} //end for y
591+
} else {
592+
if (Global::blnDebugMode) {printf("Save found.\n");}
593+
fclose(savemap);
594+
if (Screen::promptuser(promptYesNo, "Save already exists, would you like to overwrite?") == 'Y') {
595+
if (Global::blnDebugMode) {printf("Overwrite save.\n");}
596+
for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) {
597+
for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) {
598+
fprintf(savemap,"%u ", Global::map[y][x]);
599+
} //end for x
600+
fprintf(savemap, "\n");
601+
} //end for y
602+
} else {
603+
if (Global::blnDebugMode) {printf("Do not overwrite\n");}
604+
} //end if y or n
605+
} //end if exists
470606
}
471607
/**********************************************************************************************************************************************/
472608
void Map::load() {
@@ -475,7 +611,10 @@ void Map::load() {
475611
/**********************************************************************************************************************************************/
476612
void Map::newmap() {
477613
//New map; completely blank
614+
for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) {
615+
for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) {
616+
Global::map[y][x] = tileSpace;
617+
}
618+
}
478619
}
479620
/**********************************************************************************************************************************************/
480-
481-

Source/main.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ enum tools {
9696
toolBucket,
9797
toolLine,
9898
};
99+
100+
enum prompttype {
101+
promptYesNo = 0,
102+
promptOkay
103+
};
99104
/**********************************************************************************************************************************************/
100105
namespace Global {
101106
extern const bool blnDebugMode; //Holds if in debug mode or not. Causes more messages to appear in the console-
@@ -116,6 +121,7 @@ namespace Screen {
116121
bool bln_SDL_Started;
117122
WINDATT window;
118123
OFFST offset;
124+
OFFST modoffset; //offset that has been modded slightly (is this even needed?)
119125
};
120126

121127
//Functions related to the toolbar

Source/version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010

1111
//Standard Version Type
1212
#define DEFINED_VER_MAJOR 0
13-
#define DEFINED_VER_MINOR 5
13+
#define DEFINED_VER_MINOR 6
1414
#define DEFINED_VER_PATCH 0
1515

1616
//Miscellaneous Version Types
1717
//Don't forget to increment the build number before each build
18-
#define DEFINED_VER_RC_FILEVERSION 0,5,0,2
19-
#define DEFINED_VER_RC_FILEVERSION_STRING "0,5,0,2\0"
20-
#define DEFINED_VER_FULLVERSION_STRING "0.5.0"
18+
#define DEFINED_VER_RC_FILEVERSION 0,6,0,6
19+
#define DEFINED_VER_RC_FILEVERSION_STRING "0,6,0,6\0"
20+
#define DEFINED_VER_FULLVERSION_STRING "0.6.0"
2121

2222
//Software Status
2323
#define DEFINED_VER_STATUS "Alpha"

0 commit comments

Comments
 (0)