Last active
August 29, 2015 14:16
-
-
Save VoX/83409194b874c562a5f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
So at a high level you game looks like this | |
Main | |
gameEngine = GameEngine() | |
renderEngine = RenderEngine() | |
baseSurface = Display.get_surface; | |
while 1 | |
pygame.FpsLockThingIforgetTheName(60) | |
gameEngine.Step() | |
renderEngine.Render(baseSurface, gameEngine) | |
GameEngine contains top level game objects so it may look like | |
GameEngine | |
Character | |
HP | |
Pos | |
ItemList | |
Name | |
Damage | |
Owner | |
Pos | |
SpellList | |
Name | |
Damage | |
CooldownCost | |
CooldownLeft | |
Caster | |
Target | |
EnemyList | |
HP | |
Pos | |
Map | |
Name | |
TileList | |
Passable | |
Pos | |
Step() | |
SpellBehavior() | |
EnemyBehavior() | |
CharacterBehavior() | |
Then you have your RenderEngine object which examines the GameEngine object and renders the current state of the game. It gets hard | |
because pygame makes it seem like you need to bind a particular sprite to a particular game object. But this isn't true, you can make | |
pools of each different type of sprite and just use any sprite from the pool to render a game object. This is actually more efficient | |
too because rather then newing up a sprite for each bullet you fire you just reuse the same ones from the pool. It may look like | |
RenderEngine | |
CharacterSprite | |
EnemySpritePool | |
FireballSpellSpritePool | |
SwordSpritePool | |
MapTileSpritePool | |
CurrentMap | |
SpriteLayer | |
UILayer | |
MapLayer | |
Render(baseSurface, gamestate) | |
if(gamestate.Map.Name != CurrentMap) | |
MapLayer = renderMap(gamestate.Map) | |
CurrentMap = gamestate.Map.Name | |
UILayer = renderUI(gamestate) | |
SpriteLayer = renderSprites(gamestate) | |
blitLayers(baseSurface, SpriteLayer, UILayer, MapLayer) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment