Hey all,
im making a menu for a game that i made.
This is the code for the game:
#include "DarkGDK.h"
#include "dinput.h"
char XPos[30];
char YPos[30];
char lol[5];
bool debug = false;
bool showfps = false;
int level = 1;
int maxen = level * 2;
int speed = 1;
int score = 0;
int lvl1 = 10;
int lvl2 = 15;
int lvl3 = 20;
int lvl4 = 25;
int lvl5 = 34;
int lvl6 = 45;
int lvl7 = 68;
int player = 100;
bool shooting = false;
char score1[10];
char highscore[100];
bool bypassmenu = false;
void Menu()
{
dbSyncOn();
dbSyncRate(60);
if (bypassmenu == false)
{
dbSetDisplayMode(600, 400, 32);
int mx = dbMouseX();
int my = dbMouseY();
dbLoadImage("res//menu//bg.png", 500); // Menu Start at 500
dbSprite(500, 0, 0, 500);
bypassmenu = true;
while (!dbKeyState(57) || !dbEscapeKey() == 1)
{
if (dbKeyState(57))
{
DarkGDK();
}
if (dbEscapeKey() == 1)
{
break;
}
dbSync();
}
}
else
{
DarkGDK();
}
dbSync();
}
void GameOver()
{
if (dbFileExist("hg//highscore.txt"))
{
sprintf_s ( highscore, 20, "||Score: %d", score);
dbOpenToWrite ( 1, "hg//highscore.txt" ) ;
dbWriteString ( 1, highscore );
}
else
{
dbMakeFile("hg//highscore.txt");
sprintf_s ( highscore, 20, "||Score: %d", score);
dbOpenToWrite ( 1, "hg//highscore.txt" ) ;
dbWriteString ( 1, highscore );
}
return;
}
void load()
{
dbLoadImage("res//bg.png", 1);
dbLoadImage("res//p1.png", player);
dbLoadImage("res//water.png", 2);
dbLoadImage("res//mouse.png", 3);
//Sounds
dbLoadSound("res//sounds//bomb.wav", 1); //bomba
dbLoadSound("res//sounds//explosion.wav", 2); // explosao
dbLoadImage("res//bomb.png", 5);
// barcos
dbLoadImage("res//barco1.png", 4);
dbMakeFile("hg//highscore.txt");
dbMakeFile("cfg//cfg.dat");
dbMakeFile("cfg//island.idc");
}
void collision()
{
// Test
int BoatX = dbSpriteX(4);
int BombX = dbSpriteX(5);
int BombY = dbSpriteY(5);
if (BombX < 115 && BombY > 303)
{
dbDeleteSprite(4);
dbPlaySound(2);
dbDeleteSprite(5);
dbText(10, 70, "Lost");
dbText(10, 100, "Wait a few seconds to return Game");
score = 0;
}
if (BoatX <= 123)
{
dbDeleteSprite(4);
dbText(10, 70, "Lost");
dbText(10, 100, "Wait a few seconds to return Game");
score = 0;
}
//
if(dbSpriteCollision(5, 2))dbDeleteSprite(5);
}
void Spawn1()
{
dbSprite(4, 600, 434, 4);
}
void generate()
{
if (!dbSpriteExist(4))
{
Spawn1();
}
}
void display()
{
dbHideSprite(1);
dbPasteImage(1, 0, 0);
dbHideMouse();
dbSprite(3, dbMouseX() - 13, dbMouseY() - 13, 3); //change Mouse
sprintf_s ( score1, 20, "Score: %d", score);
dbText(10, 50, score1);
if (debug == true)
{
sprintf_s ( XPos, 20, "X: %d", dbSpriteX(3));
sprintf_s ( YPos, 20, "Y: %d", dbSpriteY(3));
dbText (10,10, XPos);
dbText (10,30, YPos);
}
if(showfps == true)
{
char fpsrate[20];
int fps = dbScreenFPS();
sprintf_s ( fpsrate, 20, "FPS: %d", fps);
dbText(10, 70, fpsrate);
}
}
void bomb()
{
dbMoveSprite(5, -6); //speed da bomba
dbRotateSprite(4, 90);
dbMoveSprite(4, -0.6 - score * 0.1 / 2);
dbRotateSprite(4, 0);
}
void input()
{
if(dbMouseClick() == 1 && shooting == false)
{
shooting = true;
int x = dbSpriteX(3);
int y = dbSpriteY(3);
int subir = 5;
dbPlaySound(1);
dbSprite(5, x, -20, 5);
}
if(dbKeyState(66) == 1) //F8
{
debug = true;
}
if(dbKeyState(67) == 1) // F9
{
debug = false;
}
if(dbKeyState(64) == 1) // F6 - FPS Rate
{
showfps = true;
}
if(dbKeyState(65) == 1) // F7 - FPS Rate
{
showfps = false;
}
}
void DarkGDK ( void )
{
dbSyncOn ( );
dbSyncRate ( 60 );
Menu();
load();
dbSprite(1, 0, 0, 1);
dbSprite(player, 0, 240, player);
dbSprite(2, 0, 460, 2); //water
Spawn1();
dbSetWindowTitle("Island Defender Client - Beta");
while ( LoopGDK ( ) )
{
if(dbSpriteCollision(5, 4))
{
dbDeleteSprite(5);
dbPlaySound(2);
dbDeleteSprite(4);
score = score + 4;
}
if(showfps == true)
{
char fpsrate[20];
sprintf_s ( fpsrate, 20, "FPS: %d", dbScreenFPS);
dbText(10, 70, fpsrate);
}
input();
display();
generate();
bomb();
collision();
if(!dbSpriteExist(5)) shooting = false;
if(dbEscapeKey() == 1)break;
dbSync ( );
}
return;
}
Ok the Part that im working on is the Menu void
void Menu()
{
dbSyncOn();
dbSyncRate(60);
if (bypassmenu == false)
{
dbSetDisplayMode(600, 400, 32);
int mx = dbMouseX();
int my = dbMouseY();
dbLoadImage("res//menu//bg.png", 500); // Menu Start at 500
dbSprite(500, 0, 0, 500);
bypassmenu = true;
while (!dbKeyState(57) || !dbEscapeKey() == 1)
{
if (dbKeyState(57))
{
DarkGDK();
}
if (dbEscapeKey() == 1)
{
break;
}
dbSync();
}
}
else
{
DarkGDK();
}
dbSync();
}
When i load the game, it loads the menu image saying Spacebar to start and ESC to quit, the ESC works but the space bar gives this error:
Unhandled exception at 0x0040100d in Island Defender.exe: 0xC00000FD: Stack overflow.
Then hitting Break:
No symbols are loaded for any call stack frame. The source code cannot be displayed.
I think what's wrong is the Call for the DarkGDK function to start the game but i dont know how to do it.. :S
Thanks a lot
Learning C++
VB6 Advanced: 4/5
VB.NET Advanced: 4/5