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.
- Simple, beginner-friendly interface.
- Choose the bits you want to use, and continue to use Pygame for everything else!
Usage
pip install pygamepal
orpip install --upgrade pygamepal
- Full example, using lots of pygamepal functionality
Add suggestions and bugs here!
Contents
Game (create a game with minimal setup) -- Template // Example
# create new game subclass and instance
class MyGame(pygamepal.Game):
# add init(), update() and draw() methods
myGame = MyGame()
myGame.run()
# properties
self.size = (x, y)
self.caption = 'text'
self.icon = pygame.image.load('imageURL')
self.fps = x
self.screen
self.gameTime
self.events
# methods to create in subclass
self.init()
self.update(gameTime)
self.draw()
Input -- Key Example // Mouse Example
# create new instance
input = pygamepal.Input(longPressDuration=60, doublePressTimeout=30)
# update() must be called once per frame
input.update(deltaTime=1)
# key press methods
input.isKeyDown(keycode)
input.isKeyPressed(keycode)
input.isKeyDoublePressed(keycode)
input.isKeyReleased(keycode)
input.getKeyDownDuration(keycode)
input.isKeyLongDown(keycode)
input.isKeyLongPressed(keycode)
input.getKeyLongPressPercentage(keycode)
# mouse button methods
input.isMouseButtonDown(mouseButton)
input.isMouseButtonPressed(mouseButton)
input.isMouseButtonDoublePressed(mouseButton)
input.isMouseButtonReleased(mouseButton)
input.getMouseButtonDownDuration(mouseButton)
input.isMouseButtonLongDown(mouseButton)
input.isMouseButtonLongPressed(mouseButton)
input.getMouseButtonLongPressPercentage(mouseButton)
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(
self, position = (0, 0), size = (640, 480),
target = (0, 0),
# follow delay is a (clamped) value between
# 0 (instant snap to target) and 1 (no movement)
lazyFollow = 0,
# passed value for 'zoom' will be clamped
# between 'minZoom' and 'maxZoom' values
zoom = 1, minZoom = 0.1, maxZoom = 10,
# zoom follow delay is a (clamped) value between
# 0 (instant zoom) and 1 (no zoom)
lazyZoom = 0,
backgroundColour = 'gray30',
borderColour='black', borderThickness = 2,
clamp = False, clampRect = (0, 0, 1000, 1000)
)
# 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=5,
# particle attributes
particleVelocityMin=(-1,-1), particleVelocityMax=(1,1),
particleAccelerationMin=(0,0), particleAccelerationMax=(0,0),
particleLifetime=100,
particleSize=20,
particleSizeDecay=0.2,
particleColors=None
)
# update() must be called once per frame
particles.update(deltaTime=1)
# call draw() once per frame to draw all particles
particles.draw(surface)
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 = pygampal.bounceEaseOut
Triggers -- Example
# creates a new trigger
# -- onCollide is executed every frame that this trigger collides with another
# -- onEnter is executed once on collision
# -- onExit is executed once when triggers are no longer colliding
# -- these functions should be of the form, e.g.:
# -- def onEnter(thisTrigger, otherTrigger):
# -- [add code here]
trigger = pygamepal.Trigger(x=0, y=0, w=10, h=10, onEnter=None, onCollide=None, onExit=None)
# update() must be called once per frame
trigger.update(deltaTime=1)
# you can call draw() to see triggers
trigger.draw(screen)
Buttons -- Example
# create a new button
button = pygamepal.Button(
# input is not optional
input,
position = (0,0), size = (100,50),
label = None,
fgColor = 'white', bgColor = 'black',
borderWidth = 1,
borderColor = 'white',
image = None,
# this method called when highlighted
onHighlighted = None,
# this method is called when selected
onSelected = None,
# updateMethod and drawMethod give the ability
# to override default button befaviour
updateMethod = None,
drawMethod = None,
# a keycode can also be associated with a button
# (only works if pygamepal.input is specified)
keyCode = None
)
# call update() and draw() each frame
button.update(deltaTime = 1)
button.draw(screen)
# if creating your own update method, you
# may want to use the following methods
# to set the button state
self.setHighlighted()
self.setSelected()
# if creating your own draw method, you
# may want to use the following methods
# to draw the button components
self.drawBackground(screen)
self.drawImage(screen)
self.drawText(screen)
self.drawBorder(screen)
# 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.5.2.tar.gz
(14.4 MB
view details)
Built Distribution
pygamepal-0.5.2-py3-none-any.whl
(22.8 kB
view details)
File details
Details for the file pygamepal-0.5.2.tar.gz
.
File metadata
- Download URL: pygamepal-0.5.2.tar.gz
- Upload date:
- Size: 14.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7400940d7e161fb384f2f1cc1b73f1cb1b05c63f7acf290fd2013717fc7e2078 |
|
MD5 | ee2be4811d306344d4e270f0068d0e5b |
|
BLAKE2b-256 | 7376751b0419292a88c7c359599d3a169bf7d3777cad1de7ab593c4753903658 |
File details
Details for the file pygamepal-0.5.2-py3-none-any.whl
.
File metadata
- Download URL: pygamepal-0.5.2-py3-none-any.whl
- Upload date:
- Size: 22.8 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 | f0149834add872020c05b1424d533c141916a8684bd87d12195876844b8b9110 |
|
MD5 | 00ed8d002f800018e335d4a5fa63a04d |
|
BLAKE2b-256 | 0375af63b2a417b3b3ad7ac15c5dd4af97aa002a6bba6351eee7d71a83fb4f2d |