A library of classes and helper functions to support game development in Pygame
Project description
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
self.size = (x, y)
self.caption = 'text'
self.icon = pygame.image.load('imageURL')
self.fps = x
self.screen
self.gameTime
self.init()
self.update(gameTime)
self.draw()
self.quit()
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 // Showcase
# 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)
Particles -- Example
# creates a new particle emitter
particles = pygamepal.particles(
# emitter attributes
emitterPosition=(0, 0), emitterSize=(0, 0),
emitterLifetime=100,
emitterVelocity=(0, 0), emitterAcceleration=(0, 0),
emitterParticleDelay=200,
# particle attributes
particleVelocityMin=(-1,-1), particleVelocityMax=(1,1),
particleAccelerationMin=(0,0), particleAccelerationMax=(0,0),
particleLifetime=20,
particleSize=20,
particleSizeDecay=1,
# a list of colours
particleColors=None
)
# update() must be called once per frame
particles.update(deltaTime=1)
# call draw() once per frame to draw all particles
particles.draw(deltaTime=1)
Transitions -- Example // Showcase
Transition types:
- TransitionFade
- TransitionFadeToBlack
- TransitionWipeLeft
- TransitionWipeRight
- TransitionWipeUp
- TransitionWipeDown
- TransitionMoveLeft
- TransitionMoveRight
- TransitionMoveUp
- TransitionMoveDown
Easing functions
- linear
- bounceEaseOut
# creates a new transition instance
transition = pygamepal.TransitionFade(fromSurface=None, toSurface=None, duration=100, easingFunction=linear)
# update() and draw() should be called each game loop frame
transition.update(deltaTime=1)
transition.draw(surface)
# transition properties
transition.duration = x # number of frames (default) / game time in ms
transition.easingFunction = pygame.linear | pygame.bounceEaseOut
# draws text with minimal required parameters
drawText(screen, text, x, y, font=None, antialias=True, color='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.3.0.tar.gz
(2.6 MB
view details)
Built Distribution
pygamepal-0.3.0-py3-none-any.whl
(12.4 kB
view details)
File details
Details for the file pygamepal-0.3.0.tar.gz
.
File metadata
- Download URL: pygamepal-0.3.0.tar.gz
- Upload date:
- Size: 2.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e092ac2d73afe4693c93b067dd66a4156250c48f447c0f750cba2f090b16420 |
|
MD5 | cc20a5ba5c46dc22f3cff409e7061766 |
|
BLAKE2b-256 | 5394641e76840676b7a3c659ff763641c0950d03816586f28309d96ef68b20dd |
File details
Details for the file pygamepal-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: pygamepal-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c94f9720a2f4ca1c63fdcf5c126e217aeeb45692fdee7ac36f53ef64aed96816 |
|
MD5 | abbb6a37e9d9949fe4f5b6d1240826be |
|
BLAKE2b-256 | d09fe26234656a6c42009bbc04c4f99e0131a97feb4ccc0f48a7f7b789f53a37 |