I am programming my game SoulQuest, and I need a faster collision checking routine.

Code:
``` //Matrix for Tile Map [[1,1,1,1,1,1,1,1,1,1,1,1][1,7,8,8,8,8,19,12,8,8,9,1][1,5,0,0,0,0,0,10,0,0,6,1][1,7,8,8,8,8,8,14,8,8,9,1][1,5,0,0,0,0,0,0,0,18,6,1][1,5,38,0,0,0,0,0,0,17,6,1][1,2,3,3,3,3,3,3,3,3,4,1][1,1,1,1,1,1,1,1,1,1,1,1->[A] //List for tile ids that you cannot pass through {1,15,16,17,18,19,20,24,25,26,27,28,29,30,31,32,33,34,37,39,40,41,42,43,50,51,52,60,61,62,63,66,67,~1->L1 //Pic for character sprites identity(0,"SQthetaPIC",6,8,1 //Pic for tiles identity(0,"SQthetaPIC",6,7,10 //Init sprite coords 5->X:5->Y DrawTileMap(0,0,0,8,12,0,12,0,8,10,0 DrawSprite(8(X-1),8(Y-1),1,16,1,0,0,3,0 //Main Loop While Ans!=54 GetKey( While Ans=0 GetKey( End //If down key is pressed If Ans=1:Then DrawTileMap(0,0,0,12,8,0,12,0,8,10,0 1->A [A](Y+1,X->B Repeat B=L1(A) or L1(A)=-1 A+1->A End Y+(C=-1->Y DrawSprite(8(X-1),8(Y-1),1,16,1,0,0,0,0 End //If left key is pressed If Ans=2:Then DrawTileMap(0,0,0,12,8,0,12,0,8,10,0 1->A [A](Y,X-1->B Repeat B=L1(A) or L1(A)=-1 A+1->A End X-(C=-1->X DrawSprite(8(X-1),8(Y-1),1,16,1,1,0,0,1 End //If right key is pressed If Ans=3:Then DrawTileMap(0,0,0,8,12,0,12,0,8,10,0 1->A [A](Y,X+1->B Repeat B=L1(A) or L1(A)=-1 A+1->A End X+(C=-1->X DrawSprite(8(X-1),8(Y-1),1,16,1,1,0,0,0 End If Ans=4:Then DrawTileMap(0,0,0,12,8,0,12,0,8,10,0 Y-(C=~1->Y DrawSprite(8(X-1),8(Y-1),1,16,1,2,0,0,0 End End ```

In case you missed the collision code, it's in every key if statement:

Code:
``` 1->A //Init dim of L1 [A](Y+1/-1,X+1/-1->B //The tile in which is ahead of the direction you are going (for example, If you are going down, it's [A](Y+1,X) (Also a pre-evalution optimization) Repeat B=L1(A) or L1(A)=-1  //Repeat until the tile id equals a non-passable tile id or -1 (which represents a passable tile if the tile id from the matrix doesn't match up) A+1->A //Scroll through the list with increasing A End X/Y +/- (L1(A)=-1->X/Y //Increments/decrements sprites position if tile's id is passable ```

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum