Engines
During quest.game.QuestGame.on_update(), a Physics Engine is used to
update all the sprites’ positions. Generally, a physics engine implements a
set of rules for movement.
If you want to explore other possibilities,
the Arcade Library provides a number of physics engines
such as arcade.PhysicsEngineSimple (which keeps the player from
bumping into walls) and arcade.PhysicsEnginePlatformer (which
implements gravity, allows the player to jump, and lets the player rest on
platforms, like in Mario.)
- class quest.engines.QuestPhysicsEngine(game)[source]
Base class for Quest Physics Engines
The engine is initialized with a
QuestGameinstance, which the engine uses to access sprites. Quest’s physics engines make some assumptions about the structure of a game in order to simplify logic. It is assumed that the game has attributes player_list, wall_list, and npc_list. Players and NPCs will be moved according to their change_x and change_y attributes; walls will not move. When players or NPCs collide with walls, they are pushed back until they are no longer colliding. When players or NPCs collide with each other, their on_collision methods are called, but they are not automatically repelled. If you want players or NPCs to be repelled from each other, seequest.examples.grandmas_soup.Grandma.- Parameters
game (QuestGame) – The game to which the engine will be attached.
- class quest.engines.ContinuousPhysicsEngine(game, **kwargs)[source]
A continuous physics engine allows sprites to be at any point.
This implementation is simple but inefficient. It may be problematic with more complex games. If we run into trouble, first try using spatial hashes to resolve collisions.
- update_sprite_positions()[source]
Updates sprite positions using their change_x and change_y attributes.
- resolve_sprite_wall_collision(sprite, wall)[source]
Stops the sprite and backs it away from the wall until they are no longer colliding.
The distance by which the sprite backs up doubles until they are no longer colliding. Note that this does not handle the case in which backing away from one wall means it hits another wall (e.g. in a narrow passageway). This will be handled on the subsequent update. We can write more complex code if it becomes necessary.
- class quest.engines.DiscretePhysicsEngine(game, grid_map_layer, diagonal=True, check_for_new_sprites=True, **kwargs)[source]
A physics engine which snaps sprite movement to specific gridpoints.
Some games work better when sprites occupy specific tiles, rather than having continuous positions. This can make it easier to think about relationships between sprites (for example, to calculate which are adjacent, or to plan a route).
DiscretePhysicsEnginehandles sprite movement in a discrete way, while animating sprites’ transitions from tile to tile.- Parameters
player_sprite (arcade.Sprite) –
dynamic_sprite_lists (bool) – Whether new sprites might be added to sprite lists during the game. Performance is better when False. Default True.
- tile_transition_cutoff = 0.5
- easing_class
alias of
easing_functions.easing.LinearInOut