Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: saintrunner on November 17, 2011, 03:58:50 pm

Title: Tile mapping tutorial? for axe?
Post by: saintrunner on November 17, 2011, 03:58:50 pm
I'm looking for a really good tutorial for tile mapping! keep in mind I have never done it before, but I am very interested!
Thanks guys :)
Title: Re: Tile mapping tutorial? for axe?
Post by: AngelFish on November 17, 2011, 04:00:35 pm
We have a tutorials section on the website that happens to have two tilemapping tutorials on it.

Here you go:

http://www.omnimaga.org/index.php?action=articles;cat=12
Title: Re: Tile mapping tutorial? for axe?
Post by: saintrunner on November 17, 2011, 04:10:53 pm
can you also direct me to an example program I can look at?
Title: Re: Tile mapping tutorial? for axe?
Post by: aeTIos on November 18, 2011, 08:12:59 am
Most tutorials have an example program with it. You build one while you are learning.
Title: Re: Tile mapping tutorial? for axe?
Post by: Scipi on November 18, 2011, 08:49:30 am
If you have any questions pertaining to the actual logic, I can help you. I've made several programs utilizing Tile Mapping as well as a Tile Map Editor so I can definitely help. :D
Title: Re: Tile mapping tutorial? for axe?
Post by: shmibs on November 18, 2011, 11:39:39 am
^the same goes here for smoothly scrolling a tilemap, which can be tricky to make fast. good luck on whatever you're doing.
Title: Re: Tile mapping tutorial? for axe?
Post by: saintrunner on November 18, 2011, 05:02:36 pm
Yeah I kinda get all of the sprites and map stuff, but I don't get the actually main loop stuff! ? Could someone make a real quick tutorial for me? I'm really interested in working on an rpg. They sound fun to make! 
Title: Re: Tile mapping tutorial? for axe?
Post by: Scipi on November 18, 2011, 05:15:30 pm
Can you break it down to more specifics? With main loop are you having trouble drawing the tilemap each frame?
Title: Re: Tile mapping tutorial? for axe?
Post by: saintrunner on November 18, 2011, 09:51:40 pm
Yeah I guess, I really just need a quick and easy tutorial explaining all of it
Title: Re: Tile mapping tutorial? for axe?
Post by: Scipi on November 18, 2011, 10:00:45 pm
Well, the way I do it in TileCat is I have an array for the data. I use two for loops like so (You should be able to port this to Axe code):

Code: [Select]
for(int y = 0; y < MapHeight; y++)
    for(int x = 0; x < MapWidth; x++)
        {
             tile = MapArray[x + (y * MapWidth)];
             if tile == 0
                 //Draw Something at x * 8,y * 8
             if tile == 1
                 //Draw something else at x * 8,y * 8
         }

This will iterate over each tile in the array and read its value. Depending upon the value draw a sprite at X * 8 and y * 8

Note: There is a way you can modify this for scrolling by using two variables to keep track of where your view is and replacing MapWidth and MapHeight with those variables plus a value, say, 16 and 8 respectively. You will also want to make sure you don't go off the map though when doing that or going outside the array.
Title: Re: Tile mapping tutorial? for axe?
Post by: C0deH4cker on November 18, 2011, 11:12:44 pm
dont use an if statement for it.

I use nibbles, which can be any value from 0-F (0-15). So, since each pic is 8 bytes in length:

Code: [Select]
[HEXCODE]->Pic1
[MapDataInNibbles]->GDB1
For(A,0,95)
nib{A+GDB1*2}->B
A^12->X
A/8->Y
Pt-off(X*8,Y*8,B*8+Pic1)
End

I usually use something similar to this.


Therefore, just define your pics right after each other like this:
[HEX]->Pic1
[MoreHexForPic2]
[EvenMoreHexPic3]
etc.
Title: Re: Tile mapping tutorial? for axe?
Post by: Jonius7 on November 19, 2011, 05:35:38 am
That's definitely more optimised, C0deH4cker good job. I'm not sure if i get what nibbles is for. Is that a variable name?
Title: Re: Tile mapping tutorial? for axe?
Post by: saintrunner on November 19, 2011, 02:34:20 pm
can I have an example?
Title: Re: Tile mapping tutorial? for axe?
Post by: epic7 on November 19, 2011, 02:45:00 pm
Yeah, I'm not understanding this :P
Title: Re: Tile mapping tutorial? for axe?
Post by: shmibs on November 19, 2011, 02:54:35 pm
jonius: a nibble is four bits, or half a BYTE :P
saintrunner: c0de fellow posted a decent example there. here it is explained, though:

Code: [Select]
[HEXCODE]->Pic1 //this is the place where you put the hex data for all of your sprites, one after another.
[MapDataInNibbles]->GDB1 //this holds the map data in nibbles, which basically just means that every four bits holds a binary number from 0 to 15 (or 0 to F) to describe what tile to draw in what location. here they are listed in rows of twelve.
For(A,0,95) //a for loop. 12*8 (the screens width and height in increments of 8) is 96, so it has to run from sprite 0 to sprite 95 in order to cover the whole screen.
nib{GDB1*2+A}->B //this gets the sprite that is to be drawn next. it uses a "nibble pointer" rather than a "byte pointer" (i'm not sure what these are actually called...), so the "byte pointer" location of GDB1 has to be doubled. A is then added to determine which one to draw currently.
A^12->X //a modulus 12, or the whole integer remainder that would remain after A is divided by 12 is stored to X
A/8->Y //the integer value of A, were it divided by 8, is stored to Y
Pt-off(X*8,Y*8,B*8+Pic1) //drawing sprites to the screen. because B holds a value from 0 to 15, multiplying this by 8 and adding Pic 1 slides the pointer to the spot where you stored your sprite data and then jumps forward to the number desired.
End
Title: Re: Tile mapping tutorial? for axe?
Post by: saintrunner on November 19, 2011, 03:00:40 pm
Thanks that helps! can someone also explain movement with tile mapping? like if I have a character I want to be able to move? I would assume it would be similar to the regular getkey stuff
Title: Re: Tile mapping tutorial? for axe?
Post by: shmibs on November 19, 2011, 03:01:56 pm
i'm working on it already, actually, and will edit it in here.

EDIT:
The main restriction of our last map drawing style is that it doesn't allow drawing different spots in a tile map larger that 12*8, but rather only draws a single screen. here is a simple example that uses bytes for map data (because usually people have more that 16 tiles) and allows the map to be scrolled with getkey.

Code: [Select]
[HEXCODE]->Pic1
[MapDataInBytes]->GDB1
0->A->B //A and B are the x and y coordinates in the tilemap.
<map's width in tiles, minus 12>->X
<map's height in tiles, minus 8>->Y
Repeat getkey(15) //repeat until Clear is pressed

if getkey(3) //if right key
A<X+A->A //A is increased by the value of (A<X) which can either be 1 or 0, meaning that A will be incremented unless it equals X
end

if getkey(2) //if left key
A-(A>X)->A //similar to the last line
end

if getkey(4) //if up key
B<Y+B->B
end

if getkey(1) //if down key
B-(B>Y)->B
end

For(M,0,7)
For(L,0,11)
PtOff(L*8,M*8,{B+M*X+A+L+GDB1}*8+Pic1)
end
end
/*
/This is a fun section to describe. L*8 and M*8 should be fairly obvious in the first and second arguments.
/B+M*X is, because of Axe's lack of order of operations, interpreted as (B+M)*X. This will give the Y coordinate
/in the map data to read, because in order to find Y coordinates in a single dimensional list, one has to
/multiply that value by the total width of the map. A+L then gives the X coordinate, and adding GDB1 makes it point to
/the tile map data.
*/

end
Title: Re: Tile mapping tutorial? for axe?
Post by: saintrunner on November 19, 2011, 03:06:02 pm
thanks!