Pac-Man Evolution
Loading...
Searching...
No Matches
GameField.h
1/*----------------------------------------------------------------------
2Pac-Man Evolution - Roberto Prieto
3 Copyright (C) 2018-2025 MegaStorm Systems
4contact@megastormsystems.com - http://www.megastormsystems.com
5
6This software is provided 'as-is', without any express or implied
7warranty. In no event will the authors be held liable for any damages
8arising from the use of this software.
9
10Permission is granted to anyone to use this software for any purpose,
11including commercial applications, and to alter it and redistribute it
12freely, subject to the following restrictions:
13
141. The origin of this software must not be misrepresented; you must not
15claim that you wrote the original software. If you use this software
16in a product, an acknowledgment in the product documentation would be
17appreciated but is not required.
182. Altered source versions must be plainly marked as such, and must not be
19misrepresented as being the original software.
203. This notice may not be removed or altered from any source distribution.
21
22------------------------------------------------------------------------
23
24GameField class
25
26------------------------------------------------------------------------ */
27
28#ifndef GAMEFIELDPME_H
29#define GAMEFIELDPME_H
30
31// Flags for debugging
32//#define DEBUG_INTERNAL
33
34// Includes and forward definitions
35#include "MemoryManager.h"
36#include "Pac-Man_Evolution.h"
37class Maze;
38class MapSearchAStar;
39class Object;
40class EVNTrainer;
41class Actor;
42
43#define PME_STATE_NULL 0
44#define PME_STATE_WALL 1
45#define PME_STATE_WALKABLE_GHOST 2
46#define PME_STATE_WALKABLE 4
47
48#define PME_ITEM_NULL 0
49#define PME_ITEM_PELLET 1
50
51#define PME_OBJECT_NULL 0
52#define PME_OBJECT_PACMAN 1
53#define PME_OBJECT_GHOST_RED 2
54#define PME_OBJECT_GHOST_PINK 4
55#define PME_OBJECT_GHOST_BLUE 8
56#define PME_OBJECT_GHOST_ORANGE 16
57#define PME_OBJECT_PELLET_POWER1 32
58#define PME_OBJECT_PELLET_POWER2 64
59#define PME_OBJECT_PELLET_POWER3 128
60#define PME_OBJECT_PELLET_POWER4 256
61
62#define PME_GET_PELLET(x) ((x) & 0x1E0)
63
64#define PME_ACTOR_ALIVE PME_LOOP
65#define PME_ACTOR_SPECIAL 1
66
67#define PME_GLOBAL_WAVE_CHASING 1
68#define PME_GLOBAL_WAVE_SCATTERING 2
69#define PME_GLOBAL_WAVE_EVADING 4
70#define PME_GLOBAL_WAVE_EVADING_END 8
71
72#define RENDERGRAPHICS_START 0
73#define RENDERGRAPHICS_GAME 1
74
75// Debug output
76#define PME_DEBUG_PANEL_GAMEFIELD_X 8
77#define PME_DEBUG_PANEL_GAMEFIELD_Y 0
78#define PME_DEBUG_PANEL_PACMAN_X 8
79#define PME_DEBUG_PANEL_PACMAN_Y 112
80#define PME_DEBUG_PANEL_GHOST_X 8
81#define PME_DEBUG_PANEL_GHOST_Y 224
82
83// GameField class
84class GameField : public CMemPME
85{
86 friend class EVNTrainer;
87public:
88 GameField(GlobalStatus* GS);
89 ~GameField();
90 Sint32 init();
91 Sint32 nextMaze();
92 Sint32 close();
93 Sint32 execute();
94 Sint32 render(Sint32 iMode);
95
96 MapSearchAStar& mapSearch();
97 Sint32 getState(Sint32 iMX, Sint32 iMY);
98 Sint32 getItem(Sint32 iMX, Sint32 iMY);
99 Sint32 getEatenPelletsPercent();
100 Sint32 getObjectPosition(Sint32, Sint32&, Sint32&);
101 Sint32 getObjectDirection(Sint32, Sint32&, Sint32&);
102 Sint32 getObjectStateName(Sint32, string&);
103 Sint32 getClosestPellet(Sint32, Sint32&, Sint32&);
104 Sint32 moveTo(Sint32, Sint32, Sint32, Sint32, Sint32);
105 Sint32 messageGetReady(Sint32 iShow);
106 Sint32 initObjects();
107 Sint32 validateMazePosition(Sint32&, Sint32&);
108 Sint32 getMovementOptions(Sint32, Sint32, vector<MazePoint>&);
109 Sint32 getWaveMode();
110 Sint32 setWaveMode(Sint32);
111 Sint32 restoreWaveMode();
112
113private:
114 // GlobalWave vars
115 struct sGlobalWave
116 {
117 Sint32 update();
118 Sint32 reset();
119
120 Sint32 iMode;
121 Sint32 iPreviousMode;
122 Sint32 iTicks;
123 Sint32 iChanges;
124 } sGlobalWave;
125
126 // General methods
127 Sint32 messageStart(); // Show a message at the beginning of each maze
128 Sint32 messageEnd(Sint32); // Show a message at the end of the game
129 Sint32 specialText(Font* pFont, Sint32 iX, Sint32 iY, string &sText, Sint32 iCount);
130 Sint32 debug(); // Show debug information on game screen
131 Sint32 addPoints(Sint32 iP);
132
133 // General attributes
134 Uint64 iTimeStart;
135 Sint32 iMazeReady, iGetReadyTime;
136 Sint32 iNumPellets, iNumEatenPellets;
137 Sint32 iMazePixelX, iMazePixelY; // Start maze rendering coordinates, auto-adapt to screen resolution
138 template <typename T> T **create2DArray(Sint32 height, Sint32 width); // Taken from CRM64Pro
139 template <typename T> Sint32 delete2DArray(T** Array); // Taken from CRM64Pro
140 struct sField
141 {
142 Sint32 iState;
143 Sint32 iItem;
144 Sint32 iObject;
145 Sint32 iReserved;
146 };
147 sField **iFieldArray; // Dynamic 2D array [y][x]
148
149 // Vector with objects
150 vector<Object*> vObjects;
151 Sint32 getObjectIndex(Sint32);
152
153 // Used by EVNTrainer
154 Actor* getActor(Sint32);
155 Sint32 getMazeNumber();
156
157 // Special messages (start game, end game, add points, etc.) vars
158 Sint32 iRenderGraphicsStatus;
159 Sint32 iSpecialTextCounter;
160 string sSpecialMessageCounter;
161 string sSpecialMessage;
162
163 // Debug stuff
164 Sint32 bDebug;
165 Sint32 iDebugMode;
166 Sint32 bDebugDisableObjectRender;
167 Sint32 bDebugShowTarget;
168 Sint32 iMazeDynamicGenerationTime;
169 Sint32 iMazeDynamicGenerationAttemps;
170
171 // Internal components
172 Maze* pMazeGen;
173 MapSearchAStar* pMapSearch;
174
175 // Pointer to needed components
176 GlobalStatus* pGlobalStatus;
177};
178
179#endif