Skip to content

Commit 4345f5c

Browse files
committed
fixed layout of main menu and added exit button to the options menu. Checkbox screenobjects now exist but are never used.
1 parent ca9681f commit 4345f5c

File tree

5 files changed

+135
-20
lines changed

5 files changed

+135
-20
lines changed

Globals.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ class globals {
2020
static Button* Options;
2121
static Button* Exit;
2222

23+
static Button* ExitOps;
24+
2325
static std::vector<screenObject*> g_ScreenObjects;
2426
static level* g_level;
2527
static player* g_player;

globals.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Button* globals::Resume;
1616
Button* globals::Options;
1717
Button* globals::Exit;
1818

19+
//option buttons
20+
Button* globals::ExitOps;
21+
1922
std::vector<screenObject*> globals::g_ScreenObjects;
2023
level* globals::g_level;
2124
player* globals::g_player;

paint.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ void pnt(HWND hWnd, RECT* region)
7070
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
7171
drawText(&buffer, globals::End->text, temprect, globals::End->txtFlag, tempCol);
7272
break;
73+
case 1:
74+
tempCol = globals::ExitOps->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
75+
temprect = globals::ExitOps->rect;
76+
temprect.top = ((temprect.bottom + temprect.top) / 2) - 8;
77+
drawText(&buffer, globals::ExitOps->text, temprect, globals::ExitOps->txtFlag, tempCol);
78+
break;
7379
case 2:
7480
tempCol = globals::Resume->draw(&buffer, globals::g_mouseX, globals::g_mouseY, globals::g_mouseDown);
7581
temprect = globals::Resume->rect;

screenObjects.cpp

+63-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,68 @@ struct Button : public screenObject
9898
}
9999
};
100100

101+
struct CheckBox : public screenObject
102+
{
103+
bool* valPtr;
104+
105+
CheckBox(RECT rect, COLORREF color, bool * valPtr, std::string txt = "", unsigned int txtFlag = 1, bool debug = false) :
106+
screenObject(rect, color, txt, txtFlag, debug), valPtr(valPtr) {}
107+
108+
void screenObject::press(int n)
109+
{
110+
*this->valPtr = !*(this->valPtr);
111+
}
112+
113+
COLORREF screenObject::draw(HDC* hdc, long mousX, long mouseY, bool mouseDown)
114+
{
115+
COLORREF tempcolor = this->color;
116+
HBRUSH brush = NULL;
117+
if (this->active)
118+
{
119+
if (this->Touching(mousX, mouseY))
120+
{
121+
if (mouseDown)
122+
{
123+
tempcolor = RGB(GetRValue(this->color) - 20, GetGValue(this->color) - 20, GetBValue(this->color) - 20);
124+
brush = CreateSolidBrush(tempcolor);
125+
if (*this->valPtr)
126+
FillRect(*hdc, &this->rect, brush);
127+
else
128+
FrameRect(*hdc, &this->rect, brush);
129+
}
130+
else
131+
{
132+
tempcolor = RGB(GetRValue(this->color) + 15, GetGValue(this->color) + 15, GetBValue(this->color) + 15);
133+
brush = CreateSolidBrush(tempcolor);
134+
if (*this->valPtr)
135+
FillRect(*hdc, &this->rect, brush);
136+
else
137+
FrameRect(*hdc, &this->rect, brush);
138+
}
139+
}
140+
else
141+
{
142+
brush = CreateSolidBrush(this->color);
143+
if (*this->valPtr)
144+
FillRect(*hdc, &this->rect, brush);
145+
else
146+
FrameRect(*hdc, &this->rect, brush);
147+
}
148+
}
149+
else
150+
{
151+
tempcolor = RGB(GetRValue(this->color) - 25, GetGValue(this->color) - 25, GetBValue(this->color) - 25);
152+
brush = CreateSolidBrush(tempcolor);
153+
if (*this->valPtr)
154+
FillRect(*hdc, &this->rect, brush);
155+
else
156+
FrameRect(*hdc, &this->rect, brush);
157+
}
158+
DeleteObject(brush);
159+
return tempcolor;
160+
}
161+
};
162+
101163
struct Text : public screenObject
102164
{
103165
Text(RECT rect, COLORREF color, std::string txt, unsigned int txtFlag = 1, bool debug = false) :
@@ -279,7 +341,6 @@ struct level : public screenObject
279341
{
280342
stage* foreground = nullptr; //THESE ARE POINTERS TO ARRAYS
281343
stage* background = nullptr;
282-
unsigned int varienceFactor = 1;
283344
unsigned char lw = 0; //width of level (in stages)
284345
unsigned char lh = 0; //height of level (in stages)
285346
unsigned char startCX;
@@ -535,7 +596,7 @@ struct player : public screenObject
535596
file.open("player.dt");
536597
if (file.is_open())
537598
{
538-
file << "LVL:" + std::to_string(this->lvl);
599+
file << "LVL:" << this->lvl;
539600
file.close();
540601
return true;
541602
}

taptapsound.cpp

+61-18
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ HWND wnd; // current window
1212
WCHAR szTitle[MAX_LOADSTRING]; // The title bar text
1313
WCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
1414

15+
HBITMAP MMenu;
16+
HBITMAP Paused;
17+
HBITMAP Options;
18+
1519
HBITMAP TSimg;
1620
HBITMAP TSmask;
1721
HBITMAP playerSprite;
@@ -177,9 +181,10 @@ Text* modtxt1 = new Text(createRECT(0, 75, 250, 18), RGB(255, 255, 255), "Shifti
177181
Text* modtxt2 = new Text(createRECT(0, 92, 250, 18), RGB(255, 255, 255), "Control: " + std::to_string(globals::g_modKeys.at(VK_CONTROL)), DT_LEFT, true);
178182
Text* modtxt3 = new Text(createRECT(0, 109, 250, 18), RGB(255, 255, 255), "Tab: " + std::to_string(globals::g_modKeys.at(VK_TAB)), DT_LEFT, true);
179183

180-
Text* debugtxt = new Text(createRECT(0, 140, 250, 18), RGB(255, 255, 255), "Debug: " + std::to_string(globals::g_debug), DT_LEFT, true);
184+
Text* debugtxt = new Text(createRECT(0, 130, 250, 18), RGB(255, 255, 255), "Debug: " + std::to_string(globals::g_debug), DT_LEFT, true);
181185

182-
Text* fpstxt = new Text(createRECT(0, 165, 250, 18), RGB(255, 255, 255), "FPS: " + std::to_string(globals::g_fps), DT_LEFT, true);
186+
Text* fpstxt = new Text(createRECT(0, 150, 250, 18), RGB(255, 255, 255), "FPS: " + std::to_string(globals::g_fps), DT_LEFT, true);
187+
Text* Afpstxt = new Text(createRECT(0, 168, 250, 18), RGB(255, 255, 255), "AFPS: " + std::to_string(globals::g_fps), DT_LEFT, true);
183188

184189
Image* mousebox = new Image(createRECT(0, 0, 64, 64), mouseSpriteU);
185190

@@ -217,6 +222,8 @@ void end(int n)
217222
delete globals::Options;
218223
delete globals::Exit;
219224

225+
delete globals::ExitOps;
226+
220227
delete globals::g_player;
221228
if(!globals::g_level->uninit)delete globals::g_level;
222229

@@ -235,17 +242,24 @@ void end(int n)
235242
exit(0);
236243
}
237244

245+
void exitOptions(int i)
246+
{
247+
globals::curScreen = globals::prevScreen;
248+
}
249+
238250
void buildScreenObjects()
239251
{
240-
globals::NewGame = new Button(createRECT(225, 0, 300, 100), RGB(70, 125, 150), &startN, "New Game");
241-
globals::Continue = new Button(createRECT(225, 90, 300, 100), RGB(70, 125, 150), &cont, "Continue");
242-
globals::Options0 = new Button(createRECT(225, 240, 300, 100), RGB(70, 125, 150), &options, "Options");
243-
globals::End = new Button(createRECT(225, 390, 300, 100), RGB(70, 125, 150), &end, "Exit");
252+
globals::NewGame = new Button(createRECT(225, 35, 300, 100), RGB(70, 125, 150), &startN, "New Game");
253+
globals::Continue = new Button(createRECT(225, 165, 300, 100), RGB(70, 125, 150), &cont, "Continue");
254+
globals::Options0 = new Button(createRECT(225, 295, 300, 100), RGB(70, 125, 150), &options, "Options");
255+
globals::End = new Button(createRECT(225, 425, 300, 100), RGB(70, 125, 150), &end, "Exit");
244256

245257
globals::Resume = new Button(createRECT(225, 90, 300, 100), RGB(70, 125, 150), &resume, "Resume");
246258
globals::Options = new Button(createRECT(225, 240, 300, 100), RGB(70, 125, 150), &options, "Options");
247259
globals::Exit = new Button(createRECT(225, 390, 300, 100), RGB(70, 125, 150), &quit, "Exit");
248260

261+
globals::ExitOps = new Button(createRECT(225, 390, 300, 100), RGB(70, 125, 150), &exitOptions, "Exit");
262+
249263
tilesets.reserve(1);
250264
tileset->source = TSimg;
251265
tileset->sourceMask = TSmask;
@@ -269,7 +283,7 @@ void buildScreenObjects()
269283

270284
globals::g_mousebox = mousebox;
271285

272-
globals::g_ScreenObjects.reserve(12);
286+
globals::g_ScreenObjects.reserve(13);
273287

274288
globals::g_ScreenObjects.push_back(mouseXtxt);
275289
globals::g_ScreenObjects.push_back(mouseYtxt);
@@ -287,6 +301,7 @@ void buildScreenObjects()
287301
globals::g_ScreenObjects.push_back(debugtxt);
288302

289303
globals::g_ScreenObjects.push_back(fpstxt);
304+
globals::g_ScreenObjects.push_back(Afpstxt);
290305

291306
globals::g_ScreenObjects.push_back(globals::g_mousebox);
292307
}
@@ -303,6 +318,10 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
303318
return FALSE;
304319
}
305320

321+
//MMenu = LoadBitmap(hInst, MAKEINTRESOURCE(@TODO));
322+
//Paused = LoadBitmap(hInst, MAKEINTRESOURCE(@TODO));
323+
//Options = LoadBitmap(hInst, MAKEINTRESOURCE(@TODO));
324+
306325
TSimg = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_TILESET1));
307326
TSmask = CreateBitmapMask(TSimg, RGB(0,0,1));
308327
playerSprite = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_PLAYER1));
@@ -328,7 +347,7 @@ void pressed(WPARAM key)
328347
{
329348
if (globals::curScreen == 1)
330349
{
331-
globals::curScreen = globals::prevScreen;
350+
exitOptions(0);
332351
}
333352
else
334353
{
@@ -387,6 +406,7 @@ void depressed(WPARAM key)
387406

388407
unsigned long long fpsTimer = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
389408
unsigned int times = 0;
409+
unsigned int Atimes = 0;
390410

391411
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
392412
{
@@ -411,15 +431,20 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
411431
RECT temp;
412432
GetUpdateRect(hWnd, &temp, true);
413433
pnt(hWnd, &temp);
434+
Atimes++;
414435
}
415436
break;
416437
case WM_ERASEBKGND:
417438
return TRUE;
418439
case WM_MOUSEMOVE:
419440
globals::g_mouseX = GET_X_LPARAM(lParam);
420441
globals::g_mouseY = GET_Y_LPARAM(lParam);
421-
mouseXtxt->text = "Mouse X: " + std::to_string(globals::g_mouseX);
422-
mouseYtxt->text = "Mouse Y: " + std::to_string(globals::g_mouseY);
442+
if (globals::g_debug)
443+
{
444+
mouseXtxt->text = "Mouse X: " + std::to_string(globals::g_mouseX);
445+
mouseYtxt->text = "Mouse Y: " + std::to_string(globals::g_mouseY);
446+
}
447+
423448
if(globals::curScreen == 3)
424449
if (globals::g_mousebox->rect.left + 32 > 34 && globals::g_mousebox->rect.left + 32 < 734 && globals::g_mousebox->rect.top+32 > 35 && !globals::g_player->collideMouseX(float(mousebox->rect.left), float(mousebox->rect.top), false) && !globals::g_player->collideMouseY(float(mousebox->rect.left), float(mousebox->rect.top), false))
425450
if (globals::g_modKeys.at(VK_SHIFT) || globals::g_mouseDown) globals::g_player->mousebox = true;
@@ -451,6 +476,13 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
451476
InvalidateRect(hWnd, &createRECT(0, 0, SWIDTH, SHEIGHT), true);
452477
}
453478
break;
479+
case 1:
480+
if (globals::ExitOps->active && globals::ExitOps->Touching(globals::g_mouseX, globals::g_mouseY))
481+
{
482+
globals::ExitOps->press(0);
483+
InvalidateRect(hWnd, &createRECT(0, 0, SWIDTH, SHEIGHT), true);
484+
}
485+
break;
454486
case 2:
455487
if (globals::Resume->active && globals::Resume->Touching(globals::g_mouseX, globals::g_mouseY))
456488
{
@@ -508,9 +540,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
508540
default:
509541
pressed(wParam);
510542
}
511-
modtxt1->text = "Shifting: " + std::to_string(globals::g_modKeys.at(VK_SHIFT));
512-
modtxt2->text = "Control: " + std::to_string(globals::g_modKeys.at(VK_CONTROL));
513-
modtxt3->text = "Tab: " + std::to_string(globals::g_modKeys.at(VK_TAB));
543+
if (globals::g_debug)
544+
{
545+
modtxt1->text = "Shifting: " + std::to_string(globals::g_modKeys.at(VK_SHIFT));
546+
modtxt2->text = "Control: " + std::to_string(globals::g_modKeys.at(VK_CONTROL));
547+
modtxt3->text = "Tab: " + std::to_string(globals::g_modKeys.at(VK_TAB));
548+
}
514549
break;
515550
case WM_KEYUP:
516551
switch (wParam)
@@ -529,22 +564,30 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
529564
default:
530565
depressed(wParam);
531566
}
532-
modtxt1->text = "Shifting: " + std::to_string(globals::g_modKeys.at(VK_SHIFT));
533-
modtxt2->text = "Control: " + std::to_string(globals::g_modKeys.at(VK_CONTROL));
534-
modtxt3->text = "Tab: " + std::to_string(globals::g_modKeys.at(VK_TAB));
567+
if (globals::g_debug)
568+
{
569+
modtxt1->text = "Shifting: " + std::to_string(globals::g_modKeys.at(VK_SHIFT));
570+
modtxt2->text = "Control: " + std::to_string(globals::g_modKeys.at(VK_CONTROL));
571+
modtxt3->text = "Tab: " + std::to_string(globals::g_modKeys.at(VK_TAB));
572+
}
535573
break;
536574
case WM_TIMER:
537575
switch (wParam)
538576
{
539577
case 1:
540578
globals::timeNow = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
541-
timetxt->text = "Time Now: " + std::to_string(globals::timeNow);
579+
if(globals::g_debug) timetxt->text = "Time Now: " + std::to_string(globals::timeNow);
542580
if (globals::timeNow - fpsTimer >= 1000)
543581
{
544582
fpsTimer += 1000;
545583
globals::g_fps = times;
546-
fpstxt->text = "FPS: " + std::to_string(globals::g_fps);
584+
if (globals::g_debug)
585+
{
586+
fpstxt->text = "FPS: " + std::to_string(globals::g_fps);
587+
Afpstxt->text = "AFPS: " + std::to_string(Atimes);
588+
}
547589
times = 1;
590+
Atimes = 0;
548591
}
549592
else {
550593
times++;

0 commit comments

Comments
 (0)