game.h
来自「VIGASOCO (VIdeo GAmes SOurce COde) Windo」· C头文件 代码 · 共 192 行
H
192 行
// Game.h
//
// Main game class. It stores all game state, characters and game logic.
// The class is a singleton in order to be available everywhere.
//
/////////////////////////////////////////////////////////////////////////////
#ifndef _PACMAN_GAME_H_
#define _PACMAN_GAME_H_
#include "../Types.h"
#include "PlayerLevelState.h"
#include "Scheduler.h"
#include "../util/Singleton.h"
#include "GameSettings.h"
#include <list>
class GameState; // defined in GameState.h
class CharacterSubstate;// defined in CharacterSubstate.h
class Ghost; // defined in Ghost.h
class Pacman; // defined in Pacman.h"
#define theGame Game::getSingletonPtr()
enum gameStates {
INIT = 0,
DEMO = 1,
COIN_INSERTED = 2,
PLAYING = 3
};
struct Sprite {
int x, y;
int code, color;
bool flipX, flipY;
int priority;
Sprite(int xp, int yp, int sprCode, int sprColor)
{
x = xp;
y = yp;
code = sprCode;
color = sprColor;
flipX = flipY = false;
priority = 0;
}
Sprite(int xp, int yp, int sprCode, int sprColor, bool xFlip, bool yFlip, int pri)
{
x = xp;
y = yp;
code = sprCode;
color = sprColor;
flipX = xFlip;
flipY = yFlip;
priority = pri;
}
};
typedef std::list<Sprite> SpriteList;
class Game : public Singleton<Game>
{
// fields
public:
// all possible game states
int state;
static GameState *states[4];
UINT8 VRAM[0x400]; // Video RAM
UINT8 CRAM[0x400]; // Color RAM
SpriteList sprites; // sprite list
GameSettings settings; // game settings
// characters
Pacman *pacman; // pacman
Ghost *ghost[4]; // ghosts
Scheduler scheduler; // scheduler
// orientation changes
int ghostsOrientationChanges[7];
int indexOrientationChanges;
int cntOrientationChanges;
// counters for movement
int cntGhostsMovHome;
int cntGhostsAnimations;
int ghostsAnimationFrame;
int cntGhostsPanicAnim;
int cntSuperPillsAnimation;
int cntShowHide1P2P;
// difficulty
bool firstDiffFlag;
bool secondDiffFlag;
int pillsFirstDiffFlag;
int pillsSecondDiffFlag;
int pinkGhostExitHomeCounterLimit;
int blueGhostExitHomeCounterLimit;
int orangeGhostExitHomeCounterLimit;
int inactivityCounterLimit;
int inactivityCounter;
int eatenPillsAfterDead;
int timeInPanicState;
int remainingTimeInPanicState;
// fruit stuff
int fruitPosition;
int fruitEntry;
int fruitSprite;
int fruitColor;
int collisionObject; // collision detection
// ghosts' dead
int currentKills;
int killingGhostState;
int ghostDeadAnimState;
CharacterSubstate *ghostDeadSubstates[3];
int cutsceneState[3]; // cutscenes
// player level state (0 = active player, 1 = other player)
PlayerLevelState levelState[2];
int currentPlayer;
int numberOfPlayers;
// score
int score1P, score2P, highScore;
bool gotBonusLife1P, gotBonusLife2P;
// methods
protected:
// collision detection and movement
void killGhosts();
void moveAndCheckCollisions();
void checkTileColision();
void checkAbsolutePosColision();
void checkEndOfSuperPillEffect();
void checkIfPinkGhostGoesOut();
void checkIfBlueGhostGoesOut();
void checkIfOrangeGhostGoesOut();
void drawFruit();
public:
// main game loop
void run();
// collision detection and movement
void moveAndHandleCollisions();
// game counters
void updateDifficultyFlags();
void checkGhostsExitHomeCounters();
void checkGhostsExitHomeInactivity();
// game animation
void animateGhostDead();
void updateGhostAnimCounters();
void updateSuperPillState();
void moveGhostAtHome();
void setDeadGhostsColor();
void setGhostsColors();
// misc methods
void updateScore(int action);
void initSuperPillVars();
void savePillsConfiguration();
void checkForOrienationChange();
void checkDisplayFruit();
// initialization and cleanup
Game();
~Game();
void resetState();
// game's initialization methods
void initGameState();
void initCharacterState(bool special);
void resetCharacterPositions();
void initPlayersLevelData();
};
#endif // _PACMAN_GAME_H_
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?