Hi, one or the other may have already read
this thread. One of the examples of WickedX has inspired me (Space Dodger). I have changed, replaced and added some graphics and have further developed the code. Now I want to share it with you.
Why do I post this here in this forum? Because I wrote the code with my own game engine. Which is DGDK compatible, as described in the above thread. However, I use some of the advanced functions of my engine so that it does not 'down' compatible.
here i will show you the main.cpp. the whole code you find in the download with all medias and executable.
/*
_______________________________________________________________________________
Project: Space Dodger
Created: January 25, 2012 by WickedX
Version: 1.0.0
By: WickedX Software extended by MadBit
Description: C++ (SilverGDK) by MadBit
source code.
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
*/
#include "DarkGDK.h"
#include "dodger.h"
// function prototypes in the main.cpp
void Initialize();
void LoadMedia();
// hold game-states.
EGameStates g_state;
// main-function
void DarkGDK ( void )
{
// global initialization for the game.
Initialize ( );
// set main-loop.
// if loop == true handle the game-states
bool loop = true;
while (loop)
{
// if the window is closed by the user, LoopGDK returns false and the
// main-loop is no longer running.
loop=LoopGDK();
// clear backbuffer.
dbCls();
// handle states
switch(g_state)
{
// g_state is MainMenu
case EGS_MainMenu:
// here we get the instance of the main-menu class and run the
// methode 'run()'.
// if the state is changed to another state, then release the
// class main-menu.
g_state = sdMenu::getInstance()->run();
if(g_state != EGS_MainMenu)
sdMenu::release();
break;
case EGS_Play:
// here we get the instance of the game-class and run the
// methode 'run()'.
// if the state is changed to another state, then release the
// game-class.
g_state = sdGame::getInstance()->run();
if(g_state != EGS_Play)
sdGame::release();
break;
case EGS_Control:
// TODO: equal to EGS_MainMenu and EGS_Play. create a class for
// display controls. run it, and release it by state changing.
break;
case EGS_QuitGame:
// you clicked 'quit the game'. you could still create a dialog,
// for asking if you really want to end the game.
loop = false;
break;
}
// show the FPS in the top-left corner.
dbText(0, DB_Dot(0, 0), dbStr(dbScreenFPS()));
// display all what you have done. ;)
dbSync ( );
};
// release the menu-class.
sdMenu::release();
// remove the font.
RemoveFontResource("earth.ttf");
return;
}
void Initialize ( )
{
// setup the window.
//dbSetWindowOff();
dbSetDisplayMode(640, 480, 32);
dbSetWindowLayout((EWS_Overlapped|EWS_Caption|EWS_SysMenu|EWS_Border), 1, 1);
dbSetWindowTitle("Dodger - Idea by WickedX (2012) extend by MadBit (2014)");
//dbSetImageColorKey(255, 0, 255);
// hide mousecursor.
dbHideMouse();
// set the working directory.
dbSetDir(".\\..\\media\\dodger\\");
// add a font to system fontresource.
AddFontResource("earth.ttf");
// global media.
LoadMedia();
// set the beginning state.
g_state = EGS_MainMenu;
// init the random seed with timer.
dbRandomize(dbTimer());
// for debug the sprite collision.
//dbDrawSpriteCollisionShapeOn();
// draw text with transparent background.
dbSetTextTransparent(0);
}
void LoadMedia ( )
{
// load font with facename. this is new, you load the font in its own
// id-system. So you can fast swap the fonts in the game. id 0 is reserved
// for system font. old dgdk style is possible.
// ( dbSetTextFont("earth"); dbSetTextSize(24); )
dbLoadFont("earth", 24, false, false, false, false, true, 0, FNT_EARTH);
// load the music globally
dbLoadMusic("media\\impatien.mid" , MSX_GAME);
dbLoadMusic("media\\music triumph loop.mp3" , MSX_MENU);
}
This is developed with win8 and vs2012 express and compiled with xp-toolset. So you need
microsofts redistributable. I've tested with win8, win7 and winxp in a virtualbox.
Hey, if you interested to play around with this example and my engine pm me please. I will give you the needed libs and includes.
here is a screen shot.