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

Commit 599e72a

Browse files
author
Patrick Rye
committed
Update to v0.9.0
## [0.9.0] - 2015-09-14 ### Added * Menu Buttons (Save and close) ### Removed * Lots of unneeded code ## Fixed * Offset going off of map
1 parent 8a0c483 commit 599e72a

File tree

4 files changed

+73
-53
lines changed

4 files changed

+73
-53
lines changed

Documentation/ChangeLog.md

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

6+
## [0.9.0] - 2015-09-14
7+
### Added
8+
* Menu Buttons (Save and close)
9+
10+
### Removed
11+
* Lots of unneeded code
12+
13+
## Fixed
14+
* Offset going off of map
15+
16+
617
## [0.8.0] / Version Clown - 2015-09-12
718
### Fixed
819
* Several Copy Paste mistakes that weren't removed before.

Source/main.cpp

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ void Textures::load() {
167167
}
168168
/**********************************************************************************************************************************************/
169169
void Screen::start() {
170-
/* TODO (Gamerman7799 the Scrub#1#): More Comments Required to continue window32 Folder*/
171170
Screen::window.width = 35 * Global::pic_size;
172171
Screen::window.height = 14 * Global::pic_size;
173172
Screen::blnload.blnMessage = Screen::blnload.blnMessageFont = Screen::blnload.blnTiles = Screen::blnload.blnToolboxFrame = false;
@@ -189,14 +188,6 @@ void Screen::start() {
189188
if (Global::blnDebugMode) {printf("TTF init successful\n");}
190189
}
191190

192-
//Start Image (with only png)
193-
/*if (!(IMG_Init( IMG_INIT_PNG )) & IMG_INIT_PNG) {
194-
Screen::error();
195-
return;
196-
} else {
197-
if (Global::blnDebugMode) {printf("IMG init successful\n");}
198-
}*/
199-
200191
Screen::window.MessageFont = TTF_OpenFont(DEFINED_MESSAGE_FONT,16); //Opens font and sets size
201192
if ( Screen::window.MessageFont == nullptr) {
202193
printf("Font failed to load, messages will not appear.");
@@ -272,7 +263,6 @@ void Screen::cleanup() {
272263
}
273264

274265
TTF_Quit();
275-
//IMG_Quit();
276266
SDL_Quit();
277267
if (Global::blnDebugMode) {printf("SDL quit\n");}
278268
}
@@ -281,7 +271,6 @@ void Screen::error() {
281271
Screen::bln_SDL_Started = false;
282272
printf("SDL error: %s\n", SDL_GetError());
283273
printf("TTF error: %s\n", TTF_GetError());
284-
//printf("IMG error: %s\n", IMG_GetError());
285274
getchar();
286275
Screen::cleanup();
287276
}
@@ -293,29 +282,12 @@ void Screen::show() {
293282
SDL_RenderCopy(Screen::window.ren, Textures::tilemap, &Textures::clips[tileSpace], NULL);
294283
SDL_Rect dst;
295284
dst.h = dst.w = Global::pic_size;
296-
//Do a few checks on the offset so we aren't accessing a non-existing part of the map array.
297-
/* TODO (Gamerman7799 the Scrub#1#): Get rid of modoffset and replace with just normal offset
298-
299-
300-
301-
302-
303-
304-
JUST DO IT! */
305-
306-
if (Screen::offset.y < 0) {Screen::modoffset.y = 0;}
307-
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;}
308-
else {Screen::modoffset.y = Screen::offset.y;}
309-
310-
if (Screen::offset.x < 0) {Screen::modoffset.x = 0;}
311-
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;}
312-
else {Screen::modoffset.x = Screen::offset.x;}
313285

