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

Commit

Permalink
Update to v0.6.0
Browse files Browse the repository at this point in the history
## [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
  • Loading branch information
Patrick Rye committed Sep 10, 2015
1 parent c81545e commit d37a91a
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 31 deletions.
10 changes: 10 additions & 0 deletions Documentation/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
193 changes: 166 additions & 27 deletions Source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
}
/**********************************************************************************************************************************************/
Expand Down Expand Up @@ -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;

Expand All @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}
}
}
/**********************************************************************************************************************************************/


6 changes: 6 additions & 0 deletions Source/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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-
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Source/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit d37a91a

Please sign in to comment.