A pygame engine for common game operations like vector math and maintaining events in the game loop
Project description
Game Utils
0.1.2
game-utils is a pygame engine. The engine includes modules to facilitate boilerplate game operations.
Requirements
Dependences:
- pygame
- numpy
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!")
See Also...
My ongoing game projects
- Madmadam Games gitlab
Project details
Release history Release notifications | RSS feed
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.1.2.tar.gz
(11.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file game_utils-0.1.2.tar.gz.
File metadata
- Download URL: game_utils-0.1.2.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc686d5648254f4a95f01c2e1fb172c04454f7b4f19c1e2f5b6b193b4eba2bbf
|
|
| MD5 |
1920ab889959dba9a45e679749fd1157
|
|
| BLAKE2b-256 |
c1f5d04993d8d7e2d9b3488befe289af408ef02ed238b932b7043512a9dfec00
|
File details
Details for the file game_utils-0.1.2-py3-none-any.whl.
File metadata
- Download URL: game_utils-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4ec095e5695e3940cf08f9e5bc832daedbf4ab1d9f5174e2607416a2f3a0022
|
|
| MD5 |
9f25358a53112e807584d5afb53124a7
|
|
| BLAKE2b-256 |
11fd315a64a1d0cb3af2946451d28c625bd3821ebad5857f86b9580fde77e606
|