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 QuestGame instance, 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, see quest.examples.grandmas_soup.Grandma.

Parameters

game (QuestGame) – The game to which the engine will be attached.

update(game)[source]

waits for implementation from a more complex physics engine like py:class:ContinuousPhysicsEngine

player()[source]
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()[source]

Updates sprite positions and handles collisions.

update_sprite_positions()[source]

Updates sprite positions using their change_x and change_y attributes.

resolve_collisions_with_walls()[source]

Resolves collisions between every sprite and every wall.

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.

resolve_collisions_between_nonwalls()[source]

For every pair of nonwall sprites, resolves collisions.

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). DiscretePhysicsEngine handles 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

update()[source]

waits for implementation from a more complex physics engine like py:class:ContinuousPhysicsEngine

begin_move(sprite)[source]
continue_move(sprite)[source]
end_move(sprite)[source]
get_wall(sprite_list)[source]
interpolate(p0, p1, t)[source]
ease(x)[source]
ensure_sprite_metadata(all_sprites=False)[source]