Author Topic: How to tilemap?  (Read 7462 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
How to tilemap?
« on: October 19, 2010, 06:44:56 pm »
Mkay, I apologize in advance, because this question has been probably asked so many times already, but how exactly do you make a tilemap in Axe?  
What different methods are there, and what types of compression are commonly employed?

I'm pretty sure there's lots of threads with similar questions floating around, so links are fine.
« Last Edit: October 19, 2010, 06:45:16 pm by Michael_Lee »
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: How to tilemap?
« Reply #1 on: October 19, 2010, 07:00:20 pm »
I actually have had heaps of trouble making a reasonably fast tilemapper in Axe, and im also eager to see this question answered

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: How to tilemap?
« Reply #2 on: October 19, 2010, 07:14:08 pm »
first, i'll define what a tilemap is. a tilemap is usually a 2-dimensional list (like a matrix) of numbers that map a tileset into a graphical map. what's a tileset? a set of graphics to use. the tilemap in axe is just a list of bytes. so the following could be a tilemap:
[0101010101]
[0100000001]
[0102020201]
[0101010101]
say we wanted to display this tilemap. the tile 00 will be a white square, the tile 01 will be a black square, and the tile 02 will be a white square with a black outline.
here's the code.
Code: [Select]
.PROG
[0000000000000000]->Pic1
[FFFFFFFFFFFFFFFF]
[FF818181818181FF]
[0101010101]->GDB1
[0100000001]
[0102020201]
[0101010101]
For(Y,0,3
For(X,0,4
Pt-On(X*8,Y*8,{Y*5+X+GDB1}*8+Pic1
End:End
DispGraph
Repeat getKey
End

this is very, very simplistic. note that each tile number takes up a byte. meaning you can have 256 different tiles. some tilemappers use half-bytes, or nibbles. you can then have only 16 different tiles, but your map is twice as compressed. many others also use RLE compression, which is a compression technique that instead of storing each tile as byte, would store the frequency of the tile in a byte, and then the tile in the next byte. so our example would become the following:
[06010300020103020601]
which would be read as "6 tile number 1's, 3 tile number 0's, 2 tile number 1's, 3 tile number 2's, 6 tile number 1's."
« Last Edit: October 19, 2010, 07:22:31 pm by nemo »


Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: How to tilemap?
« Reply #3 on: October 19, 2010, 07:18:04 pm »
Here's a nice tutorial on it: http://ourl.ca/4550.




Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: How to tilemap?
« Reply #4 on: October 19, 2010, 07:19:11 pm »
Code: [Select]
.PROG
[0000000000000000]->Pic1
[FFFFFFFFFFFFFFFF]
[FF818181818181FF]
[0101010101]->GDB1
[0100000001]
[0102020201]
[0101010101]
For(Y,0,3
For(X,0,4
Pt-On(X*8,Y*8,Y*5+X*8+Pic1
End:End
DispGraph
Repeat getKey
End
Wait, wouldn't using X and Y just return random gibberish?  How does the code know that X and Y refer to GDB1?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline nemo

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1203
  • Rating: +95/-11
    • View Profile
Re: How to tilemap?
« Reply #5 on: October 19, 2010, 07:22:04 pm »
Code: [Select]
.PROG
[0000000000000000]->Pic1
[FFFFFFFFFFFFFFFF]
[FF818181818181FF]
[0101010101]->GDB1
[0100000001]
[0102020201]
[0101010101]
For(Y,0,3
For(X,0,4
Pt-On(X*8,Y*8,Y*5+X*8+Pic1
End:End
DispGraph
Repeat getKey
End
Wait, wouldn't using X and Y just return random gibberish?  How does the code know that X and Y refer to GDB1?

oops. fixed.


Offline JustCause

  • CoT Emeritus
  • LV8 Addict (Next: 1000)
  • *
  • Posts: 810
  • Rating: +115/-5
    • View Profile
Re: How to tilemap?
« Reply #6 on: October 25, 2010, 10:06:07 am »
This was helpful for a project I'm working on. Thanks!
See you, space cowboy...