1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
//initiating the menu state of the game
void Game::initMenu(unsigned int &bgImage){
//srand(time(0));
bgImage = CreateSprite("./images/GundamBG.png", iScreenWidth, iScreenHeight, true); //image for the background
MoveSprite(bgImage, iScreenWidth>>1, iScreenHeight>>1);//playGameButton.sprite = CreateSprite("./images/TrialPlayGameButton.png", 200, 50, true); //image for the clickable play button
//exitGameButton.sprite = CreateSprite("./images/TrialExitGameButton.png", 200, 50, true); //image for the clickable exit game button
//mouse.sprite = CreateSprite("./images/crate_sideup.png", mouse.position.x, mouse.position.y, true); //image for the cursor
}
//drawing the menu state
void Game::drawMenu(unsigned int &bgImage){
DrawSprite(bgImage); //calling the background image to the screen that was initialised earlier
DrawString("Press SPACE key to PLAY", 0, 360); //calling the play game button to the screen
DrawString("Press 'Esc' key to Exit", 0, 400);//calling the exit game button to the screen
DrawString("Press the 'Backspace' key to return to menu", 0, 440);
DrawString("Controls: W, A, S, D to move around", 0, 480);
DrawString("To shoot: Press SPACE bar", 0, 525);
}
//updating the menu to check for user input
void Game::updateMenu(unsigned int &bgImage, GameMenu &Menu){
if(IsKeyDown(KEY_SPACE))
{
Menu.playGame = true;
Menu.gamePause = false;
Menu.gameOver = false;
Menu.escape = false;
}
else if (IsKeyDown (KEY_ESC))
{
Menu.escape = true;
Menu.playGame = false;
}
}
//initiating the variables needed to start the game
void Game::initGame(unsigned int &bgImage, Sprite::MovableObject &bullets, Sprite::MovableObject &playerOne, Sprite::MovableObject &enemy){
//srand(time(0));
bgImage = CreateSprite("./images/carbonfiber.png", iScreenWidth, iScreenHeight, true);//draw bgImage
MoveSprite(bgImage, iScreenWidth>>1, iScreenHeight>>1);
playerOne.sprite = CreateSprite("./images/ship.png", playerOneW, playerOneH, true);//player
MoveSprite(playerOne.sprite, iScreenWidth/2, iScreenHeight/2);
enemy.sprite = CreateSprite("./images/crate_sideup.png", enemyW, enemyH, true);//enemies
bullets.sprite = CreateSprite("./images/bullet.png", bulletsW, bulletsH, true);//bullets
}
//destroying the sprites in order to end the game
void Game::destroyGame(unsigned int &bgImage, Sprite::MovableObject &bullets, Sprite::MovableObject &playerOne, Sprite::MovableObject &enemy){
DestroySprite(bgImage);//bgImage
DestroySprite(playerOne.sprite);//player
DestroySprite(enemy.sprite);//enemies
DestroySprite(bullets.sprite);//bullets
}
//keeping track of player score
//void gameScore(){
// if (enemyDied == true){//small enemies 100pts
// playerOneScore += 100;
// }
//medium enemies 200pts
//big enemies 400pts
// //boss' 800pts
//}
//keys used to control playerOne
void Game::move(Sprite::MovableObject &playerOne, Sprite::MovableObject &bullets, Shoot &fire) {
if(IsKeyDown('W') && playerOne.position.y > playerOne.height/2){//put switch case statement for the player to choose whether they want
playerOne.position.y -= 2;
playerOne.speed.y = 2;
}
else if(IsKeyDown('D') && playerOne.position.x < iScreenWidth - (playerOne.width/2)){
playerOne.position.x += 2;
playerOne.speed.x = 2;
}
else if(IsKeyDown ('S') && playerOne.position.y < iScreenHeight - (playerOne.height/2)){
playerOne.position.y += 2;
playerOne.speed.y = 2;
}
else if(IsKeyDown ('A') && playerOne.position.x > playerOne.width/2){
playerOne.position.x -= 2;
playerOne.speed.x = 2;
}
else if(IsKeyDown(KEY_SPACE)&& (bullets.position.x && bullets.position.y > iScreenHeight)){
DrawSprite(bullets.sprite);
fire.shoot = true;
fire.playerShoot = true;
bullets.speed.x = playerOne.position.x; bullets.speed.y = playerOne.position.y;
bullets.position.x = playerOne.position.x; bullets.position.y = playerOne.position.y;
}
}
void Game::shoot(Sprite::MovableObject &enemy, Sprite::MovableObject &playerOne, Sprite::MovableObject &bullets, Shoot &fire){
if(bullets.position.x && bullets.position.y > iScreenHeight)
{
fire.shoot = true;
}
else if (bullets.position.x && bullets.position.y < iScreenHeight)
{
fire.shoot = false;
}
}
//updates game to check for player position/enemy position and score
void Game::updateGame(unsigned int &bgImage, GameMenu &Menu, Sprite::MovableObject &playerOne, Sprite::MovableObject &enemy, Sprite::MovableObject &bullets, Shoot &fire){
move(playerOne, bullets, fire); //player position on screen
//seek(enemy);//enemies
//score
if(Menu.gameOver == false)
{
if(IsKeyDown (KEY_BACKSPACE))
{
Menu.playGame = false;
}
else if(playerOneDied == true)
{
Menu.gameOver = true;
}
MoveSprite(playerOne.sprite, playerOne.position.x, playerOne.position.y);
MoveSprite(enemy.sprite, enemy.position.x, enemy.position.y);
}
}
//drawing the initialized variables to the screen
void Game::drawGame(unsigned int &bgImage, GameMenu &Menu, Sprite::MovableObject &bullets, Sprite::MovableObject &playerOne, Sprite::MovableObject &enemy)
{
//static char outscore1[] = {'\n'};
DrawSprite(bgImage); //draw player, enemies, bullets, bgImage
MoveSprite(bgImage, iScreenWidth>>1, iScreenHeight>>1);
DrawSprite(playerOne.sprite);
DrawSprite(enemy.sprite);
DrawSprite(bullets.sprite);
if(Menu.gameOver == true)
{
DrawString("Game Over" , iScreenWidth/2, 300);
}
//sprintf_s(outScore1, "Player 1: %d", playerOneScore);
//DrawString(outScore1, 50 , 50, SColour(255, 0, 0, 255));
}
|