/*
Name : Road Warriors, a modified 3d frogger game
Author : James Macleod
*/
// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
#include <string.h>
// constant declarations
// background colour
const DWORD sky = dbRGB(150,150,255);
const DWORD white = dbRGB(255,255,255);
const DWORD red = dbRGB(255,0,0);
const DWORD green = dbRGB(0,255,0);
const DWORD black = dbRGB(0,0,0);
//Matrix constants
const int TheGround = 1;
const int width = 2000;
const int depth = 2000;
const int height = 50;
//images
const int scroll = 1;
const int grass = 2;
const int street = 3;
const int hole = 4;
const int menuScreen = 5;
//object constants
const int skybox = 3;
const int road = 4;
const int pavement = 5;
const int cone1 = 6;
const int cone2 = 7;
const int cone3 = 8;
const int home1 = 20;
const int home2 = 21;
const int home3 = 22;
const int homeA = 101;
const int homeB = 102;
const int homeC = 103;
const int wall1 = 104;
const int wall2 = 105;
const int wall3 = 106;
const int wall4 = 107;
const int player = 108;
const int Cam = 120;
//Global variables
int CarA = 10;
int CarB = 16;
int CarC = 20;
int CarD = 24;
//high score constants
const int NoScores = 5;
const int MaxStrSize = 30;
const int LineHeight = 20;
const int SaveFile = 1;
//default values for name and scores
const char DefaultNames[NoScores][MaxStrSize] = {"Simple Jack","Sgt.Doakes","Forrest Gump","Pvt.Piles","Mjr.Payne"};
const int DefaultScores[NoScores] = {400,100,50,1000,725};
//Movement constants
const int StartXR = 1300;
const int EndXL = 700;
const int StartXL = 700;
const int EndXR = 1300;
const int LaneAZ = 425;
const int LaneBZ = 475;
const int LaneCZ = 525;
const int LaneDZ = 575;
//home bools
bool homeAsafe = false;
bool homeBsafe = false;
bool homeCsafe = false;
bool gamestate = false;
//function prototypes
void SetUpScreen();
void LoadImages();
void CreateMatrix();
void LoadObjects(int,int,int);
void LaneA();
void LaneB();
void LaneC();
void LaneD();
void LoadBuildings();
void ControlPlayer(float &playerX, float &playerZ, float &playerAng, int playerSpeed,int &life,int &StartTime, int &Score);
void PlayGame(float &playerX, float &playerZ, float &playerAng,int playerSpeed,int &life,int &StartTime, int &Score);
void updatelives(int &life, int &StartTime,int &Score);
void ResetTimer(int &StartTime);
void UpdateScore(int &StartTime, int &Score);
void ResetGame();
void AddBonus(int &Score);
//function prototypes for highscore table
void DisplayScores (int , int &, int [NoScores], char [NoScores][MaxStrSize]);
void BubbleSort (int , int &, int [NoScores], char [NoScores][MaxStrSize]);
void LoadHighScores (int scores[NoScores], char names[NoScores][MaxStrSize]);
void SaveHighScores (int scores[NoScores], char names[NoScores][MaxStrSize]);
// the main entry point for the application
void DarkGDK ( void )
{
//variables for controlled character
float playerAng = 1;
float playerX = 1000;
float playerY = 10;
float playerZ = 350;
int playerSpeed = 2;
int life = 3;
int Score = 0;
int choice = 9;
int StartTime;
//declare a 2d char array to hold name strings
char names [NoScores][MaxStrSize];
// int array to hold scores
int scores [NoScores];
//text display variables
int ypos = 20, xpos = 20;
char playerName [MaxStrSize];
int PlayerScore = 0;
//Load data from file if it exists or load default values
LoadHighScores(scores, names);
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );
dbSetDisplayMode(1024,768,32);
dbMaximizeWindow ();
dbSetWindowPosition(10,10);
dbSync();
dbBackdropOff();
dbColorBackdrop(0);
do//start a loop that will keep the game running by returning to the main menu until menu choice is equal to zero
{
//gamestate = false;
homeAsafe = false;
homeBsafe = false;
homeCsafe = false;
Score = 0;
choice = 0;
life = 3;
ypos = 20;
xpos = 20;
dbInk(black,0);
// load the image for the title screen
dbLoadImage ( "menuScreen.jpg", menuScreen );
dbLoadImage ( "scroll.jpg", scroll );
// paste title screen
dbPasteImage(menuScreen, -110, 0);
//accept choice from user
choice = atoi( dbInput() );
switch (choice)
{
case 1:
dbCLS();
// paste intro screen
dbPasteImage(scroll, 130, 0);
dbSync();
dbWaitKey();
// remove images and sprites used for the title screen
dbDeleteImage(scroll);
//load and play the game
PlayGame(playerX,playerZ,playerAng,playerSpeed,life,StartTime,Score);
//delete all game images and objects
ResetGame();
//Set text type
dbSetTextFont("Aerial");
//set text size and colour
dbSetTextSize(20);
dbInk(white,0);
//get username and score
dbCLS();
dbPrint("Enter name");
//error checking to be added for names longer than char string size
strcpy_s(playerName, dbInput());
//dbPrint("Enter your score");
PlayerScore=Score;
//check if player score is bigger than the last entry in array
if(PlayerScore>scores[NoScores-1])
{
scores[NoScores-1] = PlayerScore;
strcpy_s(names [NoScores-1], playerName);
//resort array
BubbleSort(xpos, ypos, scores, names);
}//end if
SaveHighScores(scores, names);
dbCLS();
BubbleSort(xpos, ypos, scores, names);
DisplayScores(xpos, ypos, scores, names);
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2, "Press a key to continue...");
dbSync();
dbWaitKey();
break;
case 2:
//Set text type
dbSetTextFont("Aerial");
//set text size and colour
dbSetTextSize(20);
dbInk(white,0);
dbCLS();
BubbleSort(xpos, ypos, scores, names);
DisplayScores(xpos, ypos, scores, names);
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2, "Press a key to continue...");
dbSync();
dbWaitKey();
break;
case 3:
gamestate = true;
//exit the program and return to windows
break;
}//end switch
}while(gamestate!=true);
// return back to windows
return;
}//end function DarkGDK
void PlayGame(float &playerX, float &playerZ, float &playerAng,int playerSpeed,int &life,int &StartTime, int &Score)
{
// remove images and sprites used for the title screen
dbDeleteImage(menuScreen);
//call our user defined functions
SetUpScreen();
LoadImages();
CreateMatrix();
LoadObjects(playerX,playerAng,playerZ);
//create traffic lanes
LaneA();
LaneB();
LaneC();
LaneD();
//load the buildings to the screen
LoadBuildings();
//make and set initial camera position
dbMakeCamera(Cam);
dbPositionCamera(Cam,width/2,height,300);
dbPointCamera(Cam,1000,0,500);
dbSync();
//make the clock start at zero
StartTime = dbTimer();
// our main game loop
while(life>0)
{
//slowly rotate the sky
dbYRotateObject(skybox,dbObjectAngleY(skybox)+0.05);
ControlPlayer(playerX,playerZ,playerAng,playerSpeed,life,StartTime,Score);
//Set text type
dbSetTextFont("Aerial");
//set text size and colour
dbSetTextSize(20);
dbInk(white,0);
//display text to screen showing time score and lives
dbText(10,10,"Time : ");
dbText(60,10,dbStr((dbTimer()-StartTime)/1000));
dbText(450,10,"Score : ");
dbText(510,10,dbStr(Score));
dbText(900,10,"Lives : ");
dbText(950,10,dbStr(life));
//check the safe zones and set to true if player reaches home then display text to show home is occupied
if(homeAsafe == true)
{
//Set text type
dbSetTextFont("Papyrus");
dbInk(red,0);
dbText(495,265,"FULL");
}//end if
if(homeBsafe == true)
{
//Set text type
dbSetTextFont("Papyrus");
dbInk(red,0);
dbText(255,265,"FULL");
}//end if
if(homeCsafe == true)
{
//Set text type
dbSetTextFont("Papyrus");
dbInk(red,0);
dbText(720,265,"FULL");
}//end if
//if the clock gets to 30 seconds then update lives as life lost then reset timer and set score
if (((dbTimer()-StartTime)/1000)>=30)
{
updatelives( life, StartTime, Score);
}//end if
// update the screen
dbSync();
//loop the traffic for the four lanes
for (CarA=10;CarA<16;CarA++)
{
dbMoveObject(CarA,-0.5);
if(dbObjectPositionX(CarA)<700)
{
dbPositionObject(CarA,StartXR,1,LaneAZ);
}//end if
}//end for
for (CarB=16;CarB<20;CarB++)
{
dbMoveObject(CarB,-1);
if(dbObjectPositionX(CarB)>1300)
{
dbPositionObject(CarB,StartXL,1,LaneBZ);
}//end if
}//end for
for (CarC=20;CarC<24;CarC++)
{
dbMoveObject(CarC,-1);
if(dbObjectPositionX(CarC)<700)
{
dbPositionObject(CarC,StartXR,1,LaneCZ);
}//end if
}//end for
for (CarD=24;CarD<30;CarD++)
{
dbMoveObject(CarD,-0.5);
if(dbObjectPositionX(CarD)>1300)
{
dbPositionObject(CarD,StartXL,1,LaneDZ);
}//end if
}//end for
//if player gets all 3 home then end game
if((homeAsafe == true)&&(homeBsafe == true)&&(homeCsafe == true))
{
//update score with bonus for getting all players home
AddBonus(Score);
//Set text type
dbSetTextFont("Papyrus");
//set text size
dbSetTextSize(100);
dbInk(green,0);
//display message to screen
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2,"Congratulations Soldier !!!");
dbText(150,20,"Score : ");
dbText(400,20,dbStr(Score));
dbSync();
dbWaitKey();
ResetGame();
life = 0;
}//end if
}//end while
}//end function playgame
//====================================
//* Function declarations *
//====================================
void SetUpScreen()
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn();
dbSyncRate(60);
dbSetDisplayMode(1024,768,32);
dbSetWindowPosition(10,10);
//display loading message
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2, "Loading scene...");
dbSync();
dbBackdropOn();
dbColorBackdrop(sky);
}//end function SetUpScreen
void LoadImages()
{
//load images
dbLoadImage("grass36.jpg",grass);
dbLoadImage("road.dds",street);
dbLoadImage("dark01.bmp",hole);
}//end function LoadImages
void CreateMatrix()
{
//make matrix 2000*2000 pixels, and 20 * 20 tiles
dbMakeMatrix(TheGround,width,depth,50,50);
//texture with grass
dbPrepareMatrixTexture(TheGround,grass,1,1);
dbSetMatrix(TheGround,0,0,1,2,1,0,1);
dbPositionMatrix(TheGround,0,0,0);
dbUpdateMatrix(TheGround);
}//end function creatematrix
void LoadObjects(int playerX,int playerY, int playerZ)
{
//ambient light affects the amount of shadowing on 3d objects
dbSetAmbientLight(30);
//create and load Character
dbLoadObject("USA\\H-USA-Move.x",player);
dbPositionObject(player,playerX,playerY,playerZ);
dbScaleObject(player,750,750,750);
dbYRotateObject(player,180);
dbLoopObject(player);
dbSetObjectSpeed(player,10);
dbFixObjectPivot (player);
//create a road
dbMakeObjectBox(road,1000,1,200);
dbTextureObject(road,street);
dbScaleObjectTexture(road,10,2);
dbPositionObject(road,1000,0.5,500);
dbSetObjectAmbient(road,1);
//create pavement
dbMakeObjectBox(pavement,1000,1,100);
dbPositionObject(pavement,1000,0.5,650);
dbTextureObject(pavement,hole);
dbScaleObjectTexture(pavement,10,1);
//add a skybox
dbLoadObject("sky05\\sky05.x",skybox);
dbPositionObject(skybox,1000,0,1000);
dbScaleObject(skybox,9000,9000,9000);
dbSetObjectTexture(skybox,2,0);
//stop the skybox from automatic collision
dbSetObjectCollisionOff(skybox);
dbSetObjectAmbient(skybox,0);
}//end function loadobjects
void LaneA()
{
//local varibles
int space=100;
int newX;
//create Cars for laneA
for (CarA=10;CarA<14;CarA++)
{
dbLoadObject("Car\\Tank\\H-Tank.x",CarA);
if(CarA==10)
{
dbPositionObject(CarA,StartXR,1,LaneAZ);
}
else
{
dbRandomize(dbTimer());
space=85+dbRND(50);
newX=dbObjectPositionX(CarA-1)+space;
dbPositionObject(CarA,newX,1,LaneAZ);
}
dbScaleObject(CarA,500,500,500);
dbYRotateObject(CarA,90);
dbSetObjectSpeed(CarA,40);
dbLoopObject(CarA,5);
}//end for
}//end function laneA
void LaneB()
{
int space=200;
int newX;
//create Cars for laneB
for (CarB=16;CarB<20;CarB++)
{
dbLoadObject("Car\\damaged_tank\\damaged_tank.x",CarB);
if(CarB==16)
{
dbPositionObject(CarB,StartXL,1,LaneBZ);
}
else
{
dbRandomize(dbTimer());
space=200+dbRND(60);
newX=dbObjectPositionX(CarB-1)+space;
dbPositionObject(CarB,newX,1,LaneBZ);
}
dbScaleObject(CarB,18,18,18);
dbYRotateObject(CarB,270);
dbSetObjectSpeed(CarB,200);
dbLoopObject(CarB,100,180);
}//end for
}//end function laneB
void LaneC()
{
int space=200;
int newX;
//create Cars for laneC
for (CarC=20;CarC<24;CarC++)
{
dbLoadObject("Car\\Big 4x4\\L-Big 4x4-Move.x",CarC);
if(CarC==20)
{
dbPositionObject(CarC,StartXR,1,LaneCZ);
}
else
{
dbRandomize(dbTimer());
space=200+dbRND(60);
newX=dbObjectPositionX(CarC-1)-space;
dbPositionObject(CarC,newX,1,LaneCZ);
}
dbScaleObject(CarC,700,700,700);
dbYRotateObject(CarC,90);
dbLoopObject(CarC,100,180);
dbSetObjectSpeed(CarC,30);
}//end for
}//end function laneC
void LaneD()
{
int space=100;
int newX;
//create Cars for laneD
for (CarD=24;CarD<28;CarD++)
{
dbLoadObject("Car\\Tank 2\\H-Tank 2.x",CarD);
if(CarD==24)
{
dbPositionObject(CarD,StartXL,1,LaneDZ);
}
else
{
dbRandomize(dbTimer());
space=90+dbRND(50);
newX=dbObjectPositionX(CarD-1)-space;
dbPositionObject(CarD,newX,1,LaneDZ);
}
dbScaleObject(CarD,600,600,600);
dbYRotateObject(CarD,270);
dbLoopObject(CarD,100,180);
dbSetObjectSpeed(CarD,20);
}//end for
}//end function laneD
void LoadBuildings()
{
//load 3 buildings that represent the safe zones
dbLoadObject("buildings\\building2.x",homeA);
dbPositionObject(homeA,1000,0,640);
dbScaleObject(homeA,25,25,25);
dbYRotateObject(homeA,180);
dbLoadObject("buildings\\building2.x",homeB);
dbPositionObject(homeB,890,0,640);
dbScaleObject(homeB,25,25,25);
dbYRotateObject(homeB,180);
dbLoadObject("buildings\\building2.x",homeC);
dbPositionObject(homeC,1105,0,640);
dbScaleObject(homeC,25,25,25);
dbYRotateObject(homeC,180);
//load buildings for the scene
dbLoadObject("Car\\Tank\\H-Tank.x",wall1);
dbPositionObject(wall1,945,0,650);
dbScaleObject(wall1,1000,1000,1000);
dbLoadObject("buildings\\building14.x",wall2);
dbPositionObject(wall2,780,0,660);
dbScaleObject(wall2,25,25,25);
dbYRotateObject(wall2,180);
dbLoadObject("Car\\Tank\\H-Tank.x",wall3);
dbPositionObject(wall3,1055,0,650);
dbScaleObject(wall3,1000,1000,1000);
dbLoadObject("buildings\\building14.x",wall4);
dbPositionObject(wall4,1215,0,660);
dbScaleObject(wall4,25,25,25);
dbYRotateObject(wall4,180);
}//end function load buildings
void ControlPlayer(float &playerX, float &playerZ, float &playerAng, int playerSpeed,int &life , int &StartTime, int &Score)
{
//local varibles so the players movement can be updated
int OldplayerX = playerX;
int OldplayerZ = playerZ;
//Use arrow keys to control character
if (dbUpKey()==1)
{
playerX = dbNewXValue(playerX, playerAng, playerSpeed/2);
playerZ = dbNewZValue(playerZ, playerAng, playerSpeed/2);
dbYRotateObject(player, 0);
}//end if
if (dbDownKey()==1)
{
playerX = dbNewXValue(playerX, playerAng, playerSpeed*-1/2);
playerZ = dbNewZValue(playerZ, playerAng, playerSpeed*-1/2);
dbYRotateObject(player, 180);
}//end if
if (dbLeftKey()==1)
{
playerX-=0.5;
dbYRotateObject(player, 270);
}//end if
if (dbRightKey()==1)
{
playerX+=0.5;
dbYRotateObject(player, 90);
}//end if
dbPositionObject(player, playerX, playerAng, playerZ);
//set collision to make the game work as desired
dbSetObjectCollisionOff(pavement);
dbSetObjectCollisionOff(road);
dbSetObjectCollisionOn(wall1);
dbSetObjectCollisionOn(wall2);
dbSetObjectCollisionOn(wall3);
dbSetObjectCollisionOn(wall4);
dbSetObjectCollisionOn(player);
//check for the player getting to home A
if(dbObjectCollision(player,homeA))
{
//check if home A is full and lose a life
if(homeAsafe == true)
{
updatelives(life,StartTime, Score);
dbWaitKey();
playerX = 1000;
playerZ = 350;
//reset player to start position
dbPositionObject(player,playerX,2,playerZ);
}//end if
//if home A is empty then set to full
else if(homeAsafe == false)
{
//Set text type
dbSetTextFont("Papyrus");
//set text size
dbSetTextSize(100);
dbInk(green,0);
//display message to screen
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2,"Well Done !!!");
dbSync();
dbWaitKey();
//update score and reset timer
Score = Score + 50;
UpdateScore(StartTime,Score);
ResetTimer(StartTime);
playerX = 1000;
playerZ = 350;
//set home A to full
homeAsafe = true;
//reset player to start position
dbPositionObject(player,playerX,2,playerZ);
}//end if
}//end if
//check for the player getting to home B
if(dbObjectCollision(player,homeB))
{
//check if home B is full and lose a life
if(homeBsafe == true)
{
updatelives(life,StartTime, Score);
dbWaitKey();
playerX = 1000;
playerZ = 350;
//reset player to start position
dbPositionObject(player,playerX,2,playerZ);
}//end if
//if home B is empty then set to full
else if(homeBsafe == false)
{
//Set text type
dbSetTextFont("Papyrus");
//set text size
dbSetTextSize(100);
dbInk(green,0);
//display message to screen
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2,"Well Done !!!");
dbSync();
dbWaitKey();
//update score and reset timer
Score = Score + 150;
UpdateScore(StartTime,Score);
ResetTimer(StartTime);
playerX = 1000;
playerZ = 350;
//set home B to full
homeBsafe = true;
//reset player to start position
dbPositionObject(player,playerX,2,playerZ);
}//end if
}//end if
//check for the player getting to home C
if(dbObjectCollision(player,homeC))
{
//check if home C is full and lose a life
if(homeCsafe == true)
{
updatelives(life,StartTime, Score);
dbWaitKey();
playerX = 1000;
playerZ = 350;
//reset player to start position
dbPositionObject(player,playerX,2,playerZ);
}//end if
//if home C is empty then set to full
else if(homeCsafe == false)
{
//Set text type
dbSetTextFont("Papyrus");
//set text size
dbSetTextSize(100);
dbInk(green,0);
//display message to screen
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2,"Well Done !!!");
dbSync();
dbWaitKey();
//update score and reset timer
Score = Score + 100;
UpdateScore(StartTime,Score);
ResetTimer(StartTime);
playerX = 1000;
playerZ = 350;
//set home C to full
homeCsafe = true;
//reset player to start position
dbPositionObject(player,playerX,2,playerZ);
}//end if
}//end if
//if player collides with any thing except the excluded objects then lose a life
else if(dbObjectCollision(player,0)>0)
{
updatelives(life,StartTime, Score);
dbWaitKey();
playerX = 1000;
playerZ = 350;
//reset player to start position
dbPositionObject(player,playerX,2,playerZ);
}//end if
}//end function control player
void updatelives(int &life, int &StartTime,int &Score)
{
life = life-1;
//Set text type
dbSetTextFont("Papyrus");
//set text size
dbSetTextSize(70);
dbInk(red,0);
//display text to let player know they died and lost a life
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2,"YOU LOST A LIFE...");
dbSync();
dbWaitKey();
//check the player has more than zero lives if not then display game over message
if(life<=0)
{
//Set text type
dbSetTextFont("Papyrus");
//set text size
dbSetTextSize(200);
dbInk(red,0);
dbCenterText(dbScreenWidth()/2,dbScreenHeight()/2,"GAME OVER !!!");
dbText(150,20,"Score : ");
dbText(400,20,dbStr(Score));
dbSync();
dbWaitKey();
}//end if
//reset timer
ResetTimer(StartTime);
}//end function update lives
void ResetTimer(int &StartTime)
{
//reset the timer to zero
StartTime = dbTimer();
}//end function reset timer
void UpdateScore(int &StartTime, int &Score)
{
//add the remaining time to the total score by taking remaining time from 100
Score = Score + 100;
Score = Score - (dbTimer()-StartTime)/1000;
}//end function update score
void ResetGame()
{
//delete all looped objects for lane 1
for(CarA=10;CarA<14;CarA++)
{
dbDeleteObject(CarA);
}//end for
//delete all looped objects for lane 2
for(CarB=16;CarB<20;CarB++)
{
dbDeleteObject(CarB);
}//end for
//delete all looped objects for lane 3
for(CarC=20;CarC<24;CarC++)
{
dbDeleteObject(CarC);
}//end for
//delete all looped objects for lane 4
for(CarD=24;CarD<28;CarD++)
{
dbDeleteObject(CarD);
}//end for
//delete camera, matrix and all game objects
dbDeleteCamera(Cam);
dbDeleteObject(homeA);
dbDeleteObject(homeB);
dbDeleteObject(homeC);
dbDeleteObject(homeA);
dbDeleteObject(wall1);
dbDeleteObject(wall2);
dbDeleteObject(wall3);
dbDeleteObject(wall4);
dbDeleteObject(player);
dbDeleteObject(road);
dbDeleteObject(pavement);
dbDeleteObject(skybox);
dbDeleteMatrix(TheGround);
dbBackdropOff();
dbCLS();
dbSync();
}//end function reset game
void AddBonus(int &Score)
{
//add 1000 points to score
Score = Score + 1000;
}//end function add bonus score
void DisplayScores(int xpos, int &ypos, int scores[NoScores], char names[NoScores][MaxStrSize])
{
//display arrays to screen
for (int index=0;index<NoScores;index++)
{
ypos+=LineHeight;
dbText(xpos, ypos, names[index]);
dbText(xpos+120, ypos, dbStr(scores[index]));
}
ypos+=LineHeight;
}//end function DisplayScores
void BubbleSort(int xpos, int &ypos, int scores[NoScores], char names[NoScores][MaxStrSize])
{
//declare temp variables to store data being swapped
int tempNum;
char tempStr[MaxStrSize];
//flag, set to true to start the first pass
bool swapped=true;
//cycle through array till no more swaps
while (swapped==true)
{
swapped = false;
for (int i=0;i<(NoScores-1);i++)
{
if(scores[i+1]>scores[i])
{
//swap scores in number array
tempNum=scores[i];
scores[i]=scores[i+1];
scores[i+1]=tempNum;
swapped=true;
//swap strings in char array
strcpy(tempStr,names[i]);
strcpy(names[i],names[i+1]);
strcpy(names[i+1],tempStr);
}//end if
}//end for loop
}//end while
}//end function BubbleSort
void LoadHighScores(int scores[NoScores], char names[NoScores][MaxStrSize])
{
if(dbFileExist("GameSave.txt"))
{
//read from file to populate arrays then delete file
dbOpenToRead(SaveFile, "GameSave.txt");
for(int index=0; index<NoScores; index++)
{
strcpy_s(names[index], dbReadString(SaveFile));
scores[index]=dbReadFile(SaveFile);
}//end for loop
dbCloseFile(SaveFile);
dbDeleteFile("GameSave.txt");
}//end if
else
{
//load arrays with default values
for(int count=0; count<NoScores; count++)
{
strcpy_s(names[count], DefaultNames[count]);
scores[count]=DefaultScores[count];
}//end for loop
}//end else
}//end function LoadHighScores
void SaveHighScores(int scores[NoScores], char names[NoScores][MaxStrSize])
{
dbOpenToWrite(SaveFile,"GameSave.txt");
for (int count=0; count<NoScores; count++)
{
dbWriteString(SaveFile,names[count]);
dbWriteFile(SaveFile,scores[count]);
}//end for loop
dbCloseFile(SaveFile);
}//end function SaveHighScores
Ok people i am a total noob, this is my first try at making a 3d frogger type game, everything works great or atleast it did until i added the highscore functions, when i exit the program from the main menu i get an overrun error, after researching this for 2 weeks i thought i would ask, my game is good enough to hand in for my class as it meets all the requirement specs but for my own personal satisfaction i would like this error fixed or even understand it slightly better. Thanks for your time