Permalink
Browse files

some renames

  • Loading branch information...
Dmytro Lytovchenko
Dmytro Lytovchenko committed Sep 28, 2011
1 parent 14d5bfa commit 9ad522d3d5c73f4612068b1e9d8d45b4e49804b3
Showing with 90 additions and 76 deletions.
  1. +56 −45 src/game.cpp
  2. +10 −8 src/game.h
  3. +24 −23 src/game_state.cpp
View
@@ -16,7 +16,7 @@
MyGame * MyGame::m_game = NULL;
-MyGame::MyGame() : hge(NULL), gui(NULL), fnt(NULL), spr(NULL)
+MyGame::MyGame() : m_hge(NULL), m_gui(NULL), m_font(NULL), spr(NULL)
{
// remember pointer to 'this' in globally visible variable so that everyone
// else can reach it (not very good example of software design, but this simplifies a lot)
@@ -30,97 +30,108 @@ bool MyGame::FrameFunc()
{
// passing control to the current game state, so that game reacts to events
// differently in different states
- return m_game->m_state->Think( m_game );
+ return m_game->m_state->Think( m_game );
+ // do not add more code here, all the action happens in GameState's child classes
}
bool MyGame::RenderFunc()
{
+ // letting the current game state to take care of rendering (different render for
+ // main menu, for game, and for game over screen)
m_game->m_state->Render( m_game );
+ // do not add more code here, all the action happens in GameState's child classes
return false;
}
bool MyGame::Startup()
{
- hge = hgeCreate(HGE_VERSION);
+ m_hge = hgeCreate(HGE_VERSION);
- hge->System_SetState(HGE_LOGFILE, "hge_tut06.log");
- hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
- hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
- hge->System_SetState(HGE_TITLE, "HGE Tutorial 06 - Creating menus");
- hge->System_SetState(HGE_WINDOWED, true);
- hge->System_SetState(HGE_SCREENWIDTH, 800);
- hge->System_SetState(HGE_SCREENHEIGHT, 600);
- hge->System_SetState(HGE_SCREENBPP, 32);
+ m_hge->System_SetState(HGE_LOGFILE, "hgeskel.log");
+ m_hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
+ m_hge->System_SetState(HGE_RENDERFUNC, RenderFunc);
+ m_hge->System_SetState(HGE_TITLE, "My Mighty Game of Doom!");
+ m_hge->System_SetState(HGE_WINDOWED, true);
+ m_hge->System_SetState(HGE_SCREENWIDTH, 800);
+ m_hge->System_SetState(HGE_SCREENHEIGHT, 600);
+ m_hge->System_SetState(HGE_SCREENBPP, 32);
- if( !hge->System_Initiate() ) return false;
+ if( !m_hge->System_Initiate() ) return false;
// Load sound and textures
- quad.tex=hge->Texture_Load("bg.png");
- tex=hge->Texture_Load("cursor.png");
- snd=hge->Effect_Load("menu.wav");
- if(!quad.tex || !tex || !snd)
+ m_background_quad.tex=m_hge->Texture_Load("bg.png");
+ m_menu_tex=m_hge->Texture_Load("cursor.png");
+ m_click_sound=m_hge->Effect_Load("menu.wav");
+ if(!m_background_quad.tex || !m_menu_tex || !m_click_sound)
{
// If one of the data files is not found, display
// an error message and shutdown.
MessageBox(NULL, "Can't load BG.PNG, CURSOR.PNG or MENU.WAV", "Error", MB_OK | MB_ICONERROR | MB_APPLMODAL);
- hge->System_Shutdown();
- hge->Release();
+ m_hge->System_Shutdown();
+ m_hge->Release();
return false;
}
// Set up the quad we will use for background animation
- quad.blend=BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE;
+ m_background_quad.blend=BLEND_ALPHABLEND | BLEND_COLORMUL | BLEND_NOZWRITE;
for(int i=0;i<4;i++)
{
// Set up z-coordinate of vertices
- quad.v[i].z=0.5f;
+ m_background_quad.v[i].z=0.5f;
// Set up color. The format of DWORD col is 0xAARRGGBB
- quad.v[i].col=ARGB(0xFF, 0xFF, 0xFF, 0xFF);
+ m_background_quad.v[i].col=ARGB(0xFF, 0xFF, 0xFF, 0xFF);
}
- quad.v[0].x=0; quad.v[0].y=0;
- quad.v[1].x=800; quad.v[1].y=0;
- quad.v[2].x=800; quad.v[2].y=600;
- quad.v[3].x=0; quad.v[3].y=600;
+ m_background_quad.v[0].x=0;
+ m_background_quad.v[0].y=0;
+
+ m_background_quad.v[1].x=800;
+ m_background_quad.v[1].y=0;
+
+ m_background_quad.v[2].x=800;
+ m_background_quad.v[2].y=600;
+
+ m_background_quad.v[3].x=0;
+ m_background_quad.v[3].y=600;
// Load the font, create the cursor sprite
- fnt=new hgeFont("font1.fnt");
- spr=new hgeSprite(tex,0,0,32,32);
+ m_font=new hgeFont("font1.fnt");
+ spr=new hgeSprite(m_menu_tex,0,0,32,32);
// Create and initialize the GUI
- gui=new hgeGUI();
+ m_gui=new hgeGUI();
- gui->AddCtrl(new hgeGUIMenuItem(1,fnt,snd,400,200,0.0f,"Play"));
- gui->AddCtrl(new hgeGUIMenuItem(2,fnt,snd,400,240,0.1f,"Options"));
- gui->AddCtrl(new hgeGUIMenuItem(3,fnt,snd,400,280,0.2f,"Instructions"));
- gui->AddCtrl(new hgeGUIMenuItem(4,fnt,snd,400,320,0.3f,"Credits"));
- gui->AddCtrl(new hgeGUIMenuItem(5,fnt,snd,400,360,0.4f,"Exit"));
+ m_gui->AddCtrl(new hgeGUIMenuItem(1,m_font,m_click_sound,400,200,0.0f,"Play"));
+ m_gui->AddCtrl(new hgeGUIMenuItem(2,m_font,m_click_sound,400,240,0.1f,"Options"));
+ m_gui->AddCtrl(new hgeGUIMenuItem(3,m_font,m_click_sound,400,280,0.2f,"Instructions"));
+ m_gui->AddCtrl(new hgeGUIMenuItem(4,m_font,m_click_sound,400,320,0.3f,"Credits"));
+ m_gui->AddCtrl(new hgeGUIMenuItem(5,m_font,m_click_sound,400,360,0.4f,"Exit"));
- gui->SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED);
- gui->SetCursor(spr);
- gui->SetFocus(1);
- gui->Enter();
+ m_gui->SetNavMode(HGEGUI_UPDOWN | HGEGUI_CYCLED);
+ m_gui->SetCursor(spr);
+ m_gui->SetFocus(1);
+ m_gui->Enter();
return true; // all is fine
}
void MyGame::Shutdown()
{
// Delete created objects and free loaded resources
- delete gui;
- delete fnt;
+ delete m_gui;
+ delete m_font;
delete spr;
- hge->Effect_Free(snd);
- hge->Texture_Free(tex);
- hge->Texture_Free(quad.tex);
+ m_hge->Effect_Free(m_click_sound);
+ m_hge->Texture_Free(m_menu_tex);
+ m_hge->Texture_Free(m_background_quad.tex);
// Clean up and shutdown
- hge->System_Shutdown();
- hge->Release();
+ m_hge->System_Shutdown();
+ m_hge->Release();
}
@@ -129,7 +140,7 @@ int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
MyGame game;
if( game.Startup() )
{
- game.hge->System_Start(); // Let's rock now!
+ game.m_hge->System_Start(); // Let's rock now!
game.Shutdown();
}
}
View
@@ -17,19 +17,21 @@ class MyGame
static MyGame * m_game;
// Pointer to the HGE interface.
// Helper classes require this to work.
- HGE * hge;
+ HGE * m_hge;
// Some resource handles
- HEFFECT snd;
- HTEXTURE tex;
- hgeQuad quad;
+ HEFFECT m_click_sound;
+ HTEXTURE m_menu_tex;
+
+ // menu background quad. As well we can use it for sky during the gameplay
+ hgeQuad m_background_quad;
// Pointers to the HGE objects we will use
- hgeGUI * gui;
- hgeFont * fnt;
- hgeSprite * spr;
+ hgeGUI * m_gui;
+ hgeFont * m_font;
+ hgeSprite * m_mouse_cursor_sprite;
- GameState * m_state;
+ GameState * m_state;
public:
MyGame();
View
@@ -10,37 +10,38 @@
// This should render main menu
void GameState_MainMenu::Render( MyGame * game )
{
- game->hge->Gfx_BeginScene();
- game->hge->Gfx_RenderQuad( &game->quad );
- game->gui->Render();
+ game->m_hge->Gfx_BeginScene();
+ game->m_hge->Gfx_RenderQuad( &game->m_background_quad );
+ game->m_gui->Render();
// Draw framerate and time since previous frame
- game->fnt->SetColor(0xFFFFFFFF);
- game->fnt->printf(5, 5, HGETEXT_LEFT, "dt:%.3f\nFPS:%d",
- game->hge->Timer_GetDelta(),
- game->hge->Timer_GetFPS());
+ game->m_font->SetColor(0xFFFFFFFF);
- game->hge->Gfx_EndScene();
+ game->m_font->printf( 5, 5, HGETEXT_LEFT, "dt:%.3f\nFPS:%d",
+ game->m_hge->Timer_GetDelta(),
+ game->m_hge->Timer_GetFPS() );
+
+ game->m_hge->Gfx_EndScene();
}
bool GameState_MainMenu::Think( MyGame * game )
{
- float dt = game->hge->Timer_GetDelta();
+ float dt = game->m_hge->Timer_GetDelta();
static float t = 0.0f;
float tx, ty;
int id;
static int lastid = 0;
// If ESCAPE was pressed, tell the GUI to finish
- if (game->hge->Input_GetKeyState(HGEK_ESCAPE)) {
+ if (game->m_hge->Input_GetKeyState(HGEK_ESCAPE)) {
lastid = 5;
- game->gui->Leave();
+ game->m_gui->Leave();
}
// We update the GUI and take an action if
// one of the menu items was selected
- id = game->gui->Update(dt);
+ id = game->m_gui->Update(dt);
if(id == -1)
{
switch(lastid)
@@ -49,33 +50,33 @@ bool GameState_MainMenu::Think( MyGame * game )
case 2:
case 3:
case 4:
- game->gui->SetFocus(1);
- game->gui->Enter();
+ game->m_gui->SetFocus(1);
+ game->m_gui->Enter();
break;
case 5: return true;
}
} else if(id) {
lastid = id;
- game->gui->Leave();
+ game->m_gui->Leave();
}
// Here we update our background animation
t += dt;
tx = 50*cosf(t/60);
ty = 50*sinf(t/60);
- game->quad.v[0].tx=tx;
- game->quad.v[0].ty=ty;
+ game->m_background_quad.v[0].tx=tx;
+ game->m_background_quad.v[0].ty=ty;
- game->quad.v[1].tx=tx+800/64;
- game->quad.v[1].ty=ty;
+ game->m_background_quad.v[1].tx=tx+800/64;
+ game->m_background_quad.v[1].ty=ty;
- game->quad.v[2].tx=tx+800/64;
- game->quad.v[2].ty=ty+600/64;
+ game->m_background_quad.v[2].tx=tx+800/64;
+ game->m_background_quad.v[2].ty=ty+600/64;
- game->quad.v[3].tx=tx;
- game->quad.v[3].ty=ty+600/64;
+ game->m_background_quad.v[3].tx=tx;
+ game->m_background_quad.v[3].ty=ty+600/64;
return false;
}

0 comments on commit 9ad522d

Please sign in to comment.