Skip to main content

A pygame engine for common game operations like vector math and maintaining events in the game loop

Project description

Game Utils

0.2.1

game-utils is a pygame engine. The engine includes modules to facilitate boilerplate game operations.

Requirements

Dependences:

  • pygame
  • numpy
  • click

Example usage

from game_utils.game import Game
import pygame

class MyAwesomeGame(Game):
    def __init__(self, player_speed: int, screen_settings: Game.ScreenSettings):
        super().__init__(screen_settings)

        # Where, and how big, to draw the player.
        # I like to scale things by the screen size.
        self.player_radius = self.screen_settings.height / 4
        self.player_rect = pygame.Rect(
            self.screen_settings.height / 2 - self.player_radius,
            self.screen_settings.width / 2 - self.player_radius,
            self.player_radius * 2,
            self.player_radisu * 2,
        )
        self.player_speed = player_speed

    def _update_screen(self):
        self.screen_settings.screen.fill(
            self.screen_settings.bg_color or "dodgerblue2"
        )

        pygame.draw.circle(
            self.screen_settings.screen,
            "lightseagreen",
            self.player_rect.center,
            self.player_radius
        )

    def _update(self):
        # any other game logic...
        # This came from a tutorial I found on custom events...
        pressed_keys = pygame.key.get_pressed()
        up, down, left, right = map(
            lambda key: key * self.player_speed,
            [pressed_keys[key] for key in [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]] 
        )

        self.player_rect.move_ip((-left + right, -up + down))

if __name__ == "__main__":
    # these could also come from a config file
    game = MyAwesomeGame(
        player_speed=10,
        screen_settings=Game.ScreenSettings(
            bg_color="coral2",
            width=600,
            height=400
        )
    )

    print("Starting game...")
    game.run()
    print("Thanks for playing!")

Toolkit

Packaging

These are tools for various packaging strategies for your game

Example:

python -m game_utils.toolkit package batocera

Executing this will package your pygame/game-utils game for playing on Batocera pygame ports


See Also...

My ongoing game projects

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

game_utils-0.2.1.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

game_utils-0.2.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file game_utils-0.2.1.tar.gz.

File metadata

  • Download URL: game_utils-0.2.1.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for game_utils-0.2.1.tar.gz
Algorithm Hash digest
SHA256 df29cd2e2092c0ad2042fab47916fc838eb1e3379c42283c39c5b3e35cfb8a39
MD5 aa028565aedae2ba94aae3c4d0f5c7a9
BLAKE2b-256 4bdbefc254db6c7147cc8f56564b8a9e7d4d123f845dd2e0b96de7f772bdc76f

See more details on using hashes here.

File details

Details for the file game_utils-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: game_utils-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for game_utils-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b50db491f678c2e2793aeb0aed1f9c97151e704d7602a3c444f07ea5d4104153
MD5 a42bcf308656169c539293a32a33bfc3
BLAKE2b-256 57f7c3aa42f61508fc5ffba771225dc9b36da9fd492926230e23f46517339ef7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page