SHARE
TWEET

GameClass.h

a guest Jan 19th, 2020 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Windows.h>
  2. #include <d3d9.h> // directx header files
  3. #include <d3dx9.h>
  4. #include <d3dx9mesh.h>
  5. #include <dinput.h>
  6. #include "dxdbg.h"
  7. #include "CMesh.h"
  8. #include "MP3.h"
  9. #include "bsp.h"
  10. using namespace std;
  11. class Game
  12. {
  13. public:
  14.     ///////////////////////////////
  15.     ////////////////////////////////////////////////////////
  16.     //Preprocessor #defines
  17.     ////////////////////////////////////////////////////////
  18. #define SZ_FILE_BSP "maze5.bsp" // Quake 3 Type BSP Level File
  19. #define _NUMOFMAPOBJECTS 10
  20. #define __NUMOFGAMETRIGGERS 3
  21. #define _TYPE_LANTERN   1
  22. #define _TYPE_AK47      2
  23. #define _TYPE_BODY      3
  24. #define _TYPE_CLIPBOARD 4
  25.     ////////////////////////////////////////////////////////
  26.     //Global DirectX Variables
  27.     ////////////////////////////////////////////////////////
  28.     static  ID3DXEffect*       g_pEffect;
  29.     static  ID3DXEffect*       g_pEffectMesh;
  30.     static  LPDIRECTINPUT8 g_lpdi;
  31.     static  LPDIRECTINPUT8 pDI;
  32.     static LPDIRECTINPUTDEVICE8 pMouse;
  33.     static  LPDIRECT3D9 g_pD3D;
  34.     static  LPDIRECT3DDEVICE9 g_pd3dDevice;
  35.     static  IDirect3DTexture9* cubetex;
  36.     static  IDirect3DTexture9* cubetex2;
  37.     static  IDirect3DTexture9* AKTex;
  38.     static  IDirect3DTexture9* clipboardTex;
  39.     static  IDirect3DTexture9* g_Inv_LanternTex;
  40.     static  IDirect3DTexture9* g_Inv_ClipboardTex;
  41.     static  IDirect3DTexture9* g_Inv_ClipboardTex2;
  42.     static  IDirect3DTexture9* flashlightTex;
  43.     static  D3DXVECTOR3 g_vCamPosition;
  44.     static  D3DXVECTOR3 g_vNewPosition;
  45.     static  D3DXVECTOR3 g_vCamDir;
  46.     static  D3DXVECTOR3 g_vBallPos;
  47.     static  D3DXVECTOR3 g_vNewBallPos;
  48.     static  D3DXVECTOR3 g_vNewMonsterPos;
  49.     static  D3DXVECTOR3 g_vMonsterPos;
  50.     static  D3DXVECTOR3 vMonsterDir;
  51.     static  D3DXVECTOR3 vTemp2;
  52.     static  D3DXVECTOR3 vHitWallPos2;
  53.     static  D3DXVECTOR3 vHitWallNormal2;
  54.     static  D3DXVECTOR3 vGunPosVar;
  55.     static  D3DXVECTOR3 vGunRotate;
  56.     static  D3DXVECTOR3 vGunPos;
  57.     static D3DXVECTOR3 pNose;
  58.     static D3DXMATRIX world, view, proj;
  59.     static  HWND g_hwnd;
  60.     ////////////////////////////////////////////////////////
  61.     //MP3 Class Globals
  62.     ////////////////////////////////////////////////////////
  63.     Mp3 static g_Mp3Horror1;
  64.     Mp3 static g_Mp3Horror2;
  65.     Mp3 static g_Mp3Horror3;
  66.     Mp3 static g_Mp3Breathing;
  67.     Mp3 static g_Mp3Roar;
  68.     Mp3 static MP3PLAYER2;
  69.     Mp3 static MP3PLAYER3;
  70.     Mp3 static g_Mp3ClipBoard;
  71.     ////////////////////////////////////////////////////////
  72.     //Globals
  73.     ////////////////////////////////////////////////////////
  74.     static float fLengthFromMonster;
  75.     static float g_fSpinX;
  76.     static float g_fSpinY;
  77.     static float g_fZoom;
  78.     static float g_fLine;
  79.     static float g_fHeight;
  80.     static float fShipFloat;
  81.     static float Start;    // Linear fog distances
  82.     static float End;
  83.     static bool g_bWire;
  84.     static bool g_bTopView;
  85.     static bool g_bDrawShadowLevel;
  86.     static bool g_bGravity; //gravity set to false for now
  87.     static bool g_bShowMonster;
  88.     static bool g_bDebugSphere;
  89.     static bool g_bMonsterChase;
  90.     static bool g_bShowConsole;
  91.     static bool g_bPlayMusic;
  92.     static bool g_bGunFire;
  93.     static bool g_bGunPickedUp;
  94.     static bool g_bMonsterChangeDir;
  95.     static bool g_bShowClipBoard;
  96.     static bool g_bClipboardShowed;
  97.     static bool g_bShowSecondHint;
  98.     static bool g_bTextShowed;
  99.     static  bool g_bWithinMonsterView;
  100.     static  bool g_bSurpriseDirChange;
  101.     static bool g_bShowingDiary;
  102.     static bool g_bShowedDiary;
  103.     static bool g_bShowFlashlight;
  104.     static bool g_bRunning;
  105.     static bool g_bBallChangeDir;
  106.     static int g_nTotalTris;
  107.     static int g_nDrawnTris;
  108.     static int g_iInvLanterns;
  109.     static float fDensity;
  110.     static float gunscale;
  111.     static float rotconstant;
  112.     static float fDistance;
  113.     static float rotx;
  114.     static float roty;
  115.     static float xangle;
  116.     static float yangle;
  117.     static float LIGHT_RADIUS;
  118.     static float LIGHT_SPOT_INNER_CONE;
  119.     static float LIGHT_SPOT_OUTER_CONE;
  120.     static bool g_bInitLoaded;
  121.     static bool g_bLoadingThread;
  122.     static bool g_bWaitingOnChange;
  123.     static int iSongIndex;
  124.     static bool g_bScarySoundPlayed;
  125.     static bool g_bBreathingSoundPlayed;
  126.     static bool g_bMonsterAwake;
  127.     static bool g_bMonsterAwaking;
  128.     static bool g_bMonsterAwoke;
  129.     static float att0;
  130.     static float att1;
  131.     static float att2;
  132.     static float falloff;
  133.     static float g_sceneAmbient[4]; //init in constuctor
  134.     static int width, height;
  135.     static int g_iInvPages;
  136.     static bool bIntro;
  137.     static bool bCrazy;
  138.     unsigned long static int iIndex;
  139.     static bool bAssigned;
  140.     static char g_ConsoleLog[100000];
  141.     static int g_iNumofMeshes;
  142.     static float fShipRotate;
  143.     static clock_t clockTicksTaken;
  144.     static clock_t endTime;
  145.     static double timeInSeconds;
  146.     std::clock_t start;
  147.     static int starttime;
  148.     static int g_iLightLevel;
  149.     static clock_t firstTime;
  150.     static clock_t firstTime2;
  151.     static clock_t firstTimeHorror;
  152.     ////////////////////////////////////////////////////////
  153.     //Meshes
  154.     ////////////////////////////////////////////////////////
  155.     static CMesh m_mesh;
  156.     static CMesh m_meshAK47;
  157.     static CMesh m_meshDeadBody;
  158.     static CMesh m_meshShip;
  159.     static CMesh m_meshClipboard;
  160.     static CMesh m_meshEyes;
  161.     static CMesh m_meshTeapot;
  162.     static CMesh m_meshLantern;
  163.     static CMeshInstance* m_pMeshes;
  164.     static CMeshInstance* m_pShip;
  165.     static CMeshInstance* m_pMapMeshes;
  166.     ////////////////////////////////////////////////////////
  167.     //BSP Class Globals
  168.     ////////////////////////////////////////////////////////
  169.     static CBSP bsp;
  170.     static CBSP lightbsp;
  171.     ////////////////////////////////////////////////////////
  172.     //Function Prototypes
  173.     ////////////////////////////////////////////////////////
  174.     D3DXVECTOR3 FindDirection(D3DXVECTOR3 *target, D3DXVECTOR3 *firer);
  175.     void MovePlayer(CBSP * bsp,
  176.         D3DXVECTOR3 * vStart,
  177.         D3DXVECTOR3 * vEnd);
  178.     void MoveMonster(CBSP * bsp,
  179.         D3DXVECTOR3 * vStart,
  180.         D3DXVECTOR3 * vEnd);
  181.     void MoveBall(CBSP * bsp,
  182.         D3DXVECTOR3 * vStart,
  183.         D3DXVECTOR3 * vEnd);
  184.     static int  ObtainFPS();
  185.     bool MonsterInView(CBSP *bsp, D3DXVECTOR3 *vEnd);
  186.     static void FootSteps();
  187.     static void ShowDiary();
  188.     static void RenderLoading();
  189.     static void CreateMouse();
  190.     static void Mouse();
  191.     static void ShowClipboard();
  192.     static void Console(char buf[200]);
  193.     static void ShowConsole();
  194.     static void ShowDebugConsole();
  195.     static void FlashLight();
  196.     static void UpdateEffect();
  197.     static bool LoadShader(const char *pszFilename, LPD3DXEFFECT &pEffect);
  198.     static void SetupVertexFog(DWORD Color, DWORD Mode, BOOL UseRange, FLOAT Density);
  199.     static void MouseActions2(int x, int y, int lmb, int rmb, int mmb);
  200.     static void MonsterChase(CBSP *bsp);
  201.     static void Gravity(CBSP *bsp);
  202.     static void SetCameraTopView();
  203.     static void SetCameraLevelView();
  204.     static void RenderInventory();
  205.     static void SetMaterial();
  206.     static void RenderPosition();
  207.     static void SetLight();
  208.     static void ShowGameHints();
  209.     static void RenderInfo();
  210.     static void WakeMonster();
  211.     static void ObjectPickup();
  212.     static void BallMovement();
  213.     static void PlayHorror();
  214.     static void KeyBoard();
  215.     static void PlayBreathing();
  216.     static void PlayPaperSound();
  217.     static void PlayScarySound();
  218.     static bool LoadAll();
  219.     static bool Release();
  220.     ////////////////////////////////////////////////////////
  221.     //Thread Function Prototypes
  222.     ////////////////////////////////////////////////////////
  223.     static DWORD WINAPI KeyBoardThread(LPVOID lpParam);
  224.     static DWORD WINAPI RenderMeshes(LPVOID lpParam);
  225.     static DWORD WINAPI BreathingSoundTimer(LPVOID lpParam);
  226.     static DWORD WINAPI SurpiseDirChange(LPVOID lpParam);
  227.     static DWORD WINAPI ScarySoundTimer(LPVOID lpParam);
  228.     static DWORD WINAPI WakingTimer(LPVOID lpParam);
  229.     static DWORD WINAPI SongTimer(LPVOID lpParam);
  230.     static DWORD WINAPI GameHintsThread(LPVOID lpParam);
  231.     static DWORD WINAPI TextTimer(LPVOID lpParam);
  232.     static DWORD WINAPI LoadingThread(LPVOID lpParam);
  233.     ////////////////////////////////////////////////////////
  234.     //structs
  235.     ////////////////////////////////////////////////////////
  236.     struct Light
  237.     {
  238.         enum { DIR_LIGHT, POINT_LIGHT, SPOT_LIGHT };
  239.  
  240.         int type;
  241.         float dir[3];
  242.         float pos[3];
  243.         float ambient[4];
  244.         float diffuse[4];
  245.         float specular[4];
  246.         float spotInnerCone;
  247.         float spotOuterCone;
  248.         float radius;
  249.     };
  250.  
  251.     struct Material
  252.     {
  253.         float ambient[4];
  254.         float diffuse[4];
  255.         float emissive[4];
  256.         float specular[4];
  257.         float shininess;
  258.     };
  259.     Light static g_light;//init in constuctor
  260.     Material static g_material; //init in constuctor
  261.     enum { DIR_LIGHT, POINT_LIGHT, SPOT_LIGHT };
  262.     struct Vertex
  263.     {
  264.         float pos[3];
  265.         float texCoord[2];
  266.         float normal[3];
  267.     };
  268.  
  269.     struct DebugConsole {
  270.         char sData[5000];
  271.         static bool bDisplayed;
  272.         DebugConsole *next;
  273.     };
  274.     DebugConsole static *root; // This won't change, or we would lose the list in memory
  275.     DebugConsole static *conductor; // This will point to each node as it traverses the list
  276.     struct GameHintTrigger
  277.     {
  278.         static char sData[100];
  279.         static bool bDisplayed;
  280.         static bool bDisplay;
  281.     };
  282.     GameHintTrigger static GameHintTriggers[__NUMOFGAMETRIGGERS];
  283.     struct GameHints
  284.     {
  285.         static char Data[200];
  286.         static bool bDisplay;
  287.     };
  288.     GameHints static *GameHintsDisplay[3];
  289.     class MapObject
  290.     {
  291.     public:
  292.         CMeshInstance *pMapMesh;
  293.         static bool pickedup;
  294.         static float xpos, ypos, zpos; //Position of Map Object
  295.         static int ObjType; //Type of Object i.e. _TYPE_LANTERN, gun, etc.
  296.         MapObject::MapObject() {};
  297.         MapObject::MapObject(int type, float x, float y, float z);
  298.         static void MapObject::Render();
  299.     };
  300.     MapObject static *MapObjects[_NUMOFMAPOBJECTS];
  301.  
  302.  
  303.     ////////////////////////////////////////////////////////////////////////////////
  304.     //////////////////////////////////////////////////////////////
  305.     //////////////////////////////////////////////////////////////
  306.     //////////////////////////////////////////////////////////////
  307.     Game::Game();
  308.     static bool CreateDX(HWND hWnd);
  309.     static void Render();
  310.     static void ShowMessage(char buff[500]) { MessageBoxA(NULL, buff, buff, MB_OK); }
  311. };
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top