Phil's pyGame Utilities Documentation

Overview

Scripts
tileedit | leveledit | tganew | levelfancy

Reference
algo | ani | engine | fonts | high | html | layout | text | timer | vid

Tutorials
1 | 2 | 3 | 4 | 5

GUI Ref.
theme | style | widget | surface | const

Containers
container | app | table | document | area

Forms
form | group

Widgets
basic | button | input | keysym | slider | select | misc

Other
menus | dialog

Tutorials
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10

vid

sections
Sprite
Sprite.setimage
Tile
Vid
Vid.resize
Vid.set
Vid.get
Vid.paint
Vid.update
Vid.tga_load_level
Vid.tga_save_level
Vid.tga_load_tiles
Vid.load_images
Vid.run_codes
Vid.string2groups
Vid.list2groups
Vid.groups2list
Vid.loop
Vid.screen_to_tile
Vid.tile_to_screen
Sprite and tile engine.

[[tilevid]], [[isovid]], [[hexvid]] are all subclasses of this interface.

Includes support for:

  • Foreground Tiles
  • Background Tiles
  • Sprites
  • Sprite-Sprite Collision handling
  • Sprite-Tile Collision handling
  • Scrolling
  • Loading from PGU tile and sprite formats (optional)
  • Set rate FPS (optional)

This code was previously known as the King James Version (named after the Bible of the same name for historical reasons.)

Sprite

The object used for Sprites.
Sprite(ishape,pos)
ishape

an image, or an image, rectstyle. The rectstyle will describe the shape of the image, used for collision detection.

pos

initial (x,y) position of the Sprite.

Attributes
rect

the current position of the Sprite

_rect

the previous position of the Sprite

groups

the groups the Sprite is in

agroups

the groups the Sprite can hit in a collision

hit

the handler for hits -- hit(g,s,a)

loop

the loop handler, called once a frame

Sprite.setimage

Set the image of the Sprite.
Sprite.setimage(ishape)
ishape

an image, or an image, rectstyle. The rectstyle will describe the shape of the image, used for collision detection.

Tile

Tile Object used by TileCollide.
Tile(image=None)
image

an image for the Tile.

Attributes
agroups

the groups the Tile can hit in a collision

hit

the handler for hits -- hit(g,t,a)

Vid

An engine for rendering Sprites and Tiles.
Vid()
Attributes
sprites

a list of the Sprites to be displayed. You may append and remove Sprites from it.

images

a dict for images to be put in.

size

the width, height in Tiles of the layers. Do not modify.

view

a pygame.Rect of the viewed area. You may change .x, .y, etc to move the viewed area around.

bounds

a pygame.Rect (set to None by default) that sets the bounds of the viewable area. Useful for setting certain borders as not viewable.

tlayer

the foreground tiles layer

clayer

the code layer (optional)

blayer

the background tiles layer (optional)

groups

a hash of group names to group values (32 groups max, as a tile/sprites membership in a group is determined by the bits in an integer)

Vid.resize

Resize the layers.
Vid.resize(size,bg=0)
size

w,h in Tiles of the layers

bg

set to 1 if you wish to use both a foreground layer and a background layer

Vid.set

Set a tile in the foreground to a value.

Use this method to set tiles in the foreground, as it will make sure the screen is updated with the change. Directly changing the tlayer will not guarantee updates unless you are using .paint()

Vid.set(pos,v)
pos

(x,y) of tile

v

value

Vid.get

Get the tlayer at pos.
Vid.get(pos): return value
pos

(x,y) of tile

Vid.paint

Paint the screen.
Vid.paint(screen): return [updates]
screen

a pygame.Surface to paint to

returns the updated portion of the screen (all of it)

Vid.update

Update the screen.
Vid.update(screen): return [updates]
screen

a pygame.Rect to update

returns a list of updated rectangles.

Vid.tga_load_level

Load a TGA level.
Vid.tga_load_level(fname,bg=0)
g

a Tilevid instance

fname

tga image to load

bg

set to 1 if you wish to load the background layer

Vid.tga_save_level

Save a TGA level.
Vid.tga_save_level(fname)
fname

tga image to save to

Vid.tga_load_tiles

Load a TGA tileset.
Vid.tga_load_tiles(fname,size,tdata={})
g

a Tilevid instance

fname

tga image to load

size

(w,h) size of tiles in pixels

tdata

tile data, a dict of tile:(agroups, hit handler, config)

Vid.load_images

Load images.
Vid.load_images(idata)
idata

a list of (name, fname, shape)

Vid.run_codes

Run codes.
Vid.run_codes(cdata,rect)
cdata

a dict of code:(handler function, value)

rect

a tile rect of the parts of the layer that should have their codes run

Vid.string2groups

Convert a string to groups.
Vid.string2groups(str): return groups

Vid.list2groups

Convert a list to groups.
Vid.list2groups(igroups): return groups

Vid.groups2list

Convert a groups to a list.
Vid.groups2list(groups): return list

Vid.loop

Update and hit testing loop. Run this once per frame.
Vid.loop()

Vid.screen_to_tile

Convert a screen position to a tile position.
Vid.screen_to_tile(pos): return pos

Vid.tile_to_screen

Convert a tile position to a screen position.
Vid.tile_to_screen(pos): return pos

all content (c) 2006 Phil Hassey - Phil's pyGame Utilities