Skip to content

Player (Spieler) API

Player (Spieler) API Reference

The Spieler class controls player physics, movement, and collision detection against Platform objects.

Module Location

from skeletons.spieler import Spieler

Overview

Spieler handles:

  • Horizontal movement and jumping
  • Gravity and falling speed limits
  • Collision resolution with platforms
  • Checkpoints and respawn logic

Constructor

Spieler(player_pos, dt, radius=24)

Parameters:

NameTypeDefaultDescription
player_pospygame.Vector2-Shared player position vector
dtfloat-Delta time in seconds
radiusint24Legacy radius (kept for compatibility)

Attributes

AttributeTypeDescription
player_pospygame.Vector2Shared position vector
sprite_widthintCollision box width in pixels
sprite_heightintCollision box height in pixels
velocity_xfloatHorizontal velocity
velocity_yfloatVertical velocity
gravityfloatGravity acceleration
jump_strengthfloatJump impulse (negative)
accelerationfloatSlippery acceleration
max_speedfloatMax horizontal speed
max_fall_speedfloatMax vertical speed
frictionfloatCurrent friction coefficient
current_platformPlatformPlatform under player (if any)
is_on_groundboolGrounded state
prev_xfloatPrevious X position
prev_yfloatPrevious Y position

Methods

set_sprite_size(width, height)

Override collision box size to match sprite.


move_left() / move_right()

Move horizontally. Uses acceleration on slippery surfaces and direct movement otherwise.


jump()

Start a jump if grounded.


on_ground()

Return True if grounded.


apply_physics(dt)

Apply gravity, friction, and velocity updates.


get_rect()

Get the collision rectangle for the player.

Returns: pygame.Rect


check_platform_collision(platforms, adjacent_platforms=None)

Resolve collisions with solid platforms and update is_on_ground, current_platform, and friction.

Includes a broad-phase query step so only nearby platforms are tested in detail.

Parameters:

NameTypeDescription
platformsList[Platform]Platforms to check
adjacent_platformsList[Platform] | NoneOptional collision proxies from neighboring pages

check_special_platform_interactions(platforms, current_checkpoint)

Check for death/checkpoint platforms.

Returns: (new_checkpoint, should_respawn)


check_fell_off_screen(screen_height, current_checkpoint)

Respawn if the player fell below the screen.

Returns: True if respawned

Usage Example

from skeletons.spieler import Spieler
from skeletons.platform import Platform
player_pos = pygame.Vector2(100, 100)
player = Spieler(player_pos, dt=0)
# In game loop
player.apply_physics(dt)
player.check_platform_collision(platforms, adjacent_platforms)
checkpoint, respawn = player.check_special_platform_interactions(platforms, checkpoint)
if player.check_fell_off_screen(screen_height, checkpoint):
pass