Running your game
Given the fairly extensive configuration done before this point, it makes it now makes it fairly trivial to run your game from a single configuration file.
A first step in starting the game is, just like you would with pygame is calling init of PG_Engine, it will handle the registration of all built in or otherwise provided engine parts, gameobject components and other code that may need registration as well as calling pygame.init().
import pg_engine
pg_engine.init()
Next is loading your game’s configuration into memory and building up a gameinstance in a state before the gameloop starts running. here GameConfigLoader will be orchestrating the loading of all engine parts and game components as well as creating instances where necessary.
import pg_engine
from pg_engine.core import GameConfigLoader
import pathlib
pg_engine.init()
config_root = pathlib.Path(__file__).parent
GameConfigLoader(
filename='config/config.yml',
root=config_root,
).load()
Last we just need to start the game.
import pg_engine
from pg_engine.core import GameConfigLoader, TGame
pg_engine.init()
config_root = pathlib.Path(__file__).parent
GameConfigLoader(
filename='config/config.yml',
root=config_root,
).load()
TGame().run()
pg_engine.quit() # cleaning up like responsible developers
If your IDE has a type checker active it may complain that TGame is an abstract class. Under normal circumstances an abstract class cannot be instantiated.
Instead TGame() stands in a proxy for the game instance type you defined in Game Instance Configuration (we used BaseGame in this tutorial). This is possible due to the singleton nature of TGame which lets it skip normal instantiation in favor of an existing instance.
Hint
If you prefer using literal Singleton access the following code is also valid, though PG_Engine liberally makes use of the version above.
from pg_engine.core.bases import TGame, Singleton
game: TGame = Singleton.get('Game')
game.run()
If your game uses collisions, configuration of collision layers has not yet been implemented and must be enabled before your game starts running (though it is technically still possible to enable them at runtime). Bot layers in enable_collision() are interchangeable and each unique enabled combination must therefore only be registered once. Collision layers may collide with themselves and will ignore gameobjects colliding with themselves.
TGame().system_controller.collision_system.enable_collision(
'collision_layer_1',
'collision_layer_2'
)
TGame().run()
pg_engine.quit() # cleaning up like responsible developers
Note
hot reloading is not supported, though everything from standard pygame still applies.