#ifndef GAME_H
#define GAME_H
#include "CPInit.h"
// standard libraries
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <string>
#include <cstring>
#include <sstream>
using namespace std;
#ifndef USE_SDL
//windows/directx headers
#include <windows.h>
#include <dinput.h>
#include "dxinput.h"
#else
// define HWND class for SDL
typedef unsigned short int HWND; // 4 bytes
#endif
// cross-plat library headers
#include "SDL/SDL.h"
#include "SDL/SDL_image.h"
#include "SDL/SDL_mixer.h"
#ifdef USE_SDL
#include "SDL/SDL_ttf.h"
#endif
// cross-plat interface headers
#include "CPGraphics.h"
#include "CPInput.h"
#include "CPSound.h"
#include "CPTimer.h"
// game headers
#include "csprite.h"
#include "cship.h"
#include "cguns.h"
#include "cdebris.h"
// for debug output
#include "debug.h"
//application title
#define APPTITLE "BugHunt 2942AD"
//screen setup
static int FULLSCREEN = 0; //0 = windowed, 1 = fullscreen
static int SCREEN_WIDTH = 1024; //1280 // 1024 // 800
static int SCREEN_HEIGHT = 768; // 960 // 768 // 600
#define FRAMES_PER_SECOND 30 // desired FPS cap
#define TILEWIDTH 64
#define TILEHEIGHT 64
#define MAPWIDTH 32 //24 //16
#define MAPHEIGHT 32 //64 //96
#define GAMEWORLDWIDTH 2048 //(TILEWIDTH * MAPWIDTH)
#define GAMEWORLDHEIGHT 2048 // (TILEHEIGHT * MAPHEIGHT)
// scrolling window size
#define WINDOWWIDTH (SCREEN_WIDTH / TILEWIDTH) * TILEWIDTH
#define WINDOWHEIGHT (SCREEN_HEIGHT / TILEHEIGHT) * TILEHEIGHT
// scroll buffer size
#define SCROLLBUFFERWIDTH (SCREEN_WIDTH + TILEWIDTH * 2)
#define SCROLLBUFFERHEIGHT (SCREEN_HEIGHT + TILEHEIGHT * 2)
// colors
const CPCOLOR CP_RED = CPCOLOR_ARGB( 255, 255, 120, 120 ); // R
const CPCOLOR CP_GREEN = CPCOLOR_ARGB( 255, 120, 255, 120 ); // G
const CPCOLOR CP_BLUE = CPCOLOR_ARGB( 255, 120, 120, 255 ); // B
const CPCOLOR CP_WHITE = CPCOLOR_ARGB( 255, 225, 225, 225 ); // WHITE-ISH
// player SHIP stats
static int START_energy = 30;
static int START_eRecharge = 25; // ticks per delay to recharge
static int START_Shields = 3;
static int START_Armor = 2;
static int START_Hull = 1;
static int START_shield_regen_delay = 50;
// DRONE stats
static int DRONE_maxSpd
= 1 + rand()% 4; // 1 - 4
static int DRONE_curSpd = DRONE_maxSpd;
static int DRONE_energy = 15;
static int DRONE_eRecharge = 30; // ticks per delay to recharge
static int DRONE_Shields = 0;
static int DRONE_Armor
= rand()%3 + 1; // 1-3
static int DRONE_Hull
= rand()%2 + 1; // 1-2
// BOSS stats
static int BOSS_ARMOR = 8; //(-1) per life lost, for max (-7) = 1
static int BOSS_HULL = 10; //(-1) per life lost, for max (-7) = 3
const int MAX_TOKENS = 99;
// functions to read tokens from config file
bool isLetter(int charValue);
bool isNumber(int charValue);
int getToken(string token);
void setToken(string token, string value);
bool load_Config(string filename);
// function to auto change views when collide with planets
void changeView(int docked_planet);
//function prototypes
int Game_Init(HWND);
void Game_Run(HWND);
void Game_End(HWND);
// dynamic scrolling map support functions
void UpdateScrollPosition();
void loadMaps(); // loads the static and moving object maps
void DrawSprites();
void Check_Keys();
DIRS getDirection(CPPOINT sourcePT, CPPOINT targetPT); // determine which direction to turn to face target
float findDistance(CPPOINT pt1,CPPOINT pt2); // returns distance in pixels
bool min_max
(int num
, int
min,int
max); // returns t/f is given # is with the range
void drawNumbers(int number, int screenX, int screenY, CPCOLOR color = CP_GREEN);
void drawText(char* outText, int screenX, int screenY, CPCOLOR color);
void drawBar
(int x
, int y
,int curr
,int
max, int color
); // draw bar at location; using current, max # and color
void drawBars(); // wrapper to draw player / enemy health bars
int SpriteCollision(CSprite *sprite1, CSprite *sprite2);// test for collisions
bool rectCollision(CPRECT r1, CPRECT r2);
bool circleCollision(CPPOINT a,int radius1, CPPOINT b, int radius2);
void createDebris(); // randomly creates the initial Debris for SPACE/SYSTEM/PLANET views
void respawnDebris(); // checks if debris leaves game space and spawns new debris
void drawPlanets(); // non-moving objects
void drawDebris(); // random moving objects
void moveDebris();
void checkDebris(); // player vs debris collision testing and results of impact
int planetCollision( CSprite *target ); // returns # of junk sprite collided with and reverses movement, if collided
int debrisCollision( CSprite *target ); // updated xy velocity after impact of 2 objects
void collision2Ds(double m1, double m2,
double x1, double y1, double x2, double y2);
int getScrollX(int x);
int getScrollY(int y);
void Init_Guns(); // setup the guns and ammo (for all SHIPS)
void moveBullets(); // moves the active bullets
void drawBullets(); // draws the bullet sprites
void bulletCollision(CShip *target);
void bullet_AI_Collision(CShip *target);
void createDrones(); // assigns the initial values to enemy ships
void respawnDrones(int );
void EnemyAI(); // makes AI choices/state changes
void BossAI();
void respawnBoss(bool randLoc);
void DrawBG(CPTexture& pSource);
CPPOINT offsetPT(CPPOINT pt1, int Width, int Height,DIRS Facing);
// handle the explosions
void newExp(CPPOINT dest);
void animExp();
void drawExp();
typedef enum
{
SPACE = 1,
PLANET = 3
} GAME_STATE;
void respawnPlayer();
#endif