Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: FinaleTI on January 03, 2011, 05:08:51 pm

Title: Unique Pure BASIC Scrolling Tilemapper
Post by: FinaleTI on January 03, 2011, 05:08:51 pm
This tilemapper that I made is unique in that it uses pictures for the source.
Generally Pure BASIC scrolling tilemappers use strings, which while a little faster, they can be much larger.
So I tried to make one of these kind of mappers before, but I didn't handle it quite right, and it was incredibly slow. This one is much faster than the old one that I've since lost.
I've only run this on an SE, so I don't know how fast it is in 6 mHz.
Attached is the engine and the map I used in the screenie.
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: meishe91 on January 03, 2011, 06:42:48 pm
Looks cool. I'll check it out sometime soon hopefully. What do you mean though by it uses pictures as source?
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: FinaleTI on January 03, 2011, 06:54:26 pm
I mean it determines your map from the pixels in a picture.
So if a pixel is on, it draws a wall tile, but if the pixel is off, it draws a floor tile.
The tiles are stored in Str2, in the order of floor tile, wall tile.
So you if you want 'L' to be your floor and 'F' to be your wall your Str2 would be "LF".
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: Eeems on January 03, 2011, 07:15:13 pm
Reminds me of Illusiat 12 :)
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: FinaleTI on January 03, 2011, 07:22:18 pm
Yep. The Illusiat games are what made me wanna make this, although the mapping style is closer to that of Illusiat 11.
I did use a map from Illusiat 12 to test with. That's the map I used in the screenie.
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: ztrumpet on January 03, 2011, 07:23:08 pm
Fascinating!

This is just about the coolest tilemapper I've ever scene.  I really like it.  Map props, man. ;D

