Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: abstauber on Tue 30/03/2010 08:44:47

Title: Tile engines anyone?
Post by: abstauber on Tue 30/03/2010 08:44:47
Yes, this comes up every now and then ;)

For some unexplainable reasons I got curious in scripting up a tile engine, or at least playing around with it. But then I've learned that a map editor could come handy, multiple layers would be nice and so on... also after some searching I found out that at least Khris, Scarab and Jim Reed are already working on the same thing.

Well, my motivation in reinventing the wheel over and over again is quite low right now.

@Current Tile Engine Coders
Are your creations going to be released as modules?
Title: Re: Tile engines anyone?
Post by: Gilbert on Tue 30/03/2010 09:45:02
I think it depends on how specific the engine you want it to.

In fact it is not difficult to code your own engine, provided it's intended to be tailor-made for your own game, without "general purpose features". It all depends on whether you're having fun with making your own thing (this is what I personally like, even though you're inventing the wheels once again and possibly you can just adopt others' engines and do much more advanced stuff), or you rather save your effort in improving other aspects of your games. Neither idea is wrong in itself.

If you're looking for "reusable" engines, either the engines have to be "general enough" to cover your own needs (and probably also provide features that you don't need) or you may have to modify them to suit your own needs. But if you make your own engine you can always just make it to suit your own needs, 100%.

For example, my yet-to-be-released game has a simple tile engine and it features a fully functional map editor too:
(http://i488.photobucket.com/albums/rr249/gilbot/snake004.png)
In fact it took me about 1 month to finish the skeleton of the whole game and it's already technically complete, missing only polish like sound and cutscenes, etc. I'm just too lazy busy to continue it at the moment and this game has been on hold for 6 whole years now (ah well...).

And no, I won't make a module out of it as this game used AGS V2.6SP1, in which there wasn't even module support. :=
Title: Re: Tile engines anyone?
Post by: abstauber on Tue 30/03/2010 10:01:27
Hey, that looks pretty cool, I wonder how much more projects you hide in your sleeves ;)
AGS 2.6 was last with DOS support, right? So it somehow makes sense, as it's last really portable release.

Anyway in my case I wouldn't be lurking in an "game engine forum" if I had fun coding my own engine, even if it's an engine inside an engine ;D
Title: Re: Tile engines anyone?
Post by: Khris on Tue 30/03/2010 10:11:47
I don't really have anything to show for yet. I wanted to replicate the Chrono Trigger engine, and while I sort of know how it works (it uses two layers very elegantly), I've played through Golden Sun 2 recently and it has an even more advanced layer engine.

To me it really is about reinventing the wheel, that's were the fun is, but I haven't gotten around to much yet.
Title: Re: Tile engines anyone?
Post by: Gilbert on Tue 30/03/2010 10:18:20
Quote from: abstauber on Tue 30/03/2010 10:01:27
AGS 2.6 was last with DOS support, right? So it somehow makes sense, as it's last really portable release.

In fact the last version with DOS support was V2.62 (V2.7 was the first to drop the support), so if I start off with new games I'll go with this. The reason I used V2.6SP2 for this was because it was the latest version when I started and I scripted a lot of stuff to work around limitations (like say, repeatedly_execute_always() was not implemented yet). If I had to upgrade it to a newer version I would have to re-work a lot of stuff such as trimming the then-unnecessary workarounds (though not absolutely required) and most importantly, my scripts were a mess that I wouldn't want to spend time in reunderstanding them to fix them. ::)
Title: Re: Tile engines anyone?
Post by: abstauber on Wed 31/03/2010 07:56:14
At a certain level reinventing the wheel is sure interesting, but I know myself - after getting the basics done, I loose interest. Actually creating the game is a much bigger motivation ;)

Still I'm very curios, how others implemented those tiles. E.g. I've stumbled upon Revelation by dkh and he utilises a really cool map editor: notepad  :o
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=32496.0


@Khris: Hooray for Chrono Trigger ;D That is by far the best SNES RPG I've ever played, even though FF6 was great as well.
Title: Re: Tile engines anyone?
Post by: Jim Reed on Wed 31/03/2010 09:33:31
Quote from: abstauber on Tue 30/03/2010 08:44:47@Current Tile Engine Coders
Are your creations going to be released as modules?
Not likely, sorry.