314286
for (uint y = 0; (y < DEFINED_MAP_HEIGHT); y++) {
315287
for (uint x = 0; (x < DEFINED_MAP_WIDTH); x++) {
316288
//update where we're trying to put the texture.
317-
dst.x = (x * Global::pic_size) - Screen::modoffset.x;
318-
dst.y = (y * Global::pic_size) - Screen::modoffset.y;
289+
dst.x = (x * Global::pic_size) - Screen::offset.x;
290+
dst.y = (y * Global::pic_size) - Screen::offset.y;
319291

320292
switch (Global::map[y][x]) { //Use this to make sure we aren't try to load a non-existing part
321293
case tileCoin:
@@ -441,12 +413,10 @@ char Screen::promptuser(uchar prompttype, std::string message) {
441413
void Toolbar::make_buttons() {
442414
uint centerx; //center of the toolbox
443415
centerx = (uint)(Screen::window.width / 2);
444-
//FIXME weird space in toolbar
445416
//Calculate all the places, the tool box frame has a 2 px wide border all the way around.
417+
//Make tile buttons
446418
for (uchar i = 0; i < DEFINED_NUM_BUTN_TILES; i++) {
447419
Toolbar::button_xplaces[i] = centerx - ( ( 2 - i ) * 4 ) - ( ( 2 - i ) * Global::pic_size );
448-
//if (i <= 2 ) {xplaces[i] -= 2;}
449-
//else {xplaces[i] += 2;}
450420
}
451421

452422
for (uchar i = 0; i < DEFINED_NUM_BUTN_TILES; i++) {
@@ -456,6 +426,15 @@ void Toolbar::make_buttons() {
456426
Toolbar::tilebuttons[i].box.y = 2;
457427
Toolbar::tilebuttons[i].box.x = Toolbar::button_xplaces[i];
458428
}
429+
430+
//Make menu buttons
431+
for (uchar i = 0; i < DEFINED_NUM_BUTN_MENU; i++) {
432+
Toolbar::menubuttons[i].buttontype = menuClose + i;
433+
Toolbar::menubuttons[i].clip = &Textures::clips[menuClose + i];
434+
Toolbar::menubuttons[i].box.w = Toolbar::menubuttons[i].box.h = Global::pic_size;
435+
Toolbar::menubuttons[i].box.y = 2;
436+
Toolbar::menubuttons[i].box.x = (Screen::window.width - 2) - ( (i+1) * Global::pic_size);
437+
}
459438
}
460439
/**********************************************************************************************************************************************/
461440
void Toolbar::draw() {
@@ -469,13 +448,20 @@ void Toolbar::draw() {
469448
SDL_RenderCopy(Screen::window.ren, Textures::toolboxframe, NULL, &dst);
470449
}
471450

472-
//Show all the buttons
451+
//Show all the tile buttons
473452
for (uchar i = 0; i < DEFINED_NUM_BUTN_TILES; i++) {
474453
SDL_RenderCopy(Screen::window.ren, Textures::tilemap, Toolbar::tilebuttons[i].clip, &Toolbar::tilebuttons[i].box);
475454
if (Toolbar::tilebuttons[i].buttontype == paintbrush.CurrentTile) {
476455
SDL_RenderCopy(Screen::window.ren, Textures::tilemap, &Textures::clips[menuFrame] , &Toolbar::tilebuttons[i].box);
477456
}
478457
}
458+
459+
//show all the menu buttons
460+
for (uchar i = 0; i < DEFINED_NUM_BUTN_MENU; i++) {
461+
//dst.x = (Screen::window.width - 2) - ( (i+1) * Global::pic_size);
462+
//SDL_RenderCopy(Screen::window.ren, Textures::toolboxframe, NULL, &dst);
463+
SDL_RenderCopy(Screen::window.ren, Textures::tilemap, Toolbar::menubuttons[i].clip, &Toolbar::menubuttons[i].box);
464+
}
479465
}
480466
/**********************************************************************************************************************************************/
481467
void Toolbar::check_events(SDL_Event* e) {
@@ -487,8 +473,7 @@ void Toolbar::check_events(SDL_Event* e) {
487473
int x, y;
488474
SDL_GetMouseState(&x, &y);
489475

490-
//check all of the buttons to see if we are on that one.
491-
476+
//check all of the tile buttons to see if we are on that one.
492477
for (uchar i = 0; i < DEFINED_NUM_BUTN_TILES; i++) {
493478
if ( x >= Toolbar::tilebuttons[i].box.x && x <= Toolbar::tilebuttons[i].box.x + Toolbar::tilebuttons[i].box.w ) { //In the x range
494479
if ( y >= Toolbar::tilebuttons[i].box.y && y <= Toolbar::tilebuttons[i].box.y + Toolbar::tilebuttons[i].box.h) { //in the y range
@@ -497,13 +482,31 @@ void Toolbar::check_events(SDL_Event* e) {
497482
} // end if in x
498483
} // end for buttons
499484

485+
//check all of the menu buttons
486+
for (uchar i = 0; i < DEFINED_NUM_BUTN_MENU; i++) {
487+
if ( x >= Toolbar::menubuttons[i].box.x && x <= Toolbar::menubuttons[i].box.x + Toolbar::menubuttons[i].box.w ) { //In the x range
488+
if ( y >= Toolbar::menubuttons[i].box.y && y <= Toolbar::menubuttons[i].box.y + Toolbar::menubuttons[i].box.h) { //in the y range
489+
blnButtonDown = false;
490+
switch (Toolbar::menubuttons[i].buttontype) {
491+
case menuSave:
492+
Map::save();
493+
break;
494+
case menuClose:
495+
if (Screen::promptuser(promptYesNo, "Do you really want to quit?") == 'Y') {
496+
e->type = SDL_QUIT;
497+
} //end if yes
498+
break;
499+
} //end switch
500+
} //end if in y
501+
} // end if in x
502+
} //end for menu buttons
503+
500504

501505
//user did not click on any buttons therefore change the map tile.
502506
//convert to map coordinates
503507
uint mapx, mapy;
504-
/* TODO (GamerMan7799#1#): Add drag ability */
505-
mapx = (uint) ( (x + Screen::modoffset.x) / Global::pic_size);
506-
mapy = (uint) ( (y + Screen::modoffset.y) / Global::pic_size);
508+
mapx = (uint) ( (x + Screen::offset.x) / Global::pic_size);
509+
mapy = (uint) ( (y + Screen::offset.y) / Global::pic_size);
507510

508511
Global::map[mapy][mapx] = paintbrush.CurrentTile;
509512
} else if (e->type == SDL_KEYDOWN) {
@@ -513,18 +516,22 @@ void Toolbar::check_events(SDL_Event* e) {
513516
case SDLK_UP:
514517
case SDLK_w:
515518
Screen::offset.y -= Global::pic_size;
519+
if (Screen::offset.y < 0) {Screen::offset.y = 0;}
516520
break;
517521
case SDLK_DOWN:
518522
case SDLK_s:
519523
Screen::offset.y += Global::pic_size;
524+
if (Screen::offset.y > (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height) {Screen::offset.y = (DEFINED_MAP_HEIGHT * Global::pic_size) - Screen::window.height;}
520525
break;
521526
case SDLK_RIGHT:
522527
case SDLK_d:
523528
Screen::offset.x += Global::pic_size;
529+
if (Screen::offset.x > (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width) {Screen::offset.x = (DEFINED_MAP_WIDTH * Global::pic_size) - Screen::window.width;}
524530
break;
525531
case SDLK_LEFT:
526532
case SDLK_a:
527533
Screen::offset.x -= Global::pic_size;
534+
if (Screen::offset.x < 0) {Screen::offset.x = 0;}
528535
break;
529536
case SDLK_HOME:
530537
Screen::offset.x = Screen::offset.y = 0;
@@ -559,6 +566,7 @@ void Toolbar::check_events(SDL_Event* e) {
559566
case SDLK_l:
560567
Map::load();
561568
break;
569+
562570
//Switch tile
563571
case SDLK_1:
564572
Toolbar::paintbrush.CurrentTile = tileSpace;
@@ -622,7 +630,7 @@ void Map::newmap() {
622630
for (uint y = 0; y < DEFINED_MAP_HEIGHT; y++) {
623631
for (uint x = 0; x < DEFINED_MAP_WIDTH; x++) {
624632
Global::map[y][x] = tileSpace;
625-
} //end for xh
633+
} //end for x
626634
} //end for y
627635
} //end if yes
628636
}

Source/main.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define DEFINED_MAP_WIDTH 217
2626
#define DEFINED_NUM_OF_TILES 12
2727
#define DEFINED_NUM_BUTN_TILES 6
28+
#define DEFINED_NUM_BUTN_MENU 2
2829
/**********************************************************************************************************************************************/
2930
//Ahh laziness at its finest
3031
//This is why Patrick, we can't have nice things
@@ -43,13 +44,13 @@ struct stcLoaded { //Holds boolEANs for if stuff is loaded or not
4344

4445
struct stcColors {
4546
SDL_Color Black;
46-
SDL_Color White; //Stupid code, you make me look bad
47+
SDL_Color White;
4748
};
4849

4950
struct stcWindowAtt { //Window attributes
5051
SDL_Window *win;
5152
SDL_Renderer *ren;
52-
TTF_Font *MessageFont; //You must build additional pylons
53+
TTF_Font *MessageFont;
5354
uint width;
5455
uint height;
5556
};
@@ -70,7 +71,7 @@ struct stcOffset {
7071
int y;
7172
};
7273

73-
typedef struct stcLoaded Loaded; //Abbreviations are OVER 9000!
74+
typedef struct stcLoaded Loaded;
7475
typedef struct stcColors clrs;
7576
typedef struct stcWindowAtt WINDATT;
7677
typedef struct stcPaintBrush BRUSH;
@@ -86,8 +87,8 @@ enum tile {
8687
tileCoin, //5
8788
menuFrame, //6
8889
menuError, //7
89-
menuSave, //8
90-
menuClose, //9
90+
menuClose, //8
91+
menuSave, //9
9192
menuLeft, //10
9293
menuRight //11
9394
};
@@ -104,7 +105,7 @@ enum prompttype {
104105
};
105106
/**********************************************************************************************************************************************/
106107
namespace Global {
107-
extern const bool blnDebugMode; //Holds if in debug mode or not. Causes more messages to appear in the console-
108+
extern const bool blnDebugMode; //Holds if in debug mode or not. Causes more messages to appear in the console
108109
extern const uint pic_size;
109110
extern uchar map[DEFINED_MAP_HEIGHT][DEFINED_MAP_WIDTH];
110111
};
@@ -123,7 +124,6 @@ namespace Screen {
123124
bool bln_SDL_Started;
124125
WINDATT window;
125126
OFFST offset;
126-
OFFST modoffset; //offset that has been modded slightly (is this even needed?)
127127
};
128128

129129
//Functions related to the toolbar
@@ -135,6 +135,7 @@ namespace Toolbar {
135135
uint button_xplaces[DEFINED_NUM_BUTN_TILES];
136136
BRUSH paintbrush;
137137
BTTN tilebuttons[DEFINED_NUM_BUTN_TILES];
138+
BTTN menubuttons[DEFINED_NUM_BUTN_MENU];
138139
};
139140

140141
//Stuff related to the textures

Source/version.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22
#define __VERSION_HEADER__
33

44
//Date Version Types
5-
#define DEFINED_VER_DATE "10"
5+
#define DEFINED_VER_DATE "14"
66
#define DEFINED_VER_MONTH "09"
77
#define DEFINED_VER_YEAR "2015"
88
//I don't know what this is for, but I'll leave it for now.
99
#define DEFINED_VER_UBUNTU_VERSION_STYLE "15.09"
1010

1111
//Standard Version Type
1212
#define DEFINED_VER_MAJOR 0
13-
#define DEFINED_VER_MINOR 8
13+
#define DEFINED_VER_MINOR 9
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,8,0,0
19-
#define DEFINED_VER_RC_FILEVERSION_STRING "0,8,0,0\0"
20-
#define DEFINED_VER_FULLVERSION_STRING "0.8.0"
18+
#define DEFINED_VER_RC_FILEVERSION 0,9,0,7
19+
#define DEFINED_VER_RC_FILEVERSION_STRING "0,9,0,7\0"
20+
#define DEFINED_VER_FULLVERSION_STRING "0.9.0"
2121

2222
//Software Status
2323
#define DEFINED_VER_STATUS "Alpha"
24-
#define DEFINED_VER_STATUS_SHORT "A"
24+
#define DEFINED_VER_STATUS_SHORT "a"
2525

2626
/*
2727
Software Status can be the following:

0 commit comments

Comments
 (0)