1 /* 2 * Game.h 3 * Copyright (C) 2007 by Bryan Duff <duff0097@gmail.com> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 18 * USA 19 */ 20 21 #ifndef _GAME_H_ 22 #define _GAME_H_ 23 24 #include <stdlib.h> 25 #include <stdio.h> 26 #include <string.h> 27 #include <ctype.h> 28 #include <cstdarg> 29 30 #include "SDL_funcs.h" 31 #include "MacInput.h" 32 #include "Quaternions.h" 33 #include "Camera.h" 34 #include "Skeleton.h" 35 #include "Files.h" 36 #include "Models.h" 37 #include "Text.h" 38 #include "TGALoader.h" 39 #include "Fog.h" 40 #include "Font.h" 41 #include "Frustum.h" 42 #include "Sprites.h" 43 #include "Person.h" 44 #include "Decals.h" 45 #include "Globals.h" 46 #include "Weapon.h" 47 48 #include "Threads.h" 49 #include "Window.h" 50 #include "Label.h" 51 #include "Image.h" 52 #include "Button.h" 53 54 #define num_blocks 100 55 #define block_spacing 360 56 #define max_people 90 57 #define max_people_block 20 58 59 class Game { 60 public: 61 static Game &getInstance(); 62 63 //Eventloop 64 Boolean gQuit; 65 float gamespeed; 66 double end, start, framespersecond; 67 int maxfps; 68 //Graphics 69 int screenwidth, screenheight; 70 float viewdistance; 71 72 //GL functions 73 void LoadingScreen(float percent); 74 void DrawMouse(); 75 void DrawFlash(); 76 void DrawMainMenu(); 77 void DrawGame(); 78 int DrawGLScene(void); 79 80 //Game Functions 81 void SaveScreenshot(const char *path); 82 void HandleKeyDown(char theChar); 83 void EventLoop(void); 84 //Tick functions 85 void Splat(int k); 86 void MainMenuTick(); 87 void SpawnPeople(); 88 void checkCollisions(); 89 void Fire(); 90 void GameTick(); 91 void Tick(); 92 93 void InitGame(); 94 void InitGUI(); 95 void Dispose(); 96 97 //Mouse 98 Point mouseloc; 99 Point oldmouseloc; 100 101 float mouserotation, mouserotation2; 102 float oldmouserotation, oldmouserotation2; 103 float mousesensitivity; 104 float usermousesensitivity; 105 106 int mouseoverbutton; 107 int oldmouseoverbutton; 108 109 Point olddrawmouse; 110 111 //keyboard 112 bool tabkeydown; 113 bool slomokeydown; 114 bool oldvisionkey; 115 116 //Project Specific 117 //state 118 enum game_state state; 119 bool initialized; 120 bool paused; 121 bool gameinprogress; 122 123 bool oldbutton; 124 int enemystate; 125 int cycle; 126 127 //setting 128 float losedelay; 129 bool reloadtoggle; 130 bool aimtoggle; 131 float difficulty; 132 bool azertykeyboard; 133 ///TODO: add an 'always on' feature for the lasersight? 134 bool lasersight; 135 136 //stat 137 int goodkills; 138 int badkills; 139 int civkills; 140 141 int cityrotation[num_blocks][num_blocks]; 142 int citytype[num_blocks][num_blocks]; 143 int citypeoplenum[num_blocks][num_blocks]; 144 bool drawn[num_blocks][num_blocks]; 145 int onblockx, onblocky; 146 147 float flashamount; 148 float flashr, flashg, flashb; 149 150 Person person[max_people]; 151 152 GLuint personspritetextureptr; 153 GLuint deadpersonspritetextureptr; 154 GLuint scopetextureptr; 155 GLuint flaretextureptr; 156 157 XYZ bodycoords; 158 159 FRUSTUM frustum; 160 Model blocks[4]; 161 Model blockwalls[4]; 162 Model blockcollide[4]; 163 Model blocksimplecollide[4]; 164 Model blockroofs[4]; 165 Model blockocclude; 166 Model sidewalkcollide; 167 Model street; 168 Model Bigstreet; 169 Model path; 170 Model blocksimple; 171 XYZ boundingpoints[8]; 172 Files files; 173 Text text; 174 175 int machinegunsoundloop; 176 bool blur; 177 178 XYZ vipgoal; 179 XYZ aimer[2]; 180 181 double eqn[4]; 182 183 float oldrot, oldrot2; 184 185 XYZ lastshot[2]; 186 bool zoom, oldzoom; 187 188 int numpeople; 189 float spawndelay; 190 191 float psychicpower; 192 193 int type; 194 195 float timeremaining; 196 int whichsong; 197 int oldscore; 198 int score; 199 int mission; 200 int nummissions; 201 int numpossibleguns; 202 int possiblegun[6]; 203 int evilprobability; 204 205 int shotcount; 206 207 //checkCollision, GameTick 208 unsigned char theKeyMap[16]; 209 210 int beginx, endx; 211 int beginz, endz; 212 213 XYZ normalrotated; 214 XYZ move; 215 XYZ underpoint; 216 XYZ overpoint; 217 218 int whichtri; 219 220 XYZ facing; 221 int murderer; 222 ~Game()223 ~Game() { 224 glDeleteTextures(1, (const GLuint *)&personspritetextureptr); 225 glDeleteTextures(1, (const GLuint *)&deadpersonspritetextureptr); 226 glDeleteTextures(1, (const GLuint *)&scopetextureptr); 227 glDeleteTextures(1, (const GLuint *)&flaretextureptr); 228 } 229 230 private: 231 static std::auto_ptr <Game> instance; 232 static Mutex m; 233 }; 234 235 #endif 236