Skip to content
Newer
Older
100755 161 lines (128 sloc) 5.58 KB
7daf1a9 @dimroc Initial check in to git
authored Aug 25, 2012
1 #pragma once
2
3 #include "GlobalDefine.h"
4 #include "mp3player.h"
5
6 using std::list;
7 using std::vector;
8
9 class CGameEntities
10 {
11 private:
12 static const UCHAR PLAYER_STOP = 0x00;
13 static const UCHAR PLAYER_FORWARD = 0x01;
14 static const UCHAR PLAYER_BACK = 0x02;
15 static const UCHAR PLAYER_LEFT = 0x04;
16 static const UCHAR PLAYER_RIGHT = 0x08;
17
18 static const int m_ActorSpriteID = 0;
19 static const int m_ShelterSpriteID = 1;
20 static const int m_ObstacleSpriteID = 2;
21 static const int m_DecorationSpriteID = 3;
22 static const int m_PlayerSpriteID = 4;
23 static const int m_HighlighterCurID = 5;
24
25 /////////////////////////// STRUCTS /////////////////////////////
26 struct SSprite {
27 IDirect3DVertexBuffer9* m_pVB;
28 vector<LPDIRECT3DTEXTURE9> m_vpTex;
29 int nFrames;
30 float animSpeed; //! animation speed
31
32 SSprite(IDirect3DDevice9* pd3dDevice, float width, float height); // height and width of billboard
33 ~SSprite();
34
35 VOID AddTexture(IDirect3DDevice9* pd3dDevice, LPCWSTR texFileName);
36 };
37
38 //! Interface containing all Entity attributes. Inherited by other elements.
39 struct IEntity { // polymorphism is unecessary
40 int SpriteID; //! Which Group of Textures this Entity uses
41 int nFrame; //! Which frame in the Texture Group it's in (sprites).
42 float fScale; //! scale of entity!
43 float x, y; //! position
44 float radius; //! for collision detection
45 float timeElapsed;
46 float speed; //! movement speed
47 D3DXMATRIX mWorld; //! Every Entity has it's own world mtx based on it's 2D position.
48
49 IEntity();
50 ~IEntity();
51
52 virtual VOID OnFrameMove(float elapsedTime);
53 VOID UpdateWorldMatrix(bool bFlipHorizontal = false);
54 };
55 struct SDecoration : public IEntity {
56 SDecoration(float scale, float _x, float _y);
57 ~SDecoration();
58 };
59 struct SActor : public IEntity {
60 UCHAR movement;
61 bool bSheltered, bPlayer;
62 float width, height;
63 float lastTime;
64
65 SActor();
66 SActor(float scale, float x, float y, int level);
67 ~SActor();
68 virtual VOID OnFrameMove(float elapsedTime);
69 VOID PerformAI(float elapsedTime, bool bSheltered, float playerx, float playery, float playerrad, int level);
70 BOOL WithinSightRadius(float playerx, float playery, float playerrad, int level);
71 };
72 struct SShelter : public IEntity {
73 double lastVisit;
74 bool bBulldozed;
75 SShelter();
76 SShelter(float scale, float x, float y);
77 ~SShelter();
78 };
79 struct SObstacle : public IEntity {
80 float tx, ty;
81 bool bConstructing, bLeftToRight, bDone;
82 float lastTime;
83 list<SShelter>::iterator itTarget;
84
85 SObstacle(list<SShelter>::iterator itTarget, bool _bConstructing = false);
86 ~SObstacle();
87 virtual VOID OnFrameMove(float elapsedTime, SActor &player, list<SShelter> &shelters, float &speedIncr);
88 };
89
90 bool m_bCameraMoveX, m_bCameraMoveY;
91 float m_CameraStepX, m_CameraStepY;
92 float m_lastSpawnTime;
93
94 int m_level;
95 float m_totalCarbonEaten; //! how many pencil ppl he's eaten since last death
96
97 double m_TotalTime;
98
99 vector<SSprite*> m_vSprites;
100
101 list<SDecoration> m_lDecorations;
102 list<SActor> m_lEnemies;
103 list<SShelter> m_lShelters;
104 list<SObstacle> m_lObstacles;
105
106 SActor m_Player;
107 private:
108 VOID DrawDecorations(IDirect3DDevice9* pd3dDevice);
109 VOID DrawShelters(IDirect3DDevice9* pd3dDevice);
110 VOID DrawObstacles(IDirect3DDevice9* pd3dDevice);
111 VOID DrawEnemies(IDirect3DDevice9* pd3dDevice);
112 VOID DrawPlayer(IDirect3DDevice9* pd3dDevice);
113
114 VOID PlaceSpriteVBOnDevice(IDirect3DDevice9* pd3dDevice, int index);
115 VOID PlaceSpriteInfoOnDevice(IDirect3DDevice9* pd3dDevice, const D3DXMATRIX &mWorld, int SpriteIndex, int nFrame);
116
117 VOID SpawnHouses(int level);
118 VOID SpawnDecorations(int level);
119 VOID SpawnEnemies(int level);
120 VOID SpawnBulldozer(float elapsedTime);
121
122 BOOL CheckPlayerCollision(); //! Checks if players eat trees(decorations) or eat/get eaten
123 BOOL IsOnBoard(float nx, float ny, float nr);
124
125 VOID UpdateCamera(D3DXVECTOR3 &vEye, D3DXVECTOR3 &vAt, float speed, UCHAR movement, float elapsedTime);
126
127 static BOOL WithinWidth(float x) {
128 static float halfWidth = g_bgWidth/2;
129 return abs(x) < halfWidth; }
130
131 static BOOL WithinHeight(float y) {
132 static float halfHeight = g_bgHeight/2;
133 return abs(y) < halfHeight; }
134
135
136 public:
137 static const int LEVEL_COMPLETE = 1;
138 static const int LEVEL_DEATH = 2;
139 static const int LEVEL_GAMEOVER = 3;
140 static const int LEVEL_CANCOMPLETE = 4;
141
142 CGameEntities(IDirect3DDevice9* pd3dDevice);
143 ~CGameEntities(void);
144
145 VOID PopulateWorld(int level);
146 VOID CleanWorld();
147
148 INT OnFrameMove(D3DXVECTOR3 &vEye, D3DXVECTOR3 &vAt, float elapsedTime);
149 HRESULT Render(IDirect3DDevice9* pd3dDevice);
150
151 float GetScore() { return (m_totalCarbonEaten)*g_ScoreDisplayMult; }
152 VOID ResetScore() { m_totalCarbonEaten = 0.0f; }
153
154 VOID PlayerToggleForward(bool bKeyDown);
155 VOID PlayerToggleBackward(bool bKeyDown);
156 VOID PlayerToggleLeft(bool bKeyDown);
157 VOID PlayerToggleRight(bool bKeyDown);
158 };
159
160 BOOL IsCollision(float nx, float ny, float nr, float ox, float oy, float or);
Something went wrong with that request. Please try again.