1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
string GameMenu()
/* This function displays the main menu of the game. The MenuSystem object
created here returns the selection chosen by the user. */
{
/* If the player has crashed the snake and is trying again, we do not need to
show the menu but just re-enter the master game loop. */
if (g_GameData.StartOver()) return "_dummy_";
/* Clean up the screen for drawing the menu. */
g_HdcOut.WideBox(0,1018,710,CreateSolidBrush(RGB(0,128,192)));
/* Draw yellow rectangle with shadow for menu. */
HRGN hrShadowRect = CreateRoundRectRgn(310,170,710,570,15,15);
FillRgn(g_WinDC,hrShadowRect,CreateSolidBrush(RGB(80,80,80)));
DeleteObject(hrShadowRect);
HRGN hrRoundRect = CreateRoundRectRgn(300,160,700,560,15,15);
FillRgn(g_WinDC,hrRoundRect,CreateSolidBrush(RGB(255,255,0)));
DeleteObject(hrRoundRect);
/* Create & define a rectangle structure. */
RECT rect; SetRect(&rect,10,250,130,700);
/* Paint the main Squibbles game title! */
g_HdcOut.Font("Courier New",50);
g_HdcOut.MakeBold(); // quickly make this font bold
g_HdcOut.Txt(315,30,"SQUIBBLES",RGB(0,0,0));
g_HdcOut.MakeTransparent(); // next font will have transparent background
g_HdcOut.MakeBold(); // quickly make this font bold
g_HdcOut.Txt(315,32,"SQUIBBLES",RGB(255,255,255));
g_HdcOut.Font("Courier",30);
g_HdcOut.Txt(675,65,"®",RGB(255,255,0)); // just for fancyness!
/* Create the main menu for the Squibbles game. */
MenuSystem Main;
// Fill the menu with selections...
Main.AddItem(312,190," Start Game ","Lucida Console",28);
Main.AddItem(312,240," Player Mode ","Lucida Console",28);
Main.AddItem(312,340," Skill Level ","Lucida Console",28);
Main.AddItem(312,440," How To Play ","Lucida Console",28);
Main.AddItem(312,490," Quit Game ","Lucida Console",28);
// Initialize menu display parameters.
Main.BkColor(RGB(255,255,0)); // Background.
Main.TxtColor(RGB(0,0,0)); // Text color.
Main.SltBkColor(RGB(255,0,0)); // Selection text background.
Main.SltTxtColor(RGB(230,230,230)); // Selection text color.
Main.InitMenu(); // Initialize menu for operation.
Main.Present(); // Display menu to screen.
/* Copyright information & developer. */
g_HdcOut.Font("Fixedsys",10);
g_HdcOut.WideBox(710,1018,30,CreateSolidBrush(RGB(192,192,192))); // draws the box
g_HdcOut.Txt(10,717,":: Copyright (C) 2011 Rafael Perez-Santana",RGB(0,0,0));
string MenuSlt; // To store returned selection.
bool blQuit = false; // For quitting the loop.
while(!blQuit)
{
/* Display the play mode and difficulty. */
g_HdcOut.Font("Verdana",20);
g_HdcOut.Txt(400,290,g_GameData.GetPlayMode(),RGB(128,128,128)); // play mode
g_HdcOut.Txt(415,390,g_GameData.GameDiffStr(),RGB(128,128,128)); // skill level
MenuSlt = Main.Control(); // Give control to the menu.
// If the window was commanded to close, quit the game. */
if (MenuSlt == "MenuSys::Close") return " Quit Game ";
if (MenuSlt == " Player Mode ")
{ // Cycle to; two player if single player.
if (g_GameData.GetPlayMode() == " ONE PLAYER ")
{ g_GameData.SetPlayMode(" TWO PLAYER "); continue; }
// Cycle to; single player if two player.
if (g_GameData.GetPlayMode() == " TWO PLAYER ")
{ g_GameData.SetPlayMode(" ONE PLAYER "); continue; }
}
/* Game difficulty or skill level. */
if (MenuSlt == " Skill Level ")
{ g_GameData.NextGameDiff(); continue; }
/* How to play message box. */
if (MenuSlt == " How To Play ")
{
MessageBox(g_Hwnd,
"The squibbles game is very simple. Maneuver your snake with the arrow keys "
"while eating the colorful squares that appear in random locations on the "
"screen. The snake will grow the more you eat and it will become faster!\n\n"
"If your in one player mode, your snake is Tommy and is yellow in color. If "
"your in two player mode, the second player controls Sammy, the white "
"snake.\n\n"
"To control Sammy the white snake, use the WASD keys. W is up, S is down, "
"A is left and D is right, MAKE SURE CAPSLOCK is off! To control Tommy the yellow "
"snake, use the arrow keys like I just pointed out in the first paragraph.\n\n"
"Do not hit walls or edges of the screen or your snake will die! You only get "
"five lives to attempt to beat the game, there are a total of seven levels and "
"they become difficult as you progress through the game.\n\n"
"I hope you like playing squibbles :) I spent four-months making this game, so "
"if you want to show any kind of support, send me an e-mail, I would love to hear "
"from you!\n\n"
"Happy Squibbling!\n\n"
"mr.rafael.ps@gmail.com",
"Squibbles --- How to Play",
MB_OK|MB_ICONINFORMATION);
continue; // Stay in menu.
}
blQuit = true; // Quit the loop.
}
return MenuSlt.c_str(); // Return menu selection.
}
////////////////////////////WINDOW PROCEDURE//////////////////////////////////
LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
/* This is the window procedure for the Squibbles game. What product can you
recommend to grow back the hairs I pulled out coding this? It seems that external
variables were the only solution. */
{
switch(Message)
{
case WM_COMMAND:
if (LOWORD(wParam) == BUTTON_ABOUT)
/* Game developer information. */
MessageBox(g_Hwnd,
"Squibbles 1.0\n"
"Copyright (C) 2011 Rafael Perez-Santana\n"
"All Rights Reserved.\n"
"Developed with Code::Blocks\n",
"Squibbles --- About",
MB_OK|MB_ICONINFORMATION);
break;
case WM_CHAR:
/* Key controls for Sammy. */
if ((int)wParam == g_GameData.GetKeyLeft(SAMMY)) g_Sammy.MoveLeft();
if ((int)wParam == g_GameData.GetKeyUp(SAMMY)) g_Sammy.MoveUp();
if ((int)wParam == g_GameData.GetKeyRight(SAMMY)) g_Sammy.MoveRight();
if ((int)wParam == g_GameData.GetKeyDown(SAMMY)) g_Sammy.MoveDown();
break;
case WM_KEYDOWN:
/* Key controls for Tommy. */
if ((int)wParam == g_GameData.GetKeyLeft(TOMMY)) g_Tommy.MoveLeft();
if ((int)wParam == g_GameData.GetKeyUp(TOMMY)) g_Tommy.MoveUp();
if ((int)wParam == g_GameData.GetKeyRight(TOMMY)) g_Tommy.MoveRight();
if ((int)wParam == g_GameData.GetKeyDown(TOMMY)) g_Tommy.MoveDown();
if (wParam == 27) // Escape key.
{ /* Player wants to quit to menu. Alert the player that all game
progress will be lost. */
LPCSTR szConfirm = "Progress will be lost if you return to menu! You sure?";
int iMB = MessageBox(hWnd,szConfirm,"Squibbles", MB_YESNO | MB_ICONINFORMATION);
if (iMB == IDNO) return 0; /* Abort and continue. */
/* Clear all game progress and return to menu. */
g_GameData.StartOver(false); // Not starting over.
g_GameData.ResetLevel(); // Reset game level.
g_GameData.ResetScores(); // Reset all player scores.
g_GameData.ResetLives(); // Reset player lives.
g_bQuitToMenu = true; // Stop game and return to menu.
}
if (wParam == 13) // Enter key.
{ // Player wants to pause the game.
MessageBox(hWnd,"The game is paused! Click OK to continue.",
"Squibbles",MB_ICONINFORMATION);
return 0;
}
break;
case WM_SYSCOMMAND:
/* If window is commanded to close, post a WM_QUIT message and veto
the quit! */
if ((wParam & 0xFFF0) == SC_CLOSE) { PostQuitMessage(0); return 0; }
default: /* For messages that are not handled. */
return DefWindowProc(hWnd,Message,wParam,lParam);
}
return 0;
}
|