Omnimaga
Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: stevon8ter on May 30, 2012, 04:05:51 pm
-
Ok, what are the best ways to do collision detection in xlib? Could you also give a little example?
Collision detection only, codes for showing sprites aren't a must
-
Since tilemaps are drawn using matrices, use a string, convert it to a matrix when drawing the tilemap, delete the matrix, and then use the string for collision detection.
-
And how would i do that? :/ sorry, i'm
N00b
-
Use two nested For loops. Read one character from the string, using sub(), for each iteration, and write the corresponding value to the matrix (to convert a character to a value, you can use inString). Then use real(1,...) and then DelVar to delete the matrix. After that, store "sub(Str1,θ,1)" to r1.
-
writing and deleting the matrix every time something is drawn would be rather slow. you should just copy it over once at the beginning of your program and delete it at the end.
-
Collision detection with matrix is the easiest and fastest way to do so.
-
Actually it's not, if x-position = 48, then the coresponding matrix x-location = 7
And if you do 48/8 then you have 6. And if you then do 6+1 then the most left and most right tile give errors...
-
what you want to do is ipart(X/8)+1. I don't see how this will result in error tho, unless you're trying to move off screen.
In order to not get an error, you would have to do a conditional checking
Example of this:
If press left
Then
If X=0
Then
Change screen to left map
Else
If walkable=[A](ipart(Y/8)+1,ipart((X-1)/8)+1
X-1->X
End
End
If press right
Then
If X=86
Then
Change screen to right map
Else
If walkable=[A](ipart(Y/8)+1,ipart((X+8)/8)+1
X+1->X
End
End
-
Thx, first i didn't thought your code was working, but then i realised my sprite-drawing part was somewhere else, thx, it works great