Here's the very interesting code, if anyone else was baffled by the incredible speed:
Spoiler For Code:
:ClrDraw
:ClrHome
:RecallPic 2
:Disp
:44→A:14→B
:34→K
:"LN"→Str2
:"
:For(θ,0,7
:For(Z,0,15
:Ans+sub(Str2,pxl-Test(θ+A,Z+B)+1,1
:End
:Output(1,1,sub(Ans,2,length(Ans)-1
:End
:sub(Ans,2,128→Str1
:Repeat K=45
:Output(1,1,Str1
:Output(4,8,sub("ÌÏÌ      ÎÎ",K-23,1
:Repeat max(K={24,25,26,34,33,45
:getKey→K
:End
:If K=33
:Then
:Text(0,0,"
:Repeat getKey=45
:Pxl-Change(A+3,B+7
:End
:Pxl-Off(A+3,B+7
:End
:If K=26 and B<79 and not(pxl-Test(A+3,B+8
:Then
:B+1→B
:"
:For(θ,0,7)
:Ans+sub(Str2,pxl-Test(A+θ,B+15)+1,1
:End
:sub(Ans,2,8
:sub(Str1,2,15)+sub(Ans,1,1)+sub(Str1,18,15)+sub(Ans,2,1)+sub(Str1,34,15)+sub(Ans,3,1)+sub(Str1,50,15)+sub(Ans,4,1)+sub(Str1,66,15)+sub(Ans,5,1)+sub(Str1,82,15)+sub(Ans,6,1)+sub(Str1,98,15)+sub(Ans,7,1)+sub(Str1,114,15)+sub(Ans,8,1→Str1
:End
:If K=24 and B and not(pxl-Test(A+3,B+6
:Then
:B-1→B
:"
:For(θ,0,7)
:Ans+sub(Str2,pxl-Test(A+θ,B)+1,1
:End
:sub(Ans,2,8
:sub(Ans,1,1)+sub(Str1,1,15)+sub(Ans,2,1)+sub(Str1,17,15)+sub(Ans,3,1)+sub(Str1,33,15)+sub(Ans,4,1)+sub(Str1,49,15)+sub(Ans,5,1)+sub(Str1,65,15)+sub(Ans,6,1)+sub(Str1,81,15)+sub(Ans,7,1)+sub(Str1,97,15)+sub(Ans,8,1)+sub(Str1,113,15→Str1
:End
:If K=34 and A<55 and not(pxl-Test(A+4,B+7
:Then
:A+1→A
:"
:For(Z,0,15)
:Ans+sub(Str2,pxl-Test(A+7,B+Z)+1,1
:End
:sub(Str1,17,112)+sub(Ans,2,16→Str1
:End
:If K=25 and A and not(pxl-Test(A+2,B+7
:Then
:A-1→A
:"
:For(Z,0,15)
:Ans+sub(Str2,pxl-Test(A,B+Z)+1,1
:End
:sub(Ans,2,16)+sub(Str1,1,112→Str1
:End
:End
Generated by SourceCoder (http://sc.cemetech.net)
© 2005-2010 Cemetech (http://www.cemetech.net)
Excellent job! :D

Edit: Do you mind if I take a stab at making one of my own? O0
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: FinaleTI on January 03, 2011, 07:31:41 pm
Thanks. I'm really surprised with the speed I got, especially since the old one was so slow.
And feel free to make one! I'd love to see what you come up with.
I'm sure I can optimize mine in a few places, and I'm wondering about a few things that could slightly increase the speed.
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: fb39ca4 on January 03, 2011, 10:02:57 pm
Looks cool! But how do you read from the pictures in pure basic?
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: FinaleTI on January 04, 2011, 06:32:53 am
pxl-Test(). It's one of the fastest methods of collision detection in BASIC.
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: DJ Omnimaga on January 04, 2011, 03:34:57 pm
The code is huge so it confuses me, but do you actually pixel test, store an additional string char to the map, pixel test again, store another char, and that until you got 128 characters, then display the string? reading data from strings is slow but from pixel-test it's faster, so is it why it's much faster?
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: tifreak on January 04, 2011, 03:37:53 pm
Actually, if you look on ticalc.org, there was a Zelda game made on that principal. That was a goodly 8 years ago.

Nice job getting it figured out though. :)
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: DJ Omnimaga on January 04, 2011, 03:39:09 pm
Really? I never really saw that one.  Back then all BASIC games were in one section, though, so it was ridiculously hard to find anything there.
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: FinaleTI on January 04, 2011, 08:46:57 pm
The code is huge so it confuses me, but do you actually pixel test, store an additional string char to the map, pixel test again, store another char, and that until you got 128 characters, then display the string? reading data from strings is slow but from pixel-test it's faster, so is it why it's much faster?
The way I do it is I render the initial field upon start up of the program (I create the 128 char string through pxlTest()'s).
Then, say I move left.
Your X coordinate (B) is incremented.
The program pxlTest()'s the next column based on my coordinates (A+loop,B+15) in a loop, adding the generated tile to a string in Ans.
I end up with a 9 char string, so I chop off the starting space.
Then I add 15 chars from each line to each char in Ans, like the first line would be:
Code: [Select]
sub(Str1,2,15)+sub(Ans,1,1)+sub(Str1,18,15).....
This is all in the big concatenation thing at the end of each keypress If-Then.
Then it goes back to the beginning of the loop, displays Str1 and your character and waits for another keypress.

My old version of this engine didn't utilize Ans where I should have and instead I had it rebuild the string during the pxlTest() loop or something, so it was painfully slow.
I've also slightly modified the engine since I posted it and I think it's *barely* faster. :)

Actually, if you look on ticalc.org, there was a Zelda game made on that principal. That was a goodly 8 years ago.

Nice job getting it figured out though. :)
I saw that Zelda game, but unless I'm mistaken, the 83 version uses some sort of ASM code to help with the map drawing.
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: ztrumpet on January 04, 2011, 09:44:11 pm
I created my own version of this...
My old version of this engine didn't utilize Ans where I should have and instead I had it rebuild the string during the pxlTest() loop or something, so it was painfully slow.
...and it rebuilds the string in the loop instead of after. :)  I'll have to post mine sometime. ;D  (I may be building a game around it - Stay Tuned!!)
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: DJ Omnimaga on January 05, 2011, 02:46:01 am
Hmm I see. I am surprised so many sub() concatenations is so fast, though O.o

@Ztrumpet that would be cool!
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: meishe91 on January 05, 2011, 09:52:03 am
Well sub( is only usually slow if you're recalling a bit into a very long string. Otherwise I've always noticed it being pretty decently fast.
Title: Re: Unique Pure BASIC Scrolling Tilemapper
Post by: DJ Omnimaga on January 05, 2011, 06:55:34 pm
That's good, then :)

I wish I knew the string version of that trick back when I coded ROL series. The world map is like 4 times slower at the bottom. X.x