Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: stevon8ter on May 30, 2012, 04:05:51 pm

Title: Xlib collision detection help
Post 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
Title: Re: Xlib collision detection help
Post by: blue_bear_94 on May 30, 2012, 04:07:32 pm
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.
Title: Re: Xlib collision detection help
Post by: stevon8ter on May 30, 2012, 04:08:40 pm
And how would i do that? :/ sorry, i'm
N00b
Title: Re: Xlib collision detection help
Post by: blue_bear_94 on May 30, 2012, 04:15:54 pm
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.
Title: Re: Xlib collision detection help
Post by: shmibs on May 31, 2012, 11:05:27 pm
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.
Title: Re: Xlib collision detection help
Post by: jsj795 on May 31, 2012, 11:11:13 pm
Collision detection with matrix is the easiest and fastest way to do so.
Title: Re: Xlib collision detection help
Post by: stevon8ter on June 01, 2012, 09:15:26 am
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...
Title: Re: Xlib collision detection help
Post by: jsj795 on June 01, 2012, 01:29:21 pm
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:
Code: [Select]
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
Title: Re: Xlib collision detection help
Post by: stevon8ter on June 01, 2012, 04:29:36 pm
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