Omnimaga
Calculator Community => TI Calculators => TI-BASIC => Topic started by: hellninjas on September 15, 2013, 05:20:17 pm
-
So I have this current problem while playing with tilemaps.
:ClrDraw
:8→X
:8→Y
:[[0,0,0,0,0,0,0,0,0,0,0,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,0,0,0,0,0,0,0,0,0,0,0]]→[A]
:
:0→K
:Repeat K=45
:¦
:¦ real(2,0,0,0,12,8,0,12,0,8,1,0,8,0
:¦ real(1,X,Y,1,8,1,2,0,0,0,1
:¦
:¦ X→S:Y→T
:¦
:¦ getKey→K
:¦ If K=24
:¦ X-8→X
:¦ If K=25
:¦ Y-8→Y
:¦ If K=26
:¦ X+8→X
:¦ If K=34
:¦ Y+8→Y
:¦
:¦ If [A](X,Y)=0:Then
:¦ ¦ S→X:T→Y
:¦ End
:
:End
And it seems to redirect me to the beginning line of code:
:8→X
:8→Y
://Beginning of Matrix : It directs me here.
I'm not sure what it is that's wrong with my code, and i've tried changing:
:¦ If [A](X,Y)=0:Then
:¦ ¦ S→X:T→Y
:¦ End
To:
:¦ If [A](X/8,Y/8)=0:Then
:¦ ¦ S→X:T→Y
:¦ End
But that seems to prevent me from going to most of the places on the tile-map.
So how would I get this to work..?
EDIT: Sorry, this is using xLIB. (Forgot to mention.)
-
Wait, do you mean it keeps looping back to the beginning of the code? That seems strange, considering there's no While/For/If/Repeat/etc before the 1st code you posted.
-
Sorry, I should've been more clear.
When I start the program, if I move my character left, or up, it gives me the error: "ERR:DIM"
Which, if I press "Goto Error" it brings me to that said line of code.
:8→X
:8→Y
://Beginning of Matrix : It directs me here.
-
Remember that matrices on the 83+ are column first, so it should be [A](Y,X).
-
Oh I found it! It took a while because I got used to HP BASIC >.<. With some TI-BASIC commands, X and Y are inverted, so instead of If [A](X,Y)=0 you have to use If [A](Y,X)=0. Even then, try to avoid using Y at any cost, because some TI-OS bug will often reset it to zero.
EDIT Ninja'd. I think that every pixel-based command are inverted, but not graph-based ones.
-
So because the values of X and Y reach 0, that's what I end up checking for in the Matrix, which doesn't have a 0,0.
But if I add one to X or Y than my sprite has the ability to go off the field.
This is getting frustrating :P
-
Just out of interest, where are you adding 1?
You only need to do it in the matrix check: If [A]((Y/8)+1,(X/8)+1)=0:Then
-
:ClrDraw
:16→X
:16→Y
:[[0,0,0,0,0,0,0,0,0,0,0,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,0,0,0,0,0,0,0,0,0,0,0]]→[A]
:
:0→K
:Repeat K=45
:¦
:¦ real(2,0,0,0,12,8,0,12,0,8,1,0,8,0
:¦ real(1,X,Y,1,8,1,2,0,0,0,1
:¦
:¦ X→S:Y→T
:¦
:¦ getKey→K
:¦ If K=24
:¦ X-8→X
:¦ If K=25
:¦ Y-8→Y
:¦ If K=26
:¦ X+8→X
:¦ If K=34
:¦ Y+8→Y
:¦
:¦ If [A]((X/8)+1,(Y/8)+1)=0:Then
:¦ ¦ S→X:T→Y
:¦ End
:
:End
Repasted~
-
You still have X then Y, Y needs to come first:
If [A]((Y/8)+1,(X/8)+1)=0:Then
:ClrDraw
:8→X
:8→Y
:[[0,0,0,0,0,0,0,0,0,0,0,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,1,1,1,1,1,1,1,1,1,1,0][0,0,0,0,0,0,0,0,0,0,0,0]]→[A]
:
:0→K
:Repeat K=45
:
:real(2,0,0,0,12,8,0,12,0,8,1,0,8,0
:real(1,X,Y,1,8,1,2,0,0,0,1
:
:X→S:Y→T
:
:getKey→K
:If K=24
:X-8→X
:If K=25
:Y-8→Y
:If K=26
:X+8→X
:If K=34
:Y+8→Y
:
:If [A]((Y/8)+1,(X/8)+1)=0:Then
:S→X:T→Y
:End
:End
-
Problem solved!
eheh
Thanks a bunch you two :3