A library of classes and helper functions to support game development in Pygame
Project description
- (Note: I'm also developing the Gamma Pygame ECS engine!)
- Add suggestions and bugs here!
pygamepal
A library of classes and functions to support game development in Pygame
Usage
-
pip install pygamepal
-
Full example, using all pygamepal classes
Contents
Game (create a game with minimal setup) -- Template // Example
Input -- Example
# create new instance
input = pygamepal.Input(longPressDuration=60)
# update() must be called once per frame
input.update(deltaTime=1)
input.isKeyDown(keycode)
input.isKeyPressed(keycode)
input.isKeyReleased(keycode)
input.getKeyDownDuration(keycode)
input.isKeyLongDown(keycode)
input.isKeyLongPressed(keycode)
input.getKeyLongPressPercentage(keycode)
SpriteImage -- Example
# create new instance
spriteImage = pygamepal.spriteImage()
# add one or more sprites, associated with a state
spriteImage.addTextures(firstTexture, *moreTextures, state=None, animationDelay=12, loop=True, hFlip=False, vFlip=False)
# update() must be called once per frame
spriteImage.update()
# draw the current image/animation frame
spriteImage.draw()
# change the current image/animation state
# (does not need to be called for sprite with single state)
spriteImage.setState(state)
# resets the current animation
spriteImage.reset()
spriteImage.pause
Camera -- Example
# creates a new camera instance
camera = pygamepal.Camera(position=(0, 0), size=(640, 480), target=(0, 0), zoom=1, backgroundColour='gray30', borderColour='black', borderThickness=2, clamp=False, clampRect=(0, 0, 1000, 1000), followDelay=0)
# update() must be called once per frame
camera.update(deltaTime=1)
# draws surface to the destinationSurface, using camera attributes
camera.draw(surface, destinationSurface)
# draws text with minimal required parameters
drawText(screen, text, x, y, font=None, antialias=True, colour=White, background=None)
# minimal example:
drawText(screen, 'Hello, world!')
# returns a list of sub-textures from a large spritesheet/texture
# the list has the same dimensions as the original texture, but
# can be flattened using flatten(2dList).
splitTexture(texture, newTextureWidth, newTextureHeight)
# simple example, splitting a single 96x32 spritesheet into 4 separate textures:
textureList = splitTexture(texture, 32, 32)
firstTexture = textureList[0][0] # or firstTexture = flatten(textureList)[0]
# flattens a 2d list into a single list
newList = flatten(2dList)
# see above for example
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
pygamepal-0.1.1.tar.gz
(20.2 kB
view details)
Built Distribution
File details
Details for the file pygamepal-0.1.1.tar.gz
.
File metadata
- Download URL: pygamepal-0.1.1.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c275c4796dab4a8f7f908a96c7afdf7ebda733562fafeb1fef3ea2f9d9017743 |
|
MD5 | 0caa589da39089ac8d954d57036575ee |
|
BLAKE2b-256 | b69b282f5b415e8088815d9284e0c870395c2cb88567da18d3635c3552531704 |
File details
Details for the file pygamepal-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: pygamepal-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26db62583706f807836756e842e9c3c27eb5c5c086796662b798a01c85230e94 |
|
MD5 | c2d0b13b996e3d9293b3109843446a12 |
|
BLAKE2b-256 | 27341fbca8dfe9712227f6bee65af1eaedfefc5ee5bc69a07e4143254caf6312 |