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 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
|
#pragma comment(lib, "winmm.lib")
#include <string>
#include <cmath>
#include <Windows.h>
#include <time.h>
#include <assert.h>
#include <crtdbg.h>
#include <iostream>
#include "AIE.h"
#include "Player.h"
#include "Enemy.h"
#include "Bullets.h"
#include "Background.h"
#include "SBullet.h"
#define KEY_RETURN 294
#define KEY_UP 283
#define KEY_DOWN 284
struct Plane
{
//float XSpeed;
//float YSpeed;
float XPosition;
float YPosition;
float XMovementSpeed;
float YMovementSpeed;
float Width;
float Height;
};
Plane Plane1;
//create a player
Player player1;
Enemy enemy1;
Background Background1;
SBullet Bullet1;
//Game functions
void initGame();
void updateGame();
void drawGame();
void resetGame();
//menu functions
void updateMenu();
void drawMenu();
//Screen X and Y values
const int iScreenWidth = 1280;
const int iScreenHeight = 780;
//Max score
const int maxScore = 10;
//Menu items
bool StartGame ();
bool Readme ();
bool ExitGame ();
unsigned int iPlaneSprite = 0;
unsigned int iEnemySprite = 0;
unsigned int iBulletsSprite = 0;
unsigned int iBackgroundSprite = 0;
unsigned int Menu = 0;
unsigned int Instructions = 0;
//Declaring an enum for Game States
enum GameState
{
//Game states
MAIN_MENU,
HIGHSCORES,
GAME_STATE,
INSTRUCTIONS,
END
};
GameState eCurrentState = MAIN_MENU;
int main( int argc, char* argv[] )
{
srand( time(NULL) );
InitialiseBullets();
bool spacePressed = false;
unsigned int currentTime = timeGetTime();
unsigned int lastTime = currentTime;
float deltaTime = 0;
//initialise framework
Initialise( iScreenWidth, iScreenHeight, false );
//create game sprites
//Plane sprites
iPlaneSprite = CreateSprite( "./images/Phoenix.png", 96, 96, true );
iEnemySprite = CreateSprite( "./images/Viking.png", 96, 96, true );
iBulletsSprite = CreateSprite( "./images/crate_sideup.png", 32, 32, true );
iBackgroundSprite = CreateSprite( "./images/space_bg8574.png", 1280, 3600, true );
//Menu Sprites
Menu = CreateSprite( "./images/Menu.png", 1280, 780, true );
Instructions = CreateSprite( "./images/Instructions.png", 1280, 780, true );
//framework
do
{
ClearScreen();
switch(eCurrentState)
{
// if space is pressed, shoot from the center of the screen
if( IsKeyDown(' ') /*&& !spacePressed*/ )
{
float shootX = iScreenWidth / 2.0f;
float shootY = iScreenHeight / 2.0f;
// get the mouse pos
int mousePosX, mousePosY;
GetMouseLocation( mousePosX, mousePosY );
// calculate direction to the the mouse from the shoot pos
float dirToMouseX = mousePosX - shootX;
float dirToMouseY = mousePosY - shootY;
// normalise the direction
float len = sqrt( dirToMouseX*dirToMouseX + dirToMouseY*dirToMouseY );
dirToMouseX /= len;
dirToMouseY /= len;
// finally shoot
Shoot( shootX, shootY, dirToMouseX, dirToMouseY, 300.0f);
}
case MAIN_MENU:
updateMenu();
drawMenu();
break;
case GAME_STATE:
updateGame();
drawGame();
break;
case HIGHSCORES:
updateHighscores();
drawHighscores();
break;
case INSTRUCTIONS:
updateInstructions();
drawInstructions();
break;
}
UpdateBullets(deltaTime);
DrawBullets();
spacePressed = IsKeyDown( ' ' );
Sleep(1);
} while ( FrameworkUpdate() == false );
//Sprite destroys
DestroySprite(iPlaneSprite);
DestroySprite(iEnemySprite);
DestroySprite(iBulletsSprite);
DestroySprite(iBackgroundSprite);
DestroySprite(Instructions);
DestroySprite(Menu);
Shutdown();
return 0;
}
void initGame()
{
eCurrentState = GAME_STATE;
Background1.Init(iBackgroundSprite);
player1.Init(iPlaneSprite);
enemy1.Init(iEnemySprite);
}
void updateGame()
{
Background1.Update();
player1.Update();
enemy1.Update();
}
//Collision for plane!
void drawGame()
{
Background1.Draw();
player1.Draw();
enemy1.Draw();
}
//Game reset function
void resetGame()
{
Background1.Reset();
player1.Reset();
enemy1.Reset();
}
|