Hey guys. I'm messing around with LÖVE trying to create a tile-based game akin to Zelda, or Pokemon. Purely for testing out the engine. However, I'm at a bit of a stand still at the moment, I'm not exactly sure how I would go about implementing a multi-layered tile-based game where you'd have the base layer for non-collidable scenery, then the subsequent layers for things like objects, players etc.
Any ideas?
Tile-based game: layers?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- bartbes
- Sex machine
- Posts: 4946
- Joined: Fri Aug 29, 2008 10:35 am
- Location: The Netherlands
- Contact:
Re: Tile-based game: layers?
What do you want to use the layers for?
- Jasoco
- Inner party member
- Posts: 3728
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Tile-based game: layers?
Well, do it like I do.
Each "layer" is its own two-dimensional array. One layer holds the tile for the background, one for the hit map, and more for other decorations if need be. (And you will need it)
To create a multi-dimensional array:
For me, each tile uses a four character "location" code telling the game engine where in the main tile map to grab its image from. i.e. 0413 would mean it would take a tile 4 * 32 to the left and 13 * 32 down.
mapHit will hold a certain number based on whether it's passable or not. Or you can extend it by making some water, or mud or whatever so when your character walks in it, if they can, the game reacts appropriately. For me I have three values. Passable, non-passable and passable by projectiles only which is used for water or lower to the ground objects like barrels so that enemy and player weapons will pass over them. (Shooting across the river for instance)
You then draw each layer in the order they should be displayed...
Background
Decorations below
Player, enemies, other objects
Decorations above
Etc...
My game has four decoration layers for advanced detailing. But you don't need to go that far. Most older NES/GameBoy games only used one background and one sprite later.
There's a link to an older demo of my engine in my official topic if you want to look at how I did it.
http://love2d.org/forum/viewtopic.php?f=5&t=888
Lucky topic number 888.
Each "layer" is its own two-dimensional array. One layer holds the tile for the background, one for the hit map, and more for other decorations if need be. (And you will need it)
To create a multi-dimensional array:
Code: Select all
mapTiles = {}
mapHit = {}
mapDeco1 = {}
...
for x=0,max_map_width do
mapTiles[x] = {}
mapHit[x] = {}
mapDeco1[x] = {}
...
for y=0,max_map_height do
mapTiles[x][y] = ""
mapHit[x][y] = "x"
mapDeco1[x][y] = ""
...
end
end
mapHit will hold a certain number based on whether it's passable or not. Or you can extend it by making some water, or mud or whatever so when your character walks in it, if they can, the game reacts appropriately. For me I have three values. Passable, non-passable and passable by projectiles only which is used for water or lower to the ground objects like barrels so that enemy and player weapons will pass over them. (Shooting across the river for instance)
You then draw each layer in the order they should be displayed...
Background
Decorations below
Player, enemies, other objects
Decorations above
Etc...
My game has four decoration layers for advanced detailing. But you don't need to go that far. Most older NES/GameBoy games only used one background and one sprite later.
There's a link to an older demo of my engine in my official topic if you want to look at how I did it.
http://love2d.org/forum/viewtopic.php?f=5&t=888
Lucky topic number 888.
-
- Prole
- Posts: 5
- Joined: Mon Feb 22, 2010 1:00 am
Re: Tile-based game: layers?
Thanks, I'll check it out.
Edit:
Wow, that topic is very informative.
Edit:
Wow, that topic is very informative.
- Jasoco
- Inner party member
- Posts: 3728
- Joined: Mon Jun 22, 2009 9:35 am
- Location: Pennsylvania, USA
- Contact:
Re: Tile-based game: layers?
It is my pleasure to help. I am impressed with the power Löve gives me and haven't been this happy with a game engine since TNTBasic. (Which ended up being a disappointment when the project was abandoned and an open-source version never made it out of coding hell.) At least Löve is getting the love it deserves and will go on for years and years. I look forward to seeing what Löve will be like when it hits 1.0, if this is what we have at only 0.6.1. The possibilities are endless.
Who is online
Users browsing this forum: Ahrefs [Bot] and 6 guests