Tile based RPG with Pyglet

Started by
0 comments, last by slicksk8te 11 years, 7 months ago
I'm trying to make a tile based RPG with pyglet but I'm a bit stuck sad.png I plan to have a text file from which it would read the tile positions and other details from

e.g.

[map]

level = +++++
+-----+
+-----+
+++++

I was using configparser to turn this into a list of rows:
[source lang="python"]self.map = parser.get("map","level").split("\n")[/source]


But I'm not sure where to go from there :/ What I want to do is have each symbol represent a tile (grass = - etc.) and be displayed on the screen.

Any suggestions would be greatly appreciated smile.png
Advertisement
A good start for this would be to load all textures into a dictionary where the key is a symbol.
An example of this is:
{
"-": grassImage,
...
}

and then loop through your map and draw based on the tile location:
[source lang="python"]tileMapping = {
"-": grassTexture, #preloaded
...
}

TILE_SIZE = 16 # for example

xCoord = 0
yCoord = 0

Map = ["-----"] # Preloaded map

for row in Map:
xCoord = 0
for tile in row:
tileTexture = tileMapping[tile]
x = xCoord * TILE_SIZE
y = yCoord * TILE_SIZE
# Draw Tile Texture Here at x,y
xCoord += 1
yCoord += 1[/source]

Hope this helps

This topic is closed to new replies.

Advertisement