From d37a91a9e186f285ae63d44846f9bd8a17f77ed7 Mon Sep 17 00:00:00 2001 From: Patrick Rye Date: Thu, 10 Sep 2015 14:49:07 -0400 Subject: [PATCH] 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 --- Documentation/ChangeLog.md | 10 ++ Source/main.cpp | 193 +++++++++++++++++++++++++++++++------ Source/main.h | 6 ++ Source/version.h | 8 +- 4 files changed, 186 insertions(+), 31 deletions(-) diff --git a/Documentation/ChangeLog.md b/Documentation/ChangeLog.md index 3b0eb8f..358c19f 100644 --- a/Documentation/ChangeLog.md +++ b/Documentation/ChangeLog.md @@ -3,6 +3,16 @@ All notable changes to this project will be documented here. This project adheres to [Semantic Versioning](http://semver.org/) +## [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 + + ## [0.5.0] - 2015-09-10 ### Added * Save icon, Close icon, left and right arrows to tile map (not implemented yet) diff --git a/Source/main.cpp b/Source/main.cpp index 7063cfd..2db3eba 100644 --- a/Source/main.cpp +++ b/Source/main.cpp @@ -50,7 +50,6 @@ int main(int argc, char *argv[]) { Toolbar::make_buttons(); while ( quit == false) { - //TODO scrolling with arrows keys. Screen::show(); if (SDL_PollEvent( &event ) ) { Toolbar::check_events( &event ); @@ -61,7 +60,7 @@ int main(int argc, char *argv[]) { //Clean up the screen Screen::cleanup(); //TODO ask if should save - Map::save(); + //Map::save(); return 0; } /**********************************************************************************************************************************************/ @@ -299,21 +298,20 @@ void Screen::show() { SDL_Rect dst; //Do a few checks on the offset so we aren't accessing a non-existing part of the map array. - OFFST modoffset; - if (Screen::offset.y < 0) {modoffset.y = 0;} - 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;} - else {modoffset.y = Screen::offset.y;} + if (Screen::offset.y < 0) {Screen::modoffset.y = 0;} + 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;} + else {Screen::modoffset.y = Screen::offset.y;} - if (Screen::offset.x < 0) {modoffset.x = 0;} - 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;} - else {modoffset.x = Screen::offset.x;} + if (Screen::offset.x < 0) {Screen::modoffset.x = 0;} + 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;} + else {Screen::modoffset.x = Screen::offset.x;} for (uint y = 0; (y < DEFINED_MAP_HEIGHT); y++) { for (uint x = 0; (x < DEFINED_MAP_WIDTH); x++) { //update where we're trying to put the texture. - dst.x = (x * Global::pic_size) - modoffset.x; - dst.y = (y * Global::pic_size) - modoffset.y; + dst.x = (x * Global::pic_size) - Screen::modoffset.x; + dst.y = (y * Global::pic_size) - Screen::modoffset.y; dst.h = Global::pic_size; dst.w = Global::pic_size; @@ -340,7 +338,102 @@ void Screen::show() { char Screen::promptuser(uchar prompttype, std::string message) { //Prompt the user for something, prompt the user for something. //returns what they say. - return 'F'; + + //Clear the Renderer + SDL_RenderClear(Screen::window.ren); + + //Copy the sky + SDL_RenderCopy(Screen::window.ren, Textures::tilemap, &Textures::clips[tileSpace], NULL); + + SDL_Surface* surmessage = TTF_RenderText_Solid(Screen::window.MessageFont, message.c_str(), Screen::colors.Black); + if (surmessage == nullptr) { + Screen::error(); + return 'F'; + } + + SDL_Rect dst; + + Textures::texmessage = SDL_CreateTextureFromSurface(Screen::window.ren, surmessage); + if (Textures::texmessage == nullptr) { + Screen::error(); + return 'F'; + } else {Screen::blnload.blnMessage = true;} + + SDL_QueryTexture(Textures::texmessage, NULL, NULL, &dst.w, &dst.h); + //figure out x and y so that message is in the middle + + dst.x = (uint) ((Screen::window.width / 2) - (dst.w / 2)); + dst.y = (uint) ((Screen::window.height / 2) - (dst.h / 2)); + + SDL_RenderCopy(Screen::window.ren, Textures::texmessage, NULL, &dst); + + std::string message2; + + switch (prompttype) { + case promptYesNo: + message2 = "Please hit Y for yes, or N for no."; + break; + case promptOkay: + message2 = "Please hit any button to close."; + break; + default : + message2 = " "; + break; + } + + surmessage = TTF_RenderText_Solid(Screen::window.MessageFont, message2.c_str(), Screen::colors.Black); + if (surmessage == nullptr) { + Screen::error(); + return 'F'; + } + + Textures::texmessage = SDL_CreateTextureFromSurface(Screen::window.ren, surmessage); + if (Textures::texmessage == nullptr) { + Screen::error(); + return 'F'; + } else {Screen::blnload.blnMessage = true;} + + SDL_QueryTexture(Textures::texmessage, NULL, NULL, &dst.w, &dst.h); + //figure out x and y so that message is in the middle, but below the first message + dst.x = (uint) ((Screen::window.width / 2) - (dst.w / 2)); + dst.y = (uint) ((Screen::window.height / 2) + (dst.h / 2)); + + SDL_RenderCopy(Screen::window.ren, Textures::texmessage, NULL, &dst); + + bool blnStopLoop = false; + char keyPress; + SDL_Event event; + + //Start looping while wait for a response. + do { + SDL_RenderPresent(Screen::window.ren); + if (SDL_PollEvent( &event ) ) { + if (event.type == SDL_QUIT) { + //player wants to quit leave the loop + keyPress = 'N'; + blnStopLoop = true; + } else if (event.type == SDL_KEYDOWN) { + switch (prompttype) { + case promptOkay: + keyPress = 'O'; + blnStopLoop = true; + break; + case promptYesNo: + switch (event.key.keysym.sym) { + case SDLK_y: + keyPress = 'Y'; + blnStopLoop = true; + break; + case SDLK_n: + keyPress = 'N'; + blnStopLoop = true; + break; + } //end switch key + }//end switch prompt type + } // end if event type + } //end if poll event + } while (blnStopLoop == false); + return keyPress; } /**********************************************************************************************************************************************/ void Toolbar::make_buttons() { @@ -403,9 +496,9 @@ void Toolbar::check_events(SDL_Event* e) { //user did not click on any buttons therefore change the map tile. //convert to map coordinates uint mapx, mapy; - - mapx = (uint) (x / Global::pic_size); - mapy = (uint) (y / Global::pic_size); + /* TODO (GamerMan7799#1#): Add drag ability */ + mapx = (uint) ( (x + Screen::modoffset.x) / Global::pic_size); + mapy = (uint) ( (y + Screen::modoffset.y) / Global::pic_size); Global::map[mapy][mapx] = paintbrush.CurrentTile; } else if (e->type == SDL_KEYDOWN) { @@ -449,24 +542,67 @@ void Toolbar::check_events(SDL_Event* e) { return; break; - //Saving cases. + //Menu cases case SDLK_v: Map::save(); break; - + case SDLK_n: + Map::newmap(); + break; + case SDLK_l: + Map::load(); + break; + //Switch tile + case SDLK_1: + Toolbar::paintbrush.CurrentTile = tileSpace; + break; + case SDLK_2: + Toolbar::paintbrush.CurrentTile = tileWall; + break; + case SDLK_3: + Toolbar::paintbrush.CurrentTile = tilePlayer; + break; + case SDLK_4: + Toolbar::paintbrush.CurrentTile = tilePole; + break; + case SDLK_5: + Toolbar::paintbrush.CurrentTile = tileMonster; + break; + case SDLK_6: + Toolbar::paintbrush.CurrentTile = tileCoin; + break; } //end switch } //end if event type } /**********************************************************************************************************************************************/ void Map::save() { - /* TODO (GamerMan7799#1#): Prompt to overwrite if saves exists */ - FILE* savemap = fopen("map.sav","w"); - for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) { - for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) { - fprintf(savemap,"%u ", Global::map[y][x]); - } - fprintf(savemap, "\n"); - } + FILE* savemap; + savemap = fopen("map.sav", "r"); + if (savemap == NULL) { + // save does not exist make a new one. + if (Global::blnDebugMode) {printf("No save found.\n");} + savemap = fopen("map.sav","w"); + for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) { + for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) { + fprintf(savemap,"%u ", Global::map[y][x]); + } //end for x + fprintf(savemap, "\n"); + } //end for y + } else { + if (Global::blnDebugMode) {printf("Save found.\n");} + fclose(savemap); + if (Screen::promptuser(promptYesNo, "Save already exists, would you like to overwrite?") == 'Y') { + if (Global::blnDebugMode) {printf("Overwrite save.\n");} + for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) { + for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) { + fprintf(savemap,"%u ", Global::map[y][x]); + } //end for x + fprintf(savemap, "\n"); + } //end for y + } else { + if (Global::blnDebugMode) {printf("Do not overwrite\n");} + } //end if y or n + } //end if exists } /**********************************************************************************************************************************************/ void Map::load() { @@ -475,7 +611,10 @@ void Map::load() { /**********************************************************************************************************************************************/ void Map::newmap() { //New map; completely blank + for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) { + for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) { + Global::map[y][x] = tileSpace; + } + } } /**********************************************************************************************************************************************/ - - diff --git a/Source/main.h b/Source/main.h index 0a9b0d3..c67feb2 100644 --- a/Source/main.h +++ b/Source/main.h @@ -96,6 +96,11 @@ enum tools { toolBucket, toolLine, }; + +enum prompttype { + promptYesNo = 0, + promptOkay +}; /**********************************************************************************************************************************************/ namespace Global { 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 { bool bln_SDL_Started; WINDATT window; OFFST offset; + OFFST modoffset; //offset that has been modded slightly (is this even needed?) }; //Functions related to the toolbar diff --git a/Source/version.h b/Source/version.h index 6ac0620..a6a3432 100644 --- a/Source/version.h +++ b/Source/version.h @@ -10,14 +10,14 @@ //Standard Version Type #define DEFINED_VER_MAJOR 0 -#define DEFINED_VER_MINOR 5 +#define DEFINED_VER_MINOR 6 #define DEFINED_VER_PATCH 0 //Miscellaneous Version Types //Don't forget to increment the build number before each build -#define DEFINED_VER_RC_FILEVERSION 0,5,0,2 -#define DEFINED_VER_RC_FILEVERSION_STRING "0,5,0,2\0" -#define DEFINED_VER_FULLVERSION_STRING "0.5.0" +#define DEFINED_VER_RC_FILEVERSION 0,6,0,6 +#define DEFINED_VER_RC_FILEVERSION_STRING "0,6,0,6\0" +#define DEFINED_VER_FULLVERSION_STRING "0.6.0" //Software Status #define DEFINED_VER_STATUS "Alpha"