Knowledge Base‎ > ‎Programming‎ > ‎Summative Project‎ > ‎

Platformer or Image Map

An example of using an image as a map. For a platform game other ideas could be used - for instance a list of platform objects.

See the example code here:

Uses a map in the form of a PNG image to check for collisions - see code on how to do this.

def hit_platform(x,y):
  return tuplecolor(platform.get(x,y)) == (0.10980392156862745, 0.46274509803921571, 0.086274509803921567, 1.0)

This function tests to see if the image at the position matches the colour that line is draw with. platform.get retrieves the colour and then tuplecolour turns it into a tuple (r,g,b,a) (but this step isn't really needed).

Seems to run fast enough but could maybe be speeded up with a smaller map that then uses a factor to map screen position to map:

screen position / factor = map position

Map could be created in a layer with Photoshop and other graphics placed in another which could be exported and used as a background.

James Cordiner,
Apr 30, 2011, 5:45 AM