No project description provided
Project description
Pygskin
A collection of useful functions and classes for Pygame
animate function
Animation generator function which takes a list of frames or mapping of quotients (0.0 - 1.0) to keyframes and a function that returns a quotient, and returns an generator that returns frames.
anim = animate([image1, image2], timer.quotient)
screen.blit(next(anim), (0, 0))
TODO
- Support
durationandloop_countarguments -
senddelta time to the generator?
Assets class
Provides attribute access to asset files and batch loading
assets = Assets()
screen.blit(assets.player, (0, 0))
assets.player_spawn_sfx.play()
TODO
- Wrap all assets with
LazyObjectto avoid loading assets at import time
Timer class
A countdown timer dataclass. Can be used with the animate function.
timer = Timer(3000) # 3 seconds
timer.tick()
if timer.finished:
timer.elapsed = 0 # loop
iter_dialogue function
Generator function for stepping through a dialogue script parsed from a JSON or YAML file.
context = {}
dialogue = iter_dialogue(
assets.act1_scene1,
context,
speak=speak,
)
def main_loop(screen, events, quit):
if action := next(dialogue, None):
action()
Direction enum
Enum for up/down/left/right directions
direction = Direction.UP
if direction in Direction.VERTICAL:
rect.move_ip(direction.vector)
easing module
A selection of easing functions for use with interpolation. Can be used with the
animate function.
get_ecs_update_fn function
An extremely simple ECS implementation.
@filter_entities(has_velocity)
def apply_velocity(entity):
entity.pos += entity.velocity
ecs_update = get_ecs_update_fn([apply_velocity])
@dataclass
class Entity:
pos: Vector2
velocity: Vector2
ecs_update([Entity(pos=Vector2(0, 0), velocity=Vector2(1, 1)])
bind function
Partial function application with one or more argument placeholders at arbitrary positions.
foos = filter(bind(isinstance, ..., Foo), items)
run_game function
Pygbag compatible game loop.
def main_loop(screen, events, quit):
screen.fill(random.choice(pygame.color.THECOLORS.values()))
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE:
quit()
if __name__ == '__main__':
run_game(Window("My Game", (WIDTH, HEIGHT)), main_loop)
make_color_gradient function
Generate a color gradient between two colors.
sky_image = make_color_gradient(screen.size, "white", "blue")
screen.blit(sky_image, (0, 0))
rhash/unrhash functions
Simple reversible hash function for generating unique IDs.
id = rhash("foo")
assert unrhash(id) == "foo"
imgui module
Immediate mode GUI.
gui = imgui.IMGUI()
def main_loop(screen, events, quit):
with imgui.render(gui, screen) as render:
if render(imgui.button("Quit"), center=(100, 200)):
break
TODO
- More widgets
- Layouts
LazyObject class
Lazy loading object proxy.
image = LazyObject(lambda: pygame.image.load("foo.png"))
screen.blit(image, (0, 0))
scroll_parallax_layers function
Scroll parallax layers at different rates.
background = LayeredUpdates()
background.add(assets.sky, layer=0)
background.add(assets.mountains, layer=1)
background.add(assets.trees, layer=2)
scroll_parallax_layers(
(vx, vy),
background.layers,
background.get_sprites_from_layer,
{0: 0, 1: 1.5, 2: 2.0},
)
channel function
Simple pubsub implementation.
foo = channel()
foo.subscribe(lambda x: print(f"subscriber 1: {x}"))
foo("bar")
get_rect_attrs function
Filter rect attributes (eg top, center, size) from a dictionary. Useful
for passing kwargs to pygame.Rect.move_to or pygame.Surface.get_rect.
def foo(image: Surface, **kwargs):
image_rect = image.get_rect(**get_rect_attrs(kwargs))
add_padding function
Add padding of varying amounts to a Rect.
rect = add_padding(Rect(0, 0, 10, 10), [100, 50, 10, 5])
assert rect.size == (120, 65)
screen_manager function
Screen manager state machine.
def main():
return screen_manager(
{
show_title: [start_level, enter_level_code],
show_code_prompt: [start_level, return_to_titles],
play_level: [end_level],
show_game_over: [return_to_titles],
}
)
def show_main_menu(surface, events, screen_manager):
surface.blit(assets.main_menu, (0, 0))
for event in events:
if event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN:
screen_manager.send("start_level")
if event.type == pygame.KEYDOWN and event.key == pygame.K_c:
screen_manager.send("enter_code")
def start_level(input):
return play_level if input == "start_level" else None
def enter_level_code(input):
return show_code_prompt if input == "enter_code" else None
TODO
- Transition animations (fade in/out, slide, wipe, etc)
- Less clunky transition functions
Spritesheet class
Provides item access to a spritesheet image where sprites are arranged in a grid.
spritesheet = Spritesheet("foo.png", rows=3, cols=4))
screen.blit(spritesheet[(2, 1], (0, 0))
walk_frames = [spritesheet[(0, i)] for i in range(4)]
walk_anim = animate(walk_frames, timer.quotient)
TODO
- Slice support for ranges
statemachine function
State machine as generator.
get_styles function
Simple cascading style sheet engine. Filters styles by object type, class and id attributes.
stylesheet = {
"Button": {
"color": "black",
"background-color": "grey",
},
"Button#quit": {
"background-color": "red",
},
}
Button = namedtuple("Button", ["id"])
styles = get_styles(stylesheet, Button(id="quit"))
assert styles == {"color": "black", "background-color": "red"}
make_sprite function
Create a sprite from an image.
player = make_sprite(assets.player, center=player_pos)
rotate_surface function
Rotate a surface in place or around a specified point.
rotated_image = rotate_surface(image, angle, center=(0, 0))
to_snakecase and snakecase_to_capwords functions
Convert between snake_case and CapWords.
speech_duration function
Calculate rough speech duration in seconds.
tile function
Generate a blit sequence to tile an image across a surface.
screen.blits(tile(screen.get_rect(), assets.grass))
angle_between function
Calculate the angle between two points.
Other TODO
- Configurable controls
- Save / Load
- Network
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
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 pygskin-0.1.1.tar.gz.
File metadata
- Download URL: pygskin-0.1.1.tar.gz
- Upload date:
- Size: 18.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0efd07687fd6e8ec06196da60766535b7a12508e860500a4adb76bef9c0462f
|
|
| MD5 |
9d687a22ce2026d31864b0a7bb8044c3
|
|
| BLAKE2b-256 |
8e44c97ade8f8ea4a92eb3a75ec466aa8e0e8b2ee2c3aff2da52f4ca416d83ae
|
Provenance
The following attestation bundles were made for pygskin-0.1.1.tar.gz:
Publisher:
python-publish.yml on andyhd/pygskin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygskin-0.1.1.tar.gz -
Subject digest:
f0efd07687fd6e8ec06196da60766535b7a12508e860500a4adb76bef9c0462f - Sigstore transparency entry: 161709410
- Sigstore integration time:
-
Permalink:
andyhd/pygskin@088084aa04de89679d8185471d2cbc15e73c641a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/andyhd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@088084aa04de89679d8185471d2cbc15e73c641a -
Trigger Event:
release
-
Statement type:
File details
Details for the file pygskin-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pygskin-0.1.1-py3-none-any.whl
- Upload date:
- Size: 23.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75f74f3458468acac834bfd2651c03af8ab05fbd3437d109adf1222ffdb6927a
|
|
| MD5 |
640f9b4d58ac8357f3ae7af1c8fc24eb
|
|
| BLAKE2b-256 |
aa7409ab0f786e9236ba303a14284461bf3df13b4005c4906bc97bed80baf792
|
Provenance
The following attestation bundles were made for pygskin-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on andyhd/pygskin
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygskin-0.1.1-py3-none-any.whl -
Subject digest:
75f74f3458468acac834bfd2651c03af8ab05fbd3437d109adf1222ffdb6927a - Sigstore transparency entry: 161709411
- Sigstore integration time:
-
Permalink:
andyhd/pygskin@088084aa04de89679d8185471d2cbc15e73c641a -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/andyhd
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@088084aa04de89679d8185471d2cbc15e73c641a -
Trigger Event:
release
-
Statement type: