Omnimaga

Calculator Community => TI Calculators => Axe => Topic started by: SirCmpwn on April 07, 2010, 11:26:39 am

Title: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 11:26:39 am
Hey, I wanted to do something special for my 400th post, so I wrote a quick tutorial.

Tilemaps are a very important part of many, many games.  For more information on what a tilemap is and how it relates to games, see this: http://en.wikipedia.org/wiki/Tile_engine (http://en.wikipedia.org/wiki/Tile_engine)  So, let's jump right in:

Getting started: The Data
The tilemap data actually defines which tiles go where.  Now, in Axe, we use the [] tokens to store hex data.  If you are not clear on what hex is, go here: http://vlaurie.com/computers2/Articles/hexed.htm (http://vlaurie.com/computers2/Articles/hexed.htm).  A hex pair consists of two digits.  Now, we want to compress our map data, and using a special routine from BuilderBoy, we can cut our map data in half.  We have to limit ourselves to 16 tiles per map, but I'll address how to get around that later.  Anyways, here is an example map, 4x4 for the purposes of the demonstration:
Code: [Select]
[1111->GDB1
[1001
[1001
[1111
Let's explain this.  How can we store 4 tiles to two bytes?  Well, we use each digit to store a tile.  We will talk about how to get each digit alone later.  Let me explain, however, why I put "->GDB1" at the top as opposed to the bottom, like you would do for a sprite.  GDB1 is just a pointer.  You see, Axe is going to add this data to the bottom of the program output.  It also will set GDB1 to point at the very first one.  However, if we were to re-arrange the code like so:
Code: (Axe Basic) [Select]
[1111
[1001
[1001
[1111->GDB1
Then we would have GDB1 point to the 7th byte after the start of the map data.  This would be bad because it would make the first row all "1" tiles, and the rest of the rows the random gibberish sitting in the memory after the last row.  Not good.  So, we put "->GDB1" on the first line.  Also, for the sake of demonstration, please have your sprites in Pic1.

Drawing the Tile Map
Having the data is nice and all, but at some point you want to show it off.  So, we have a simple method to draw it.  The following method uses a 14x9 tile map with 7x7 tiles (hmm, isn't that what Half-Life 2: OC uses? ;)).  However, it should be easily customizable to fit with your needs.
Code: (Axe Basic) [Select]
ClrDraw
For(I,0,7  // Start at zero, and go until your tile map width diveded by two (because we store two tiles for every one byte)
For(J,0,8  // The Y axis has one byte to each tile, so you can just use the height minus one here.
{J*9+I+GDB1->A  // J*9 gets us the row offset (see below) and we just add the X value.
A^16->B // Get the second digit of the hex into B
A/16->A // And the first digit into A
If A
Pt-On(I*14,J*7,Pic1+A-8  // I*14 because of the two tiles to a byte, J*7 because of 7 pixel tiles
End
If B
Pt-On(I*14+7,J*7,Pic1+B-8
End
End
End
Spoiler For Cool Optimization:
If you have more sprites than just what is needed for the tilemap, you can optimize away the "-8" subtraction in the Pt-On lines.  You also need to have Pic1 point to the sprite before the first tile map sprite in the data.
A^16?!? A/16?!?  How is that supposed to get each digit?!?  Honestly, I don't know.  Ask BuilderBoy.  It vaugely makes sense in my mind, but I haven't put a lot of brainpower towards it.  Anyway, this routine will draw your tilemap on-screen, without updating the screen.  It's your job to call DispGraph eventually, but you can still draw a character or something without having to worry about flicker.
Now, this line: "{J*9+I+GDB1->A" is weird.  Let me explain.  If you have a tilemap that looks like this:
11111111111111
10000000000001
10000000000001
10000000000001
10000000000001
10000000000001
10000000000001
10000000000001
11111111111111
It doesn't get stored in memory looking nice and layed out for you.  It gets stored like this:
111111111111111000000000000110000000000001100000000000011000000000000110000000000001100000000000011000000000000111111111111111
So, what we can do to find the correct tile is this.  We start with the row.  We know each row is 7 bytes wide (2 tiles to a byte, remember?), so we can multipy J by seven.  So if we have J=2, then we get J=14.  That gives us an offset of 14 bytes.  So, we have eliminated tiles and we have a current estimate of which byte we are going to draw: (X for an eliminated tile)
XXXXXXXXXXXX
XXXXXXXXXXXX
10000000000001
10000000000001
10000000000001
10000000000001
10000000000001
10000000000001
11111111111111
Now, we just add the I value to get the current X offset, getting us the actual byte we need (I=3):
XXXXXXXXXXXX
XXXXXXXXXXXX
XXXXX00000001
10000000000001
10000000000001
10000000000001
10000000000001
10000000000001
11111111111111
Ta-da!  We have the correct byte. Now we can use voodoo magic to extract each individual digit from the byte, and draw it on-screen.

Getting a Tile
Hooray!  You drew a tilemap!  Congradulations!  Now, if you want to use something better than Pxl-Test to check collisions with it, you need to be able to get the value of a single tile.  I won't bother explaining this routine in detail, but just know I spent a half hour on it so you don't have to:
Code: (Axe Basic) [Select]
Lbl GT  ; X position in S, Y position in T.  Returns tile
S/7->S  // Swap 7 for the size of your tiles
T/7*7->T  // Yes, I know it is /7*7.  Leave it that way.  Unless you don't have 7x7 tiles, in which case you should change the values accordingly
If S^2
{(S/2)+T+GDB1}^16
Return
End
{(S/2)+T+GDB1}/16
Return

More Than 16 Tiles
You may get to here and realize that, using this method, you can only have up to 16 tiles, one for each digit 0-F.  This is true.  However, you can have different tiles for different maps.  What?  You can only have 16 tiles per map, but you can have 16 unique tiles per map.  So, you can have different "themes" for each map.  It's easy.  Here is a revised draw method:
Code: (Axe Basic) [Select]
ClrDraw
For(I,0,7  // Start at zero, and go until your tile map width diveded by two (because we store two tiles for every one byte)
For(J,0,8  // The Y axis has one byte to each tile, so you can just use the height here.
{J*9+I+GDB1->A  // J*9 gets us the row offset (see below) and we just add the X value.
A^16->B // Get the second digit of the hex into B
A/16->A // And the first digit into A
If A
Pt-On(I*14,J*7,O*8+Pic1+A-8  // I*14 because of the two tiles to a byte, J*7 because of 7 pixel tiles.  O is the offset
End
If B
Pt-On(I*14+7,J*7,O*8+Pic1+B-8
End
End
End

You'll notice we added "O*8+" to the Pt-On lines.  This will make it so that you can specify O as an offset sprite.  So, if you wanted an entirely new set of tiles, you can specify O as 16, which would point to the sprites after the first set.  If you wanted to add one new sprite and lose the first old sprite, you could specify 1.  If you want the original sprites, specify O=0.

If you have any questions, feel free to post them, and I will do my best to answer.

Also, 400th post!  ;D
Title: Re: Tutorial: Tilemaps in Axe Basic
Post by: Eeems on April 07, 2010, 11:33:19 am
sweet! this could come in handy for my mario game....if you want I can style this with my tutorial style I had in my tutorial.
Title: Re: Tutorial: Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 11:34:26 am
Can you email me your idea for the format before you do?
Title: Re: Tutorial: Tilemaps in Axe Basic
Post by: Eeems on April 07, 2010, 11:39:31 am
I could just PM you actually, you can edit it for yourself and then I'll actually apply the post so it will work.
Title: Re: Tutorial: Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 11:39:55 am
Mmkay, please do so.
Title: Re: Tutorial: Tilemaps in Axe Basic
Post by: Eeems on April 07, 2010, 11:44:59 am
done, also, I'll have to apply it later today, class ended
Title: Re: Tutorial: Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 07, 2010, 12:29:53 pm
Thanks a lot, I think I am getting the grasp of tilemapping in Axe, but I haven't messed around with them as much yet. Hopefully this should be very useful if I get problems or missed something.

Nice tutorial :)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 12:33:39 pm
Thanks.  I have been thinking about releasing this one for a while, it was just finally prompted by my lack of respect on this forum.  It's down to 1 :O, I want to restore some of my credibility.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 07, 2010, 12:36:26 pm
mhmm strange it has been a while since I actually saw it drop a lot :O. It was at 9 then dropped to 0 a few weeks ago, though, but since then I think it remained kinda stable :P

projects updates/tutorials/helping can help increase it, though (unless activity is ridiculously high, like last night around 11PM-1AM of my time)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 01:08:11 pm
Yeah, I just need less complex projects to get more frequent updates :P
HL2: OC, LinTIx, and Mosaic are my major projects, and they are all pretty hefty.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 05:22:47 pm
Nice tutorial. I'm not sure if I followed it all but that's just from lack of Axe knowledge.

(By the way, as a tip for the future. BBCode doesn't work inside the [code ][/code ] command (I just noticed the [b ][/b] to try to bold and thought I'd let ya know for the future.).)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 07, 2010, 05:35:43 pm
What I do if I need bbcode is

Code: [Select]
[quote][font=monospace]text
goes
here[/font][/quote]

Then check the "Don't use smileys" box.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 06:03:29 pm
@DJ What do you mean exactly? What you said just isn't making sense to me is all, sorry.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 07, 2010, 06:42:48 pm
Could someone else explain for me? I don't really have the patience to explain stuff like this this evening when I alerady done enough effort to do so. No offense intended.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 07:03:21 pm
Oh, sorry, DJ. I wasn't trying to be rude or anything. When I read what you said it just wasn't making sense in my head for some reason (probably my lack of sleep). I think I get it now though. Did you mean that instead of using "code" to have a box around it you use "quote" when you still need BBCode inside (since BBCode doesn't work in "code")? Sorry again, wasn't trying to aggravate you or anything like that.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Eeems on April 07, 2010, 07:03:23 pm
if he wants bbcode to work in a "codebox" then he will use what he posted above which makes the font monospaced which is what codebox's do.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 07:10:10 pm
Weirdly enough I don't think [ font=monospaced][/font] actually truely monospaces it (like it fixes some but not all). I did find that the teletype thing does though. Sorry, not trying to make that sound rude, just thought I'd tell you is all. (Unless my definition of monospacing is different from your guy's, in which case I'm quite sorry. I'm really not trying to make anyone mad.)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 07, 2010, 07:36:42 pm
nah I didn't think you were rude at all, I just had a bit less patience today in overall. For some reasons monospace seems to work fine for me, but it doesn't do multiple spaces in a row sometimes. However, I doN't know which other font can be used in SMF forum software. Normally monospace should be... well... monospaced x.x

Oh well, I guess there isn't really a perfect alternative to bbcode not working in [ code ], then
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 08:00:04 pm
Oh ok, well I'm sorry about that, hope everything is ok.

For the monospace thing. It's weird because on my computer (I haven't tested different browsers but I haven't seen BBCode not work in some and work in others) when I type monospaced in with the "font" command it literally monospaces it like one space (or pixel or what ever, I don't know what unit of measurement it would be). I don't know if this will show up the same on everyone else's computer but here is what I mean:

Regular Type:
IIII
I  I
I  I
IIII

Coded Type:
Code: [Select]
IIII
I  I
I  I
IIII

Monospaced Type:
IIII
I  I
I  I
IIII


Teletype Type:
IIII
I  I
I  I
IIII


Quote-Monospaced Type:
Quote
IIII
I  I
I  I
IIII

Well this is interesting. I just did the "quote/monospaced" combo and it does what is supposed to. Wasn't expecting that but that's cool. But the plain "monospaced" type shows what I meant about the no monospacing thing.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 07, 2010, 08:11:28 pm
Don't worry too much about it


About the fonts, strange, for me now it's in the quote that fails to show it fine and all others are fine x.x

I guess it depends of computers. Maybe you have a different version of monospace fonts? (or maybe it's a cross-browser compatibility issue?)

Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Eeems on April 07, 2010, 08:17:55 pm
hmm, I'm getting the same problem he is...weird....and I'm on vista...
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 08:19:08 pm
I fixed the [/b] problem.  (Lol)  *If only I could post HTML...*
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 08:19:19 pm
Ya, I see that. That's weird. ??? Well it's not that big of a deal, I'll check my other browsers later tonight though just to check.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 07, 2010, 08:25:24 pm
*If only I could post HTML...*
then every regular members could rickroll daily
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 09:02:27 pm
then every regular members could rickroll daily

Nothin' wrong with that ;D
Glad you guys like the tutorial.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 10:56:46 pm
In the eighth row you still have the front half of the bold command :P But ya, great tutorial, thanks for writing it.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 07, 2010, 10:58:36 pm
/me goes to edit
Thank you on both counts.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 07, 2010, 11:09:20 pm
No problem, just tryin' to help out.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 08, 2010, 12:44:27 am
No, I really appriciate criticisim.  It makes it so I can improve.
Unless it's a mindless rant.

Anyway, I got my respect back up to +5, so I'll be doing more super-cool stuff in the near future.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 08, 2010, 01:11:54 am
Wait if I drop it to 0 you stop coding altogether? D:

Or do you mean once you reach 10 you launch a huge troll on the forum, then wait until it's back at 10 then launch another? D:

j/k I hope to see more progress on your projects ^^ (altough with school it must be hectic)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 08, 2010, 08:30:18 am
Lol thanks :P
No, I will not stop coding because a calculator forum doesn't like me.  No, I will not start trolling as soon as I hit 10.
Yes, it is very hard to update projects with school and work combined.  I do get to work a lot on Half Life 2 during school, but not on Mosaic.  LinTIx is very slow going, that will pick up more in the summer.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 08, 2010, 09:41:09 am
Keep in mind negative respect != forum community disliking you, though. It can pretty much be a few posts in particular the community dislike :P

And the thing I always loved the most with TI-BASIC (and now Axe) is how it's programmable on-calc easily, altough of course there are ways to do it with ASM too.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 08, 2010, 06:50:07 pm
Yeah, I know less respect does not mean that a community dislikes me.  I exagerrated for the sake of argument.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: lafferjm on April 15, 2010, 04:17:49 pm
I am having problems with this.  I type in everythng as you have it except for the J*7 part since i am using 8x8 sprites.  I changed it to J*8 on both lines, and then for my sprite added this after the tilemap:
Code: [Select]
[FFFFFFFFFFFFFFFF->Pic1
It does fine except at runtime.  The sprites are unaligned and everywhere on the screen, and where there should be a blank space it is something completely random.  If I can figure out how to post a screenshot i will do so.

Edit:  Pic is below as an attachment so i guess that will work.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 15, 2010, 04:39:38 pm
Can you attach the whole code?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 15, 2010, 04:56:31 pm
Oh hi Lafferjm and welcome here. You should post the entire code since something else in the code could very well be causing the error, not to mention if it happens to be an Axe bug, then Quigibo can apply the hammer tool on his calc a few more times to fix it. :)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: lafferjm on April 15, 2010, 05:26:18 pm
Code: [Select]
:.B
:[1111→GDB1
:[1001
:[1001
:[1111
:[FFFFFFFFFFFFFFFF→Pic1
:ClrDraw
:For(I,0,7
:For(J,0,8
:{J*9+I+GDB1→A
:A^16→B
:A/16→A
:If A
:Pt-On(I*14,J*8,Pic1+A-8
:End
:If B
:Pt-On(I*14,J*8,Pic1+B-8
:End
:End
:End
© Copyright 2000-2010 Cemetech & Kerm Martian :: Page Execution Time: 0.234438 seconds.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: {AP} on April 15, 2010, 05:36:08 pm
Try this:

Code: [Select]
:.B
:[1111→GDB1
:[1001
:[1001
:[1111
:[FFFFFFFFFFFFFFFF→Pic1
:ClrDraw
:For(I,0,6
:For(J,0,7
:{J*8+I+GDB1→A
:A^16→B
:A/16→A
:If A
:Pt-On(I*14,J*8,Pic1+A-8
:End
:If B
:Pt-On(I*14,J*8,Pic1+B-8
:End
:End
:End
© Copyright 2000-2010 Cemetech & Kerm Martian :: Page Execution Time: 0.234438 seconds.

8x8 sprites can't have a 14x9 map. So this changes it to 12x8. (which should be fine)
This just changed the 3 lines below ClrDraw.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: lafferjm on April 15, 2010, 05:44:14 pm
Still didn't work.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 15, 2010, 05:45:39 pm
Are you sure you downloaded the right version of Axe?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 15, 2010, 05:48:02 pm
Code: [Select]
:.B
:[1111→GDB1
:[1001
:[1001
:[1111
:[FFFFFFFFFFFFFFFF→Pic1
:ClrDraw
:For(I,0,1           <-------------
:For(J,0,3           <-------------
:{J*2+I+GDB1→A    <--------------
:A^16→B
:A/16→A
:If A
:Pt-On(I*14,J*8,Pic1+A*8-8  <------------
:End
:If B
:Pt-On(I*14,J*8,Pic1+B-8
:End
:End
:End
© Copyright 2000-2010 Cemetech & Kerm Martian :: Page Execution Time: 0.234438 seconds.

Try this, and if it works I'll tell you why.  I don't want to give you misinformation.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: {AP} on April 15, 2010, 05:49:48 pm
Yeah, SirCmpwn saw what I just noticed... >.<
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: lafferjm on April 15, 2010, 07:18:18 pm
It still isn't working, it is the same thing as before just on a smaller area of the screen.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Quigibo on April 15, 2010, 07:24:27 pm
I think its becasue you forgot to close the parenthesis on {J*2+I+GDB1}→A

Remember, parenthesis matter when storing to variables.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 15, 2010, 07:27:50 pm
I loaded the last code in Sourcecoder, saved, opened in Wabbitemu, making sure the code was intact, compiled fine with latest Axe version, and when running Asm(prgmB it just says Done
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: lafferjm on April 15, 2010, 09:05:07 pm
I think its becasue you forgot to close the parenthesis on {J*2+I+GDB1}→A

Remember, parenthesis matter when storing to variables.

Tried doing that and it still didn't work.

I loaded the last code in Sourcecoder, saved, opened in Wabbitemu, making sure the code was intact, compiled fine with latest Axe version, and when running Asm(prgmB it just says Done

Don't forget the DispGraph at the end.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 15, 2010, 09:23:30 pm
oh ok thatnks x.x

EDIT: ok I get the same problem as Lafferjm
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Quigibo on April 15, 2010, 09:56:20 pm
Okay I'm starting with the original code and making revisions.  I bolded things that needed fixing:

:.B
:[1111→GDB1
:[1001
:[1001
:[1111
:[FFFFFFFFFFFFFFFF→Pic1
:ClrDraw
:For(I,0,1
:For(J,0,3
:{J*2+I+GDB1}→A      <--Grid is 2x4 bytes.
:A^16→B
:A/16→A
:If A
:Pt-On(I*8,J*8,A-1*8+Pic1     <--Don't forget, order of operations is left to right always.
:End
:If B
:Pt-On(I*8,J*8,B-1*8+Pic1     <--Minus 1 is more efficient than minus 8 anyway
:End
:End
:End
:DispGraph

If this doesn't work then something is wrong...
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 15, 2010, 10:01:05 pm
Is it supposed to do the following?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: lafferjm on April 15, 2010, 10:10:44 pm
It works now, thank you.  Now to go over the code and see why it works.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: _player1537 on April 18, 2010, 03:40:11 pm
well, figured since there was already a tilemapper in axe thread I would put this here.  I made another tilemapper that works with 8x8 sprites, and scrolls.  I believe it works on the same principle as SIr's program, I'll have to look at it a bit more.  anyways, here goes (it's attached at the bottom as well)

Pic3 holds the tilemap data
Pic4 holds the tile data
W is the X position for the tilemapper
R is the Y position
W is how many bytes each row of tile makes (ie in a tilemap of 18x5, 18/2=9=W)  W is also used to check if you are too far in one direction
I didn't add something to limit the Y movement, you'll have to add that yourself, not too much work really
Code: [Select]
:.B
:Full
:[0000000000000000FFFFFFFFFFFFFFFF→Pic4
:[111111111111111100→Pic3
:[000000000000000000
:[000000000000000000
:[000000000000000000
:[000000000000000000
:[000000000000010100
:[000000000000001010
:[000000000000000101
:[000000000000000000
:9→M
:2→W
:0→R
:ClrDraw
:Repeat getKey(15)
:Repeat getKey(0)
:End
:
:If getKey(2)
:W-1+(W=2)→W
:End
:If getKey(3)
:W+1-(2*M-8=W)→W
:End
:If getKey(4)
:R-1+(R=0)→R
:End
:If getKey(1)
:R+1→R
:End
:sub(AA)
:DispGraph
:Pause 100
:End
:
:
:Return
:Lbl AA
:For(V,0,7
:For(Z,0,3
:Pt-Off(16*Z+(W^2*8),8*V,Pic4+({R+V*M+Pic3+Z+(W/2)+(W^2)}/16*8)
:Pt-Off(16*Z+8-(W^2*8),8*V,Pic4+({R+V*M+Pic3+Z+(W/2)}^16*8)
:End
:End
:

Lbl AA is the specific tilemapping part, the rest just shows how to use it

hope it proves useful to someone
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 18, 2010, 04:29:50 pm
D:
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 18, 2010, 04:40:52 pm
DJ, try changing a single character.  For example, add a single comment anywhere in the code.  Then, try it again.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 18, 2010, 04:43:07 pm
still no luck
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: _player1537 on April 18, 2010, 04:45:26 pm
try making your own map, just use some random map but keep the lbl A part and try it (might be group corruption which would suck)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on April 18, 2010, 04:50:57 pm
Could you post your full code?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 18, 2010, 04:57:53 pm
no need to post the full code, all I did was adding a line break, changing map data a bit then trying, then changing it back, removing comments and stuff


This means there's a problem with the posted code or it's an Axe Parser bug
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: _player1537 on April 18, 2010, 05:00:19 pm
sorry, I forgot to attach the file, woops.  It's attached to the original post now
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 18, 2010, 05:06:40 pm
Ok ty the attached file works. Is the tilemapper supposed to look weird like this tho? It doesn't appear to have any limit of how much it can scroll down.

Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: {AP} on April 18, 2010, 05:11:06 pm
Yeah, he didn't put a limit on the Y movement for whatever reason.
Quote
I didn't add something to limit the Y movement, you'll have to add that yourself, not too much work really
Personally, I'd think that if you were sharing an engine, that you'd at least get it to run right on it's own without those weird errors.
If they edit it from there and it messes up, THEN it's the user's problem.

To each his own, I guess.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 18, 2010, 05:34:11 pm
yeah I kinda agree with AP. I think it's best to add a limit so the user won't need to code it himself. If he wants a greater limit then he just change a number. Less risks of messing up
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 18, 2010, 06:11:26 pm
What does a tilemapper do exactly?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: {AP} on April 18, 2010, 06:18:21 pm
It basically reads map information (stored however the tilemapper wants) and then displays a map on the screen based on that information.
Usually contains scrolling or map changing if scrolling isn't supported.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: _player1537 on April 18, 2010, 06:21:25 pm
it basicly just scrolls an 8x8 tile map, Pic3 holds the actual data for the tiles, pic4 holds the sprite you use.  so if the Pic3 says 0, it will use the first sprite in Pic4.  If it says 1, it will use the next sprite in pic4.  I'm pretty sure it is like Sir's, but I'm not sure if his scrolls.  yeah, I probably should have added a limit to the Y movement, but wasn't sure what it should be (and wanted it variable without actually using a variable, ie I'd like to change something at the beggining of the program instead of deep inside the program, without using a different variable, eh oh well).  give me a sec to update the code with a Y limit of 8.

Edit: beaten to it
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: {AP} on April 18, 2010, 06:24:06 pm
Thanks, _player.
Sorry, if I sounded kinda like an asshole in my message, but it kinda had to be said.
I still thank you for the contribution. Minus the bug, it looks great.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on April 18, 2010, 06:27:55 pm
Ah ok, I think I get it then. That's cool. Thanks, both of you, for explaining :)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on April 18, 2010, 06:41:30 pm
Some programmers starts programming games by hardcoding collision detections. In some cases this works OK but in the end your code becomes massive because you have an entire program for per room and some rooms are considerably slower. I wonder if that's what games like Final Fantasy VII, VIII, Legend of Dragoon and Star Ocean 2 do
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: nemo on June 01, 2010, 07:49:18 pm
i don't understand how this routine gets a tile. could someone explain it in depth?

Code: [Select]
Lbl GT  ; X position in S, Y position in T.  Returns tile
S/7->S  // Swap 7 for the size of your tiles
T/7*7->T  // Yes, I know it is /7*7.  Leave it that way.  Unless you don't have 7x7 tiles, in which case you should change the values accordingly
If S^2
{(S/2)+T+GDB1}^16
Return
End
{(S/2)+T+GDB1}/16
Return
sorry for bringing up an old post, but it seems like a useful topic to keep alive anyway.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on June 05, 2010, 09:01:37 am
Well, Axe doesn't support floating point numbers, or numbers with a decimal.  Therefore, if you have 7x7 tiles, dividing it by 7 will return the tile number, instead of the pixel number.  Then, {(S/2)+T+GDB1}^16 returns the second nibble, and {(S/2)+T+GDB1}/16 will return the first nibble.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: jsj795 on June 05, 2010, 10:09:46 am
For the half byte tilemap, you can only display total of 16 sprites per map, even if the sprite size is less than 8*8, right?
And for the one byte tilemap, can you display total of 16*16 sprites? (too lazy to do math :P)
How big are the data in the Axe tho? Like, let's say I want 30x50 map with one byte tilemap. How much memory does it take?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: _player1537 on June 05, 2010, 10:20:48 am
30x50, 1500 bytes.  for the first question and the second, yes.  
Edit: fail, 30x50 is 1500 not 150 woops :P
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: jsj795 on June 05, 2010, 10:46:22 am
oh okay, and the half-byte 30X50 would be 750... lol i got it^^
I thought it would be more, like how in BASIC the matrix is huge :/
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on June 07, 2010, 04:38:32 am
Btw I think Kindermoumoute would appreciate if someone could translate this tutorial into French. I could maybe do it but I suck at grammar and the french I would use isn't always understandable by non-Canadian users (the reason why I almost always speak English with Silver Shadow and Lionel Debroux, despite all of us speaking French as native language) :(

http://ourl.ca/4881/93140 (http://ourl.ca/4881/93140)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: meishe91 on July 17, 2010, 06:19:52 pm
Hey Sir, any chance of this thing maybe getting updated or anything? Just curious :)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on July 19, 2010, 08:15:58 pm
I think this was discontinued because he was working on a bigger and better tutorial including that stuff. However, I have some doubts it will be worked on soon, judging he last said that months ago and that he now focuses on his OS, IDE and maybe will revive his contest entry or something
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: MRide on July 26, 2010, 11:55:31 pm
Is it supposed to do the following?

Uh...that's not right.  That's only a 2*4 map.  The data was for a 4*4 map.  I think one of the things that is confusing people (especially me) is the numbers used.  If the numbers are all the same (dimension of tiles and map), then we can't tell where those came from.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: nemo on July 27, 2010, 12:10:49 am
hmm... this works on my calculator:

Code: [Select]
.A
[11111111->GDB1
[10011001
[10100101
[11111111
[0000000000000000->Pic1
[FFFFFFFFFFFFFFFF
For(Y,0,3
For(X,0,3
{Y*4+X+GDB1}->A
Pt-On(X*16,Y*8,A/16*8+Pic1
Pt-On(X*16+8,Y*8,A^16*8+Pic1
End
End
DispGraph

edit: i'm not sure which parts would be confusing to people, so i left out anything unnecessary. i'll respond best i can to anyone who posts though
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: MRide on July 27, 2010, 12:25:29 am
That same code gives me alternating black and white stripes of 8*32 pixels.  (and there are eight stripes)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: nemo on July 27, 2010, 12:33:16 am
hmm that's partially good, because the map's dimensions match the dimensions you described (8 8x32 stripes means the map is 64 pixels wide by 32 high, divide that by eight (the size of the tiles) and you get 8 tiles wide by 4 tiles high).

i think i found the bug. are you sure that the following line is typed correctly on your calculator?
Code: [Select]
Pt-On(X*16+8,Y*8,A^16*8+Pic1

because if you forgot the +8, you end up with alternating lines as you said.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: MRide on July 27, 2010, 12:38:51 am
Oh. wow......
Thanks. this whole thing was driving me crazy (sitting in a Dairy Queen with my calc, no access to a computer, and randomly changing numbers)
Sorry you had to track down the bug.  My mind doesn't seem to work right late at night.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: nemo on July 27, 2010, 12:51:32 am
oh it's no problem. now i'm getting myself started on how to smooth scroll a half byte tilemap...
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on July 27, 2010, 10:58:08 am
Wow, that one was tough.  What you have to do is draw an extra row and column, and then offset them all by the scroll value, and use the scroll value / 16 for the X offset, and the scroll value / 8 for the Y offset.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on July 29, 2010, 03:10:56 am
It would be nice to have a tutorial on how to do it. Something that is a bit visual with simple examples maybe, and maybe an example with single-byte so people can see the difference. Smooth scrolling is generally not too hard when you get used to modulus (if you redraw the entire tilemap every frame), but I am not sure how it works when using Horiz, variable scrolling speeds (like in Supersonic Ball) or half-bytes. Would it be fast enough for the regular 83+?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on July 31, 2010, 11:50:36 am
From my experience, it is not fast enough to use on a regular 83+.  It may be feasible, however, to use it in a casual game, where the tilemapping speed has little impact on the gameplay, such as Pokemon.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on August 01, 2010, 12:48:54 pm
Aaah ok. I guess it would be best to keep for RPGs if done on 83+ then. That said, half-byte scrolling in RPGs is almost a must in RPGs with simpler maps (16 tiles or below, for example), since it decreases the file size considerably
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: collechess on May 18, 2011, 05:31:06 pm
In
Code: [Select]
Lbl GT  ; X position in S, Y position in T.  Returns tile
S/7->S  // Swap 7 for the size of your tiles
T/7*7->T  // Yes, I know it is /7*7.  Leave it that way.  Unless you don't have 7x7 tiles, in which case you should change the values accordingly
If S^2
{(S/2)+T+GDB1}^16
Return
End
{(S/2)+T+GDB1}/16
Return
How do you access the value of the tile?
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: yunhua98 on May 18, 2011, 05:34:43 pm
Not trying to put Sir down, since he's an awesome coder, but this tutorial is outdated and the last post here was early August.  It may not work with current versions of Axe.

Try this (http://ourl.ca/9601) tile mapping tutorial.  ;)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: squidgetx on May 19, 2011, 07:14:25 am
Who stickied this? It's already listed in the tutorials thread :P
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: SirCmpwn on June 30, 2011, 01:21:13 pm
This tutorial is outdated, but it still works fine for newer versions of Axe.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: nikitouzz on July 17, 2012, 01:24:11 pm
where is sircmpwn ?  :o
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Juju on July 17, 2012, 01:26:28 pm
He's banned.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: nikitouzz on July 18, 2012, 05:24:25 am
...
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Stefan Bauwens on July 18, 2012, 07:32:45 am
...
Yeah, it's a long story. Of what I heard it was pretty much deserved, but there's no need to be digging into the past.
Also you should try to avoid one-word posts like yours. ;)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Hayleia on July 18, 2012, 08:08:27 am
Also you should try to avoid one-word posts like yours. ;)
There was not even one word :P

Also, nikitouzz, if you really want to talk to SirCmpwn, I think he didn't get banned from Cemetech so you might be able to contact him from there :)
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: JosJuice on July 18, 2012, 08:39:12 am
Also, nikitouzz, if you really want to talk to SirCmpwn, I think he didn't get banned from Cemetech so you might be able to contact him from there :)
He's actually banned there too.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: Hayleia on July 18, 2012, 08:45:17 am
Also, nikitouzz, if you really want to talk to SirCmpwn, I think he didn't get banned from Cemetech so you might be able to contact him from there :)
He's actually banned there too.
Ah ok, I didn't know that. I am less often on Cemetech than on Omnimaga.
Title: Re: [Tutorial] Tilemaps in Axe Basic
Post by: DJ Omnimaga on July 29, 2012, 10:53:35 am
Well you know it's bad when you get banned from both Cemetech and Omni at once, but that's a long story. It would definitively be best to contact the administration of both sites to know more details. And of course avoiding 1-word posts or posts only containing "...."