Code:
GameFramework AdventureGame(0); //You must create a new instance of the game for every new game.
CreateNewScreenItem RABBIT(0,-1 ,8 ,1); //When a new character or baddie is needed.
CreateNewScreenItem SNAIL (0,1,23,0);
CreateNewScreenItem GEARBOX (-1,-1,2,0);
CreateNewScreenItem GEARBOX1 (20,-1,2,0);
CreateNewScreenItem GEARBOX2 (20,-1,2,0);
CreateNewScreenItem GEARBOX3 (20,-1,2,0);
CreateNewScreenItem GEARBOX4 (20,-1,2,0);
CreateNewScreenItem GEARBOX5 (20,-1,2,0);
CreateNewScreenItem GEARBOX6 (20,-1,2,0);
//main entry point for your program
int APIENTRY WinMain(HINSTANCE Now,HINSTANCE,LPSTR ,int)
{
AdventureGame.StartGame(Now); //starts game loop
AdventureGame.PlayMusic(L"be.mid",true); //plays midi files for music.
if(AdventureGame.Running()) // game loop just include.
return true;
else
return false;
}
// use this function for loading in graphics, BMP's, PNG's or JPEG's.
// each image displayed on the screen needs graphic images to be loaded in,
// you can load:
// a single image
// an image for each direction.
//2,3 or 4 images for each direction for simple animation.
void GameFramework::LoadGameGraphics()
{
RABBIT.LoadImages("Graphics/Rabbit/playerl1.png","Graphics/Rabbit/playerl2.png",
"Graphics/Rabbit/playerr1.png","Graphics/Rabbit/playerr2.png",
"Graphics/Rabbit/playerb1.png","Graphics/Rabbit/playerb2.png",
"Graphics/Rabbit/playerf1.png","Graphics/Rabbit/playerf2.png");
SNAIL.LoadImage("Graphics/Snail/snailf1.png");
GEARBOX.LoadImage("Graphics/Gearbox/cars-gear-stick-prev.png");
GEARBOX1.LoadImage("Graphics/Gearbox/cars-gear-stick-1.png");
GEARBOX2.LoadImage("Graphics/Gearbox/cars-gear-stick-2.png");
GEARBOX3.LoadImage("Graphics/Gearbox/cars-gear-stick-3.png");
GEARBOX4.LoadImage("Graphics/Gearbox/cars-gear-stick-4.png");
GEARBOX5.LoadImage("Graphics/Gearbox/cars-gear-stick-5.png");
GEARBOX6.LoadImage("Graphics/Gearbox/cars-gear-stick-6.png");
AdventureGame.LoadBackgroundImage("Graphics/Screens/SplashScreen.jpg",splash_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/Options.jpg",option_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/MainGame.jpg",main_game_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/GameOver.jpg",game_over_screen);
AdventureGame.LoadBackgroundImage("Graphics/Screens/HighScore.jpg",high_score_screen);
}
//use this function for displaying anything u want on the screen
void GameFramework::DisplayMainGame()
{
RABBIT.DisplayItem(); //display RABBIT
SNAIL.DisplayItem(); //dislays GHOST
GEARBOX.DisplayItem();
GEARBOX1.DisplayItem();
GEARBOX2.DisplayItem();
GEARBOX3.DisplayItem();
GEARBOX4.DisplayItem();
GEARBOX5.DisplayItem();
GEARBOX6.DisplayItem();
AdventureGame.DisplayScore(-15,-12); //Displays a score at the relevant x,y coordiantes.
}
//This section checks for keyboard, mouse or joystick input.
void GameFramework::MainGameInput()
{
if (AdventureGame.keypressed[DIK_SPACE] & 0x80)
//SPEEDDIAL.SetSpeed=0 etc
if (AdventureGame.keypressed[DIK_1] & 0x80)
GEARBOX.SetPositionX(20),
GEARBOX1.SetPositionX(-1),
GEARBOX2.SetPositionX(20),
GEARBOX3.SetPositionX(20),
GEARBOX4.SetPositionX(20),
GEARBOX5.SetPositionX(20),
GEARBOX6.SetPositionX(20);
if (AdventureGame.keypressed[DIK_2] & 0x80)
GEARBOX.SetPositionX(20),
GEARBOX1.SetPositionX(20),
GEARBOX2.SetPositionX(-1),
GEARBOX3.SetPositionX(20),
GEARBOX4.SetPositionX(20),
GEARBOX5.SetPositionX(20),
GEARBOX6.SetPositionX(20);
if (AdventureGame.keypressed[DIK_3] & 0x80)
GEARBOX.SetPositionX(20),
GEARBOX1.SetPositionX(20),
GEARBOX2.SetPositionX(20),
GEARBOX3.SetPositionX(-1),
GEARBOX4.SetPositionX(20),
GEARBOX5.SetPositionX(20),
GEARBOX6.SetPositionX(20);
if (AdventureGame.keypressed[DIK_4] & 0x80)
GEARBOX.SetPositionX(20),
GEARBOX1.SetPositionX(20),
GEARBOX2.SetPositionX(20),
GEARBOX3.SetPositionX(20),
GEARBOX4.SetPositionX(-1),
GEARBOX5.SetPositionX(20),
GEARBOX6.SetPositionX(20);
if (AdventureGame.keypressed[DIK_5] & 0x80)
GEARBOX.SetPositionX(20),
GEARBOX1.SetPositionX(20),
GEARBOX2.SetPositionX(20),
GEARBOX3.SetPositionX(20),
GEARBOX4.SetPositionX(20),
GEARBOX5.SetPositionX(-1),
GEARBOX6.SetPositionX(20);
if (AdventureGame.keypressed[DIK_6] & 0x80)
GEARBOX.SetPositionX(20),
GEARBOX1.SetPositionX(20),
GEARBOX2.SetPositionX(20),
GEARBOX3.SetPositionX(20),
GEARBOX4.SetPositionX(20),
GEARBOX5.SetPositionX(20),
GEARBOX6.SetPositionX(-1);
if (AdventureGame.keypressed[DIK_UP] & KEY_PRESSED_DOWN)
RABBIT.MoveUp();
if (AdventureGame.keypressed[DIK_DOWN] & KEY_PRESSED_DOWN)
RABBIT.MoveDown();
if (AdventureGame.keypressed[DIK_LEFT] & KEY_PRESSED_DOWN)
RABBIT.MoveLeft();
if (AdventureGame.keypressed[DIK_RIGHT] & KEY_PRESSED_DOWN)
RABBIT.MoveRight();
if (AdventureGame.keypressed[DIK_SPACE] & 0x80)
AdventureGame.changeStage();
/*********************************************/
/* Used if you have a joystick */
/* if your objects drift then you need to */
/* Calibrate teh joystick in windows */
/*********************************************/
if (AdventureGame.JoyPresent == true)
{
if (AdventureGame.joy_state.lX > 0)
RABBIT.MoveRight();
if (AdventureGame.joy_state.lX < 0)
RABBIT.MoveLeft();
if (AdventureGame.joy_state.lY < 0)
RABBIT.MoveUp();
if (AdventureGame.joy_state.lY > 0)
RABBIT.MoveDown();
}
if (AdventureGame.Collision(&SNAIL,&RABBIT)) //Simple collision detection pass both objects as a pointer
AdventureGame.IncreaseScore(); // true returned if the 2 objects collide.
}