Skip to main content
GameDev.net gamedev.net
🔒 Locked

Tile based RPG with Pyglet

Started by WallaceD Jul 28, 2012 at 2:56 AM 0 replies 4.5k views
Original Post
WallaceD
WallaceD
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
slicksk8te
slicksk8te
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.