Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Seeking help coding a Tier1 tile map level loader for AGK2

Author
Message
method321
15
Years of Service
User Offline
Joined: 28th Jan 2009
Location:
Posted: 27th Aug 2015 03:39
Hello all.
I just picked up AGK2 recently, and been tinkering with the basics, loading up a few sprites, moving them around, added some mouse movement controls, some simple sprite manipulations, sounds etc. So i am getting the basics down and want to build a simple first game.

I have moved onto building some levels for a Breakout style game, these levels are designed in TILED (the free tiled map editor)

I am trying to figure out how to go about writing a basic level-loader in AGK2 (tier 1) to load the levels. I am kinda unsure what i'm doing.

Whats the best way to export the map for AGK2, in json format, or lua, or csv? or does it not matter.

Once I export it out, I know I need to open the file for reading, and build some sort of loops to read thru the file, and have it identify where to load the tiles and what image to assign to that location, and I assume in that loop I would also be assigning sprite identifiers so I can then use those ID for each laid out tile to determine individual collision etc.

I am having a tough time trying to figure this out, I looked at a few forum posts and youtube vids, but nothing was really making it clear to me.

Has anyone else, setup a basic tiled level loader that wouldn't mind sharing an example I can look at to see how its done, and adapt that to my specific game maps?


Thanks in advance for any constructive feedback.
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 27th Aug 2015 07:14
For my Sokoban clone I wrote the simplest level thingymajigg that I could. I've created a binary file that only contains a series of whole numbers. Since the game is grid based the first number is the width of the grid, the second is the total number of tiles in the grid and then it's the actual tiles themselves. And again, the tiles are represented as whole numbers.

I can then read the numbers, number of tiles divided by width gives me the height of the grid. Then just loop through the numbers in the file and create tiles based on that.

1, is a floor tile, 2 is a wall tile, 4 is a target where the player should push the crate, 8 is a crate and 16 is the player starting position. So if I read a 5, that's a 1 + 4 so I know that it's a floor tile with a target on it, 9 = 1 + 8 so that's a floor tile with a crate on it. That was the easiest method I could come up with and it pretty much mirrors the way I handle the logic in the game, because I store all tile information in a single dimensional array and then the player moves I check in the array to see if the tile they want to move to is free etc.

Here is an example of the code I use to read the level.
method321
15
Years of Service
User Offline
Joined: 28th Jan 2009
Location:
Posted: 27th Aug 2015 14:17
thanks for that reply.
seems like you have a nice purpose built loader for your specific game.

I like the idea of using some binary bits to define the exact "type/properties" of your tiles. I can imagine that being useful in a dungeon random generator style game where I could set tiles as being, a Monster, Treasure, Locked-Chest, Trap, Health-pickup, Coin etc, and they would be given the applicable attributes needed in game based on that type.

Not sure I could directly apply that to mt breakout game, or a platform game without some decent modifications, will take a look deeper into what you provided. Perhaps someone else has a more generic platform level loader implementation they can share as well.

thanks
Fluorescent
FPSC Reloaded TGC Backer
18
Years of Service
User Offline
Joined: 1st Aug 2005
Location: Stockholm, Sweden
Posted: 27th Aug 2015 20:43
The original purpose of my game was to work on the game logic as a teaching aid for my self and learning game development as well as AGK. But the game turned out quite fun with it's hard coded level so I rewrote parts of it to read levels from files. That's why it's on the surface such a simple implementation. If I've done it differently I might had to have reworked parts of the game that already was done and tested.

But I think it could be easily repurposed as a way of representing anything in a 2d grid. For your breakout the whole numbers could represent the different coloured blocks of the level. And you could use it to draw designs of the blocks. The only thing you probably shouldn't do, but probably can, is the power ups. Some breakout clones will drop power ups when certain blocks are smashed, but they are usually randomized.

I haven't gotten that far yet, since my breakout game has a hard coded level. I'm not really that into level design so I picked the method that seemed most natural to me.
Duncro
8
Years of Service
User Offline
Joined: 25th Jul 2015
Location:
Posted: 30th Aug 2015 17:55
I have created a generic tilemap editor that saves the plain tilemap, objects (a second tielmap layer) and collisions (a third tilemap layer). you cana lso set a type for each map and object tile, which the game can read and then assign the necessary attributes to.

All this along with the map size (nr of tiles in x and y, and the tile dimensions) are saved in a text file.
the first few lines have things like the map sizes, then there are the tile atlasses, and sprite filenames, then starts the maptiles.
the maptile infos are separated by commas and semicolons, and i use "getstringtoken" to recall them within for loops. I know its not as sophisticated as other types, but for testing its great. You can open the text file an quickly check whats there to make sure if any errors have slipped in or not.

If you want to have a look at it, see the attached file.
check the code under the file called starteditor.agc that has both the save and the load file for maps.

if you want to play around with it, go ahead. the middle mouse wheel and button is used to navigate the map while editing, and scroll up and down the map atlas file. I haven't implemented scrolling through multiple sprites though. You can add the test.png atlas to test it.
also they 1,2 and 3 keys allow you to quickly cycle through the layers.

Attachments

Login to view attachments

Login to post a reply

Server time is: 2024-04-19 20:36:54
Your offset time is: 2024-04-19 20:36:54