Slide 1

Shining Force PC Code Overview
[email protected]
http://kenhilfportfolio.blogspot.com
SFPC – GameObject Class
• The core base class of SFPC.
GameObject
Local Position
World Position
std::vector of Child GameObjects
Draw()/DoDraw()
Update()/DoUpdate()
ProcessInput()
• Derived classes use at least one but
usually many of the features of
GameObject.
• GameObjects can have child objects;
children base their positions upon the
positions of their parents
SFPC – GameObject Class
GameObject
Local Position
World Position
std::vector of Child GameObjects
Draw()/DoDraw()
Update()/DoUpdate()
ProcessInput()
• When Draw() is called, first the
object’s own DoDraw() function is
processed, which is where the actual
drawing takes place, then the object
iterates through any children it has and
calls their Draw() functions.
• The process repeats itself until every
child at every leaf of the tree has been
drawn.
SFPC – GameObject Class
GameObject
Local Position
World Position
std::vector of Child GameObjects
Draw()/DoDraw()
Update()/DoUpdate()
ProcessInput()
• The same model applies to the
Update() and DoUpdate() functions.
GameObjects that animate or change
over time update their states with time
measured in ticks (ms).
• ProcessInput() applies to the current
object only and does not call child
ProcessInput() functions.
Inheritance
Relationships
GameString: Draw,
Position
GameWindow: Update,
Draw, ProcessInput, and
Position
GameObject
DialogueWindow: Update,
Draw, ProcessInput, and
Position
ActionMenu: Update,
Draw, ProcessInput, and
Position
Actor: Update, Draw,
Position
TileMap: Update Only
(Drawing this is a Special
Case)
Camera: Update,
ProcessInput
The inheritance hierarchy
of the most common
GameObjects and which
features of the base class
each uses.
SFPC – GameString Class
GameString: Draw,
Position
GameObject
GameWindow: Update,
Draw, ProcessInput, and
Position
ActionMenu: Update,
Draw, ProcessInput, and
Position
• Basic class for rendering
strings with bitmapped fonts.
• GameStrings can be used as
stand alone objects and are
also frequently used as child
objects by other classes.
• Actor uses GameString to
show debug info: Actor’s
position and Land Effect
SFPC – GameString Class
• TileMapEditor uses them to
show editing info since a using
a full GameWindow would
obscure part of the screen
• GameWindows of course
contain child GameStrings and
use them to display their text.
SFPC – GameString Class
• DialogueWindows are
specialized GameWindows that
draw in their text one letter at
a time.
• ActionMenus make use of
GameWindow children to show
the text of the currently
selected choice.
SFPC – GameObjectMgr Class
GameObjectMgr
A separate std::vector of
GameObjects for each
LayerSpace
List of Actors
List of GameWindows
Stack of Focus objects
AddObject (overloaded)
RemoveObject
Update()
Draw()
special Get functions
Focus functions
• A singleton class that stores, manages,
and grants access to all active
GameObjects
• All GameObjects also have a LayerSpace
attribute. When an object is added to
GameObjectMgr with AddObject, it is
slotted into the std::vector of GameObjects
that corresponds to its LayerSpace.
SFPC – GameObjectMgr Class
GameObjectMgr
A separate std::vector of
GameObjects for each
LayerSpace
List of Actors
List of GameWindows
Stack of Focus objects
AddObject (overloaded)
RemoveObject
Update()
Draw()
special Get functions
Focus functions
• LayerSpace ensures objects are drawn in
the correct order regardless of what order
they were added to GameObjectMgr.
• Overloaded AddObject functions watch
for special GameObjects. For example,
Actors are also added to the ActorList,
GameWindows are tracked in the
GameWindowList, so that these objects
can be accessed from other places in the
program when necessary.
SFPC – GameObjectMgr Class
GameObjectMgr
A separate std::vector of
GameObjects for each
LayerSpace
List of Actors
List of GameWindows
Stack of Focus objects
AddObject (overloaded)
RemoveObject
Update()
Draw()
special Get functions
Focus functions
• The GameObject at the top of the stack of
Focus objects has its ProcessInput function
called at the end of GameEngine’s
ProcessInput phase.
• Camera sits at the bottom of the stack
and directs the Actor it is following to move
when the arrow keys are pressed.
SFPC – GameObjectMgr Class
GameObjectMgr
A separate std::vector of
GameObjects for each
LayerSpace
List of Actors
List of GameWindows
Stack of Focus objects
AddObject (overloaded)
RemoveObject
Update()
Draw()
special Get functions
Focus functions
•While a DialogueWindow has focus, the
player cannot move the active character
until the window is closed and the Camera
regains focus.
• Several different ActionMenus may be on
the stack at once, if the player backs out of
one, it is popped from the stack and the
previous one will come back onto the
screen and will automatically have focus.
SFPC – TileMap Class
TileMap
2D Array of TileInfo:
Solid, Actor at this Pos,
Terrain Type
Three TileMapLayers
• TileMap holds all the data about a
given map
• TileMapLayers hold indexes to the
individual tiles that graphically make
up the map stored in a Tileset class
• TileMap class has three
TileMapLayers: Background,
Overlay, and Foreground.
• Actors walk over top of the
Background and Overlay layers, but
underneath the Foreground layer.
SFPC – GameObjectMgr::Draw Loop
• TileMap is drawn one layer at a time, followed by the
corresponding objects in that LayerSpace, if any.
• Actors can walk on any layer, but are drawn in Overlay by
default.
TileMap
TileMapLayer
Background
TileMapLayer
Overlay
TileMapLayer
Foreground
GameObjectMgr
GameObjectMgr
GameObjectMgr
Background
LayerSpace
GameObjects
Overlay
LayerSpace
GameObjects
Foreground
LayerSpace
GameObjects
GameObjectMgr
Window LayerSpace
Background
GameWindows
LayerSpace
DialogueWindows
SFPC – TileMap::CalculateWalkable
• Combat style movement
• CalculateWalkable recursively
crawls across the map from the
active Actor’s current position.
• Calculates if the current tile is
within range based on the amount
of Movement the Actor has left and
the Land Effect of that tile.
SFPC – TileMap::CalculateWalkable
• Each Actor has a TerrainWalker
type. Some types do better on
some terrain but worse in others.
• Flyers ignore Land Effect when
moving.
• Tiles that are in range this turn
flash white using DrawMgr’s
blending code.
SFPC – DrawMgr Class
• Wraps up OpenGL calls to glTexCoord2f(), glVertex2i, and
glColor4f.
• Features Global and One Time tinting, blending, and fading of
any and all textures.
• DrawQuad function can draw relative to the Camera or the
Screen, and can flip, mirror, scale, and stretch any texture.