As for layers, I use two for the background, one for the sprites, and two for the foreground.
640x480 16x16px tiles @~30fps. If you don't watch out, redrawing of tiles can really eat the framerate.
Title: Re: Tile engines anyone?
Post by: abstauber on Wed 31/03/2010 09:54:43
Hehe, no need to be sorry. Don't get me wrong - this is not a public cry for giving me code ( I prefer PMs for that :P )

I'd just really like this to be done in AGS. And unlike gamemaker, doing it in AGS feels right and punchy :)
Title: Re: Tile engines anyone?
Post by: Wonkyth on Wed 31/03/2010 10:08:58
You could probably find some non-AGS code somewhere and transcribe it, AGS is pretty good that way.
Title: Re: Tile engines anyone?
Post by: Dualnames on Wed 31/03/2010 14:41:56
Quote from: abstauber on Wed 31/03/2010 07:56:14
I've stumbled upon Revelation by dkh and he utilises a really cool map editor: notepad  :o
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=32496.0

wow, and to think. Hey, wait colourwise has a tile thingy. In fact it has an editor too!
Title: Re: Tile engines anyone?
Post by: Crimson Wizard on Wed 31/03/2010 14:54:40
I have a tiled map editor made as AGS game. Originally it was supposed to be RPG editor, but I felt like not making AGS RPG yet and left it temporarily.
Editor features:
- 6 layers
- toggling layer visibility
- extra "walkable area" layer with toggling visibility and/or setting transparency
- reading tiles from AGS sprites; I could not make it load custom graphics from game folder - they always had screwed colours for some reason, so I disabled that option for now
- creating map of an any size (width/height)
- saving and loading map
- really cute and cool interface  ;D

