Project NinjaGo Intro
NinjaGo is a 2D Platform Game implemented in C++ using SDL library. NinjaGo is superior to peer projects in the sense of its design architecture. The classes are well-organized and ready for further implementation. Here is a detailed but also condensed walkthrough of the basic class hierarchy.
Class List
Collider & GameObject:
- Bullet, Collectible, Hero, Minion, Powerup, Tile
Menu:
- InstructionMenu, MainMenu, PassMenu, PauseMenu, SettingsMenu, WinMenu, LoseMenu
System:
- CollisionSystem, ControlSystem, DisplaySystem, GameSetting, PlaySystem, ResourceManager, SoundSystem, TileMapSystem
Other/Utilities:
- Camera, CAnimation, Collision, LButton, LTexture, LTimer, MainProgram, TileMap, Vector2D
Collider & GameObject:
GameObject
A GameObject is the basic unit of the game. It is a base class to be inherited.
- velocty, position, acceleartion, etc
- tag: used to identify what object it is
- animationControl: how to generate animation
- poseCode: which pose the character is having at current frame
Collider
A Collider is the interactive component of the game.
- boundingBox
-
colDir: normal vector of the collider
- onCollide(Collider c): compare whether two bounding boxes overlap (To be updated)
Bullet
A simple class.
Collectible
A Collectible refers to coin-like game objects the player can collect along the gameplay.
Hero
The hero class only sets up the basic info. Collision is handled via CollisionSystem, receiving and processing player input data is handled by ControlSystem.
- getId(): allows for future multiplayer implemetation
Minion
Analogous to hero class.
Powerup
Similar to minion class.
Tile
Tile is slightly different than the other elements of GameObject & Collider, because it doesn’t move.
- tileId: (To be updated)
- index: the “id” of the specific region of a tile source file; this is for rendering the correct tile piece
- tileType: whether it is ground or not
Menu:
Menu is a layer to display current content. It is an abstract base class.
enum MENU_MESSAGE{
MENU_NONE = 1,
MENU_QUIT = 2,
MENU_RETURN = 3
};
virtual bool loadMedia();
virtual MENU_MESSAGE accept();
virtual void show();
virtual void destroy();
virtual void render();
MainMenu
- Constructor: call init() and loadMeadia()
- init(): create button for each option, set button position, add button to button map (To be updated: mouse out, hover, down, up)
- loadMedia(): load texture (To be updated: stringstream)
- accept(): (To be updated)
- label: (To be updated)
- render(): render button then render label
- show(): a loop to determine SDL_event; will jump to other menu(interface/layer); then call render()
InstructionMenu
Similar to MainMenu class, but simpler because there are less chocies of what menus it can jump to.
PassMenu
Even simpler than InstructionMenu because PassMenu represents the passing scene of the game (i.e., level 1 passes; now click to play level 2).
PauseMenu
Similar to other menus.
SettingsMenu
Similar to other menus.
WinMenu/LoseMenu
A scene to display win/lose message. Similar to other menus.
System
All systems use singleton design pattern. Only one instance is necessary to function well.
CollisionSystem
The core of this game. (To be updated: 800+ lines of code)
ControlSystem
(To be updated)
DisplaySystem
Init SDL library and then loadMedia() using ResourceManager. The main function is to render game objects (i.e., hero, minions, bullets, etc), menus (differnet scenes), and game info (i.e. current level, life, etc).
- update(): (To be updated: invoke TileMapSystem)
- updateMapTexture(): different cases on what current level is, so different map can be aquired accordingly
GameSetting
GameSetting is a container of the “game data”, such as levels, score, minions. (To be updated)
PlaySystem
For now I will say PlaySystem monitors the state of the game. The hero status, minion status, and other interactive game components will get updated, but this update doesn’t involve collision. The game status will be checked (win/lose).
ResourceManager
Load resources including textures, videos and audios from files.
- Also loads languages
- tile maps
SoundSystem
Render music and sound effects.
TileMapSystem
(To be updated)
Other/Utilities:
Camera
Also a singleton class. The camera always focuses on the hero. (To be updated)
CAnimation
CAnimation only takes care of calculating the correct frame and then the other system (To be updated) can render correct pose from spritesheet.
Collision
(To be updated) Handle collisions between GameObject and Tile.
LButton
A wrapper class for SDL_Button.
- handleEvent(SDL_Event* e): check whether this button is clicked and then invoke relative actions
- (To be updated)
LTimer
A timer used for keep trakcing of frame rate.
LTexture
A wrapper class for SDL_Texture. (To be updated)
MainProgram
Singleton design pattern is used becasue there is only main program. It has init(), loop(), and run().
- init(): init ResourceManager, GameSetting, ControlSystem, PlaySystem, CollisionSystem, then DisplaySystem
- run(): play bgm and then loop()
- loop():
- start timer
- monitor events
- update CollisionSystem, PlaySystem, Camera, and last DisplaySystem
- check win/lose
TileMap
(To be updated)
Vector2D
A small 2D vector “math library” which allows for basic vector operations. It may also serves as a tuple for any two-component variables, such as velocity, position, etc.