Skip to main content

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.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

# 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)

Transitions -- Example // Showcase

# 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

Utility functions

# 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


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.3.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

pygamepal-0.1.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file pygamepal-0.1.3.tar.gz.

File metadata

  • Download URL: pygamepal-0.1.3.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pygamepal-0.1.3.tar.gz
Algorithm Hash digest
SHA256 472b53569386f1194d486cedfbb282d42a4e57f55daafbe96d6ad1e24b2e7fe4
MD5 8cea73a6f952825cfbbc9be47ec02e90
BLAKE2b-256 87ee94e25e5b90adf7de9ec81d24682090dd550724565de0593e08d663393981

See more details on using hashes here.

File details

Details for the file pygamepal-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pygamepal-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for pygamepal-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5b78820f9904e5b154a967933ec82a1e328df88e10c0959990f3b98ab4e4dc90
MD5 afe4da6963665f2b69b172b5c24c43bf
BLAKE2b-256 908543940d87ab0da2b16ee19024b3005d24818f9829fc04e6a255eaa378a428

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page