(http://img706.imageshack.us/img706/9494/tileeditor1.png)


(http://img59.imageshack.us/img59/9084/tileeditor2.png)

I remember those features worked nice so far. Don't know if it may be of any use though... I started to write engine itself, but, as it often happen to me, put it away until better times because lack of inspiration  :P
Title: Re: Tile engines anyone?
Post by: Ryan Timothy B on Wed 31/03/2010 22:14:44
Yeah you're almost better just making your own.  Everyone has their own technique or design.
Like mine for instance is for a strategy game level editor Exactly like the Starcraft editor.  Ignore the programming graphics.  I haven't worked on this in a while, been busy with other games. :P

(http://www.bryvis.com/entertainment/games/strategy/editor/screenshot4.png)
(Click to enlarge) (http://www.bryvis.com/entertainment/games/strategy/editor/screenshot4.png)

Also it has fog (http://www.bryvis.com/entertainment/games/strategy/screenshot4fog.png)!  (which will probably never make it, since it 'might' be too laggy)
Title: Re: Tile engines anyone?
Post by: Scarab on Thu 01/04/2010 09:40:03
Quote from: abstauber on Tue 30/03/2010 08:44:47
@Current Tile Engine Coders
Are your creations going to be released as modules?

Possibly, however I grew up playing RPGs on Gameboy, and as such my engine is designed to emulate those kinds of games, and supports no layers, so this might not be what you're looking for.

The reason it is dead in the water right now is because I have been having trouble exporting maps from the editor into the game (using .txt files), and I need to become better at using the File functions before I can continue.
Title: Re: Tile engines anyone?
Post by: Khris on Thu 01/04/2010 11:28:55
About handling map data:
ProMotion can export GBA tile map data and currently, the only thing my editor does is import & display that.
I was planning to export the data as code in a txt file so that it only needs to be pasted into a script as-is.

That way the level data is in the game, not in editable files outside.

Btw:
There's a pretty sophisticated Chrono Trigger map editor out there, and playing with it I learned how they do dungeons and village houses: all rooms are on one big map; and all tiles contain a scroll flag.
Using the flags, the big map will stop scrolling at the edge of a room.
Title: Re: Tile engines anyone?
Post by: Wonkyth on Thu 01/04/2010 13:26:38
Wouldn't it be better to use an image for levels?
Title: Re: Tile engines anyone?
Post by: abstauber on Thu 01/04/2010 14:18:50
You guys should definately colaborate ;)

@Khris: This is actually pretty cool. I've also thought about parsing PMs map exports.
But as said, simply parsing ASCII codes is way easier for my limited project.

@Dualy: Yay and Colourwise even has isometric tiles :) Somehow I must have forgotten about it.

@Crimson Wiz:
Fancy stuff! Co-evolution made this looking like Jim's :)

It's really impressive how many people have tile projects in the pipe.
Title: Re: Tile engines anyone?
Post by: Matti on Thu 01/04/2010 14:50:23
This (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=38639.0) was my first attempt in tile-based scripting ever. I should finish that stupid game at some point.

It's rather simple and I won't make a module or something. The background consists of 10x10 tiles and each tile has ~4 variables who store some info (kind of tile/"subkind" of tile/building/player). Everytime something is changed the whole background is being drawn again. First the landscape, then the buildings, then the borders.

But if I find some time in the future I might elaborate the whole thing to make something decent with it.
Title: Re: Tile engines anyone?
Post by: Khris on Thu 01/04/2010 19:56:18
wonkyth:
I sort of do that already; ProMotion is great as a map/tile editor; e.g. you can at any time convert a drawn image to tiles, remove unused ones, or draw on one tile and have all occurrences updated on the fly.
I have yet to find a better tool.
Actually, it also supports layers so it's possible to draw layered tile maps; unfortunately, it crashed on me as soon as I started using two layers.

abstauber:
It's not too hard to parse the file, the format is well documented.
Here's the core function, if anybody's interested:

bool ReadMap(String filename) {
  File*f;
  String fs;
 
  // open sprite file
  fs = String.Format("tiles/%s#tiles.pcx", filename);
  error = "Sprite file not found";
  if (!File.Exists(fs)) return false;
   
  error = "Error importing sprite file";
  tile_images = DynamicSprite.CreateFromFile(fs);
  tiledims = tile_images.Height;
 
  if (tile_images == null) return false;

  fs = String.Format("tiles/%s#map001.map", filename);
  error = "Map file not found";
  if (!File.Exists(fs)) return false;

  f = File.Open(fs, eFileRead);
  error = "Error opening map file";
  if (f == null) return false;

  mapwidth = f.ReadDoubleword();
  mapheight = f.ReadDoubleword();
  int tiles = mapwidth * mapheight;
  int i;
  int info;
  String s;
  while (i < tiles && i < 5000) {
    info = f.Readword();
    s = BitString(info, 16);
    Tile[i].image = BitStringToInt(s.Substring(0, 10));
    if (BitStringToInt(s.Substring(10, 1))) Tile[i].mirrored_x = true;
    if (BitStringToInt(s.Substring(11, 1))) Tile[i].mirrored_y = true;
    i++;
  }
  f.Close();
 
  // setup viewscreen with tile info
  ViewScreen.SetMap(mapwidth*tiledims, mapheight*tiledims);
  ViewScreen.SetBounds(true);
 
  return true;
}
Title: Re: Tile engines anyone?
Post by: Crimson Wizard on Thu 01/04/2010 20:55:44
By the way, since we touched this topic here, does anyone know, why this may be that when I create dynamic sprite from file, all colours became screwed?
I tried everything, it seems, like making graphic colour amount match game's colour amount, trying different colour settings in game, etc, nothing seem to help.
Title: Re: Tile engines anyone?
Post by: Jim Reed on Thu 01/04/2010 23:14:37
The heart of my tile drawing function. Will render any tile/map size.
The offset is for effects like screen shaking and such.


int sprite_x=((counter%ROWSIZE)*(TILE_PIXEL_WIDTH))+MAP_X_OFFSET;
int sprite_y=((counter/ROWSIZE)*(TILE_PIXEL_HEIGHT))+MAP_Y_OFFSET;


Edit:
counter is an int, looping through the tile array.
The tiles don't have x and y positions, so it's easy to draw a map of letssay 400 tiles (20x20 tile map)
You just make an tile[400] array and run it through the above code, seting up the rowsize to 20 beforehand.
Title: Re: Tile engines anyone?
Post by: Calin Leafshade on Thu 01/04/2010 23:47:31
Quote from: Crimson Wizard on Thu 01/04/2010 20:55:44
By the way, since we touched this topic here, does anyone know, why this may be that when I create dynamic sprite from file, all colours became screwed?
I tried everything, it seems, like making graphic colour amount match game's colour amount, trying different colour settings in game, etc, nothing seem to help.

are you drawing it on a emtpy room?

try adding a 32bit background to the room
Title: Re: Tile engines anyone?
Post by: Wonkyth on Fri 02/04/2010 06:23:28
Khris: I suppose I din't explain it very well, but what I actually mean is instead of the level file being stored as values in text, wouldn't it be better - at least for less complex setups - to store the level as a PNG or something?
The first/last row/column could be used to store non-physical level information(or it could be stored as text for easy reference), and the rest for the actual tile layout.
This would enable you to use an image editor for level creation and the likes, making a near instant level editor.
Title: Re: Tile engines anyone?
Post by: abstauber on Fri 02/04/2010 14:08:41
Quote from: Khris on Thu 01/04/2010 19:56:18

ReadDoubleword
BitString
BitStringToInt


Khris: Which library am I missing? Those don't sound very AGS internal ;)

Crimson Wiz: According to Khris' posted function, it does work with .pcx files. Have you tried those yet?

Title: Re: Tile engines anyone?
Post by: Khris on Fri 02/04/2010 16:23:10
I might post the complete source code at some point, yeah :)

wonkyth:
Well, I could save the level as image, sure, but by the same logic I could not use tiles at all. Using tiles, all I need is a sprite containing all tiles; this will always be smaller than even one level.

Edit:
Here's a primitive example of a two layer room with walk tiles.
(http://img202.imageshack.us/img202/1791/promotiontiles.png) (http://img202.imageshack.us/img202/1791/promotiontiles.png)

I can save the background, foreground and walkable areas as files, then import them into my MapEditor.
Thus, ProMotion is effectively both a multi layer MapDesigner & PaintProgram. It's also the most professional pixel art program out there. It can't get any better than that :)
Title: Re: Tile engines anyone?
Post by: Wonkyth on Sun 04/04/2010 12:54:57
You're still misunderstanding me.
In the level image file, one pixel correlates to one tile, it's type specified by the clour of the pixel.
Title: Re: Tile engines anyone?
Post by: Khris on Sun 04/04/2010 13:40:04
Aha!
Now I get you.

The thing is that I'd have to read the pixel's color from the PNG (imported as sprite). Translating the color number into a tile index is really uncomfortable; plus I'd have to use multiple colors to store mirroring.
(I spent half an hour once finding the right way to translate the color number into RGB values.)

It's nice and clean as opposed to storing huge chunks of array setting codes in modules though.
Title: Re: Tile engines anyone?
Post by: abstauber on Mon 05/04/2010 11:30:35
Hey Khris, one thing that came to my mind: can you somehow store tile attributes inside that map file ( e.g. a tile being deadly) ?

In my ascii maps I only have one character to map a certain tile, like '-' being a regular floor and '~' being a water. Everything else is currently mapped by hand..
Title: Re: Tile engines anyone?
Post by: Khris on Mon 05/04/2010 13:04:07
Creating the levels using layers in ProMotion makes it possible to add all kinds of additional data to maps.
To add deadly tiles, you'd simply add a layer that uses a blank tile and, say, a purple tile. Then you'd fill all deadly areas using purple tiles and export the map.

I'm planning to have a map editor that can then be used to refine the level design, but the bulk of the design work is supposed to done using ProMotion.

Once I've imported a GBA tile map into the AGS program, I can simply save the game. Thus, every save game slot will eventually hold one level. When I want to change something, I simply restore the level's savegame, then reexport the level as a code text file.

So I'll probably not use a ProMotion layer for exits or other data that only very few tiles will have.
Thinking about it, I guess handling only the two graphics layers in PM is best, as long as the map editor is comfortable to use.

The main benefit is being able to design two visual layers at once.
Title: Re: Tile engines anyone?
Post by: Khris on Tue 06/04/2010 02:28:14
Phew, took me a few hours...
And ProMotion suddenly crashing on me constantly didn't help.

Features so far:
-imports GBA tile maps (name + name_fg, example included)
-foreground and background tile layer can be edited (big crosshair, x & y to flip)
-scrolling (hold right mouse in tile mode)
-all types of Chrono Trigger solidity tiles implemented (mousewheel to change type, right-click to delete)
-1, 2, 3 to enable/disable layer visibility, 0 to reset

http://shutupload.com/dl/ac06163fb178/

I'm seriously hoping I'll manage to stay on track this time...
Title: Re: Tile engines anyone?
Post by: abstauber on Tue 06/04/2010 07:53:08
Phew, that's pretty impressive :)
I like the scrolling - I thought of using sliders somehow, but the right click works great and intuitive.

Also having all those tiles being loaded from an external file is totally cool. I wonder if this affects the performance in any way.


A slight bug: the map designer crashes if I click on the map region before selecting a tile the first time.

Title: Re: Tile engines anyone?
Post by: Khris on Tue 06/04/2010 08:40:42
Yeah, I actually found that one immediately after uploading it, corrected it, uploaded again and only just now saw that I forgot to re-zip it and uploaded the old archive twice :D

What do you think of the way placing the different small square and triangle solidity tiles is handled? I came up with that spontaneously and liked it so I kept it. Or is it to fiddly?
Title: Re: Tile engines anyone?
Post by: abstauber on Tue 06/04/2010 10:25:23
Hehe, well it feels quite DOSsy :P In other words: if you know how it works, it works pretty good :)
But I wonder if you'll just allow keyboard movement, because for mouse-movement you'd need some sort of pathfinding inside AGS-script (of course you know that too, I'm just curious ;) )



Title: Re: Tile engines anyone?
Post by: Khris on Tue 06/04/2010 11:15:21
Tile-based path finding isn't that hard, I'd just have to implement a simple A*.
It might get hairy in narrow passages between triangles though.

Luckily I don't plan using mouse movement; everything is supposed to be controlled via keyboard/joypad eventually. I want to stay as close to the old SNES-RPGs as possible.
Title: Re: Tile engines anyone?
Post by: abstauber on Mon 19/04/2010 07:54:45
Hey guys,
currently I'm at a point where ascii-map files become somewhat limited.
I suppose doors and hotspots are just another overlay/layer in ProMotion, as well as other attributes.
But I wonder  how you manage tile animation? Right now, I'm doing it "by attribute", but of course I'm still using sprite slots so I know which sprite belongs to which frame.

Title: Re: Tile engines anyone?
Post by: Scarab on Mon 19/04/2010 08:38:01
Sorry abs, can't really help you there, haven't got to animation yet.

However, this thread has re-kindled my interest in mine, and I'm back at the exporting to file problems that stopped me originally. (I thought posting here would be better than starting a new thread).

Basically when I store something in a file, I get odd symbols in there as well, part of the String syntax, I would assume, and I would very much like for them to.. not be there.

My current solution is to copy-paste the whole thing into Room_Load(), and extract them manually using the find and replace functions, but ideally I would like to be able to access scripts from outside the game file. Would I be using the wrong commands? I'm using WriteString and WriteRawLine.

I would also like to know if there's any way one could make the exported files unopenable/uneditable, so no-one can edit maps to get rid of enemies or remove a door or something.

peace
Scarab
Title: Re: Tile engines anyone?
Post by: abstauber on Mon 19/04/2010 08:46:35
As far as I understand the manual, File.WriteString(string text) and String File.ReadStringBack()
use a custom file format. So if you use this pair, your file should become uneditable for texteditors.

File.WriteRawLine(string text) and String File.ReadRawLineBack() on the other hand use a plain textfile.

Could it be that your file troubles result in mixing these two pairs of functions?



edit
@Crimson Wizard
QuoteBy the way, since we touched this topic here, does anyone know, why this may be that when I create dynamic sprite from file, all colours became screwed?

That's most likely because you're using a blank room. Just import a black 320x200 bitmap as background and it works. I've tested it with .bmp and .pcx.
Title: Re: Tile engines anyone?
Post by: Wonkyth on Sat 24/04/2010 14:06:12
Or, again thinking of using an image, you could have the levels built in as a sprite, and can compare the colours with that of a KEY image, which would simplify the reading of colours...