Pac-Man Evolution
Loading...
Searching...
No Matches
Objects.h
1/*----------------------------------------------------------------------
2Pac-Man Evolution - Roberto Prieto
3Copyright (C) 2018-2024 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
24Objects, State and Actor classes
25
26------------------------------------------------------------------------ */
27
28#ifndef OBJECTSPME_H
29#define OBJECTSPME_H
30
31//#define DEBUG_FSM
32
33#define PME_GETREADY_TIME 2000
34#define PME_PACMAN_START_SPEED 4
35#define PME_PACMAN_START_LIFES 3
36#define PME_PACMAN_ENPOWERED_TIME 7000
37#define PME_GHOST_START_SPEED 3
38#define PME_GHOST_SPEED_VARIATION 1
39#define PME_GHOST_CHASING_TIME 20000 //20000
40#define PME_GHOST_SCATTERING_TIME 6000
41#define PME_CRUISE_MODE 8 // After 8 changes, chasing is fixed
42
43// Includes and forward definitions
44#include "MemoryManager.h"
45#include "Pac-Man_Evolution.h"
46class GameField;
47class Actor;
48
49// ---------------- Object base class ----------------
50class Object : public CMemPME
51{
52public:
53 Object(Sint32, Sint32, Sint32, GameField*);
54 virtual ~Object();
55 virtual Sint32 execute();
56 Sint32 render(Sint32, Sint32);
57 virtual Sint32 debug(Sint32);
58
59 // Messages that modified our state
60 virtual Sint32 msgPause();
61 virtual Sint32 msgGoInit();
62 virtual Sint32 msgPelletPowerEaten(Sint32, Sint32);
63 virtual Sint32 msgGhostCollision();
64
65 // Generic methods
66 Sint32 getID();
67 void getName(string&);
68 void getPositionMaze(Sint32&, Sint32&);
69 void getDirection(Sint32&, Sint32&);
70
71protected:
72 // Attributes
73 Sint32 iID; // PME_ITEM_PELLET_POWER, PME_OBJECT_PACMAN, PME_OBJECT_GHOST_RED, etc
74 Sint32 sprID; // Object sprite ID
75 Sint32 iPositionX, iPositionY; // Position on the maze in pixels
76 Sint32 iMazeX, iMazeY; // Position on the maze in tiles
77 Sint32 iMazePrevX, iMazePrevY; // Previous position on the maze in tiles
78 Sint32 iStartingPositionX; // Starting X position on the maze in pixels
79 Sint32 iStartingPositionY; // Starting Y position on the maze in pixels
80 Sint32 iMazeRenderingX; // X Position where the maze is rendered in pixels, calculated on Gamefield::render()
81 Sint32 iMazeRenderingY; // Y Position where the maze is rendered in pixels, calculated on Gamefield::render()
82 bool bRenderExecuteSync;
83
84 // Pointer to needed components
85 GameField* pGameField;
86};
87
88// ---------------- State on the FSM ----------------
89class State : public CMemPME
90{
91public:
92 explicit State(const string&);
93 virtual ~State();
94 virtual void enter(Actor*);
95 virtual void execute(Actor*) = 0;
96 virtual void exit(Actor*);
97 void getName(string &);
98private:
99 string sName;
100};
101
102// ---------------- Actor class ----------------
103class Actor : public Object
104{
105public:
106 Actor(Sint32 iObjID, Sint32 iMX, Sint32 iMY, GameField* GF);
107 virtual ~Actor();
108 virtual Sint32 execute();
109 Sint32 debug(Sint32);
110
111 enum eSpriteState
112 {
113 SS_DEFAULT = 0,
114 SS_EVADE_FIRST_STAGE = 1,
115 SS_EVADE_SECOND_STAGE = 2,
116 SS_DEATH = 3
117 };
118
119 enum eActorMoving
120 {
121 AM_DISABLED = 0,
122 AM_NEXT_STEP = 1,
123 AM_WORKING = 2
124 };
125
126 Sint32 msgPause();
127 Sint32 msgGoInit();
128
129 // Auxiliary methods
130 double euclideanDistance(Sint32, Sint32, MazePoint&);
131 Sint32 getStateName(string&);
132
133 // Brain management
134 Sint32 getBrain();
135 Sint32 setBrain(Sint32);
136 Sint32 think(Sint32&, Sint32&);
137
138protected:
139 Sint32 moveX(Sint32);
140 Sint32 moveY(Sint32);
141
142 // Attributes
143 Sint32 iSpeed; // Movement speed
144 eSpriteState eSS; // Sprite state modifier.
145 eActorMoving eAM; // Moving status
146 vector<MazePoint> vPath; // Path that the actor will follow, first element is the target
147 MazePoint pointNextStep; // Next step coordinates
148 MazePoint pointTarget; // Desired target
149 Sint32 sprTargetID; // Target sprite ID
150
151 // Brain
152 Sint32 idBrain;
153
154 // State Machine methods and attributes for Pac-Man and Ghosts
155 void stateChange(State*);
156 void statePrevious();
157 bool stateCurrentCheck(State&);
158 bool statePreviousCheck(State&);
159 State* pCurrentState;
160 State* pPreviousState;
161};
162
163#endif