Omnimaga

Calculator Community => TI Calculators => TI-BASIC => Topic started by: SuperSmashcz on December 19, 2006, 09:04:00 am

Title: Hit detection with xlib
Post by: SuperSmashcz on December 19, 2006, 09:04:00 am
Ok, im very very VERY new at xlib, and ive done all the tutorials, and i understnad how they work, ect..
But now id like to know how to do a hit detection with xlib  :)smile.gif
anyone point me in the right direction?

Also, ive been re reading the tutorial, and it saids we can only use 8X8 sprites? What? So i cant use a 16X16? :(sad.gif


P.S. Don't double post unless it is to bump or for other sensible reasons
Title: Hit detection with xlib
Post by: Speler on December 19, 2006, 09:40:00 am
Use edit button rather then double post.  Wait a little and someone who uses xlib will answer.
Title: Hit detection with xlib
Post by: Floodkiller on December 19, 2006, 11:06:00 am
1) Hit detection is what you make it.  If you know how to do matrix hit detection, you know how to do a basic hit detection in xlib.  Anything more complicated I haven't figured out yet, since my games haven't gotten to the point where I need a complicated hit detection.

2) You can use 16x16, just read the txt file with the xlib download in order to find out how to use each in your real( commands.
Title: Hit detection with xlib
Post by: SuperSmashcz on December 19, 2006, 12:06:00 pm
The problem is idk how to do a matrix hit detection..:(sad.gif All i want is a basic wall hit detection..
Title: Hit detection with xlib
Post by: dinhotheone on December 19, 2006, 12:07:00 pm
i belive the manual says the sprites must have width of multiples of 8, so 16 is definitely fine, you only have to write 2 for sprite width instead of 1 (along with 16 in height not 8)
Title: Hit detection with xlib
Post by: SuperSmashcz on December 19, 2006, 12:08:00 pm
Oh ok, *hits self* didnt think of that one :Dbiggrin.gif
Title: Hit detection with xlib
Post by: Speler on December 19, 2006, 03:19:00 pm
*Super Speler
Title: Hit detection with xlib
Post by: necro on December 19, 2006, 06:37:00 pm
@SuperSmashcz: please try to put a bit more content into each post...like when you said you got it, explain the method you now "get" in case it might help any other member in the future

@super speler:why not just merge the posts like I did?

Matrices can be used for a lot of complex tricks and as you can store several digits in a matrix in decimal (which xlib will ignore) you can store wether something is for instance a floor, wall, teleport, etc.  You could then retrive this data through a series of rounding methods...but this can get slow.  

And out of couriosity, is this forum actualy for xlib related coding advice/help?
Title: Hit detection with xlib
Post by: SuperSmashcz on December 21, 2006, 12:45:00 pm
Ok, apperently i didnt "got it"
  ive got all the map data in a matrix,im using xlib, if that helps, but ive got 0 as wall, and 2 as a walkable tile, im using 16X16 sprites, basicaly giant squares, the method for detection is using
If[A](A+X+1,B+X+1) =2 : then
does movement code

i cant understand whats wrong, the problem is on the left and bottem sides of the screen, the sprite can go into the wall sprite "half way", where on the left and top, it stops just before hitting the sprite. realy confusing, let me kno if u need more code.
Title: Hit detection with xlib
Post by: Floodkiller on December 22, 2006, 03:51:00 am
Well, if it hits it halfway, then either something is wrong with your displaying techniques, collision checks, or scrolling.  In my game, it was the scrolling, because the formula wasn't put together correctly and pushed the character 1 square ahead of the matrix's hit detection.  It was a simple fix (add one to the subtracted variable), but back to your problem. I would need more code from you, or I can't tell specifically what it is.
Title: Hit detection with xlib
Post by: dinhotheone on December 22, 2006, 01:42:00 pm
going halfway in is odd... the most plausible thing would be some mixup between bit numbers, like your scrolling an 8*8 char using a 16x16 tile map  or something. code would defenitely be useful though

Edit: just thought of some stuff... one thing that may be wrong is the fact that x and y on the matrix corrospond to the top left spot on the screen. so when you are calculating what spot you are on you have to subtract one from x and y when you add screen location coordinates with regular position coordinates. another thing that might be a problem is that if you are using smooth movent instead of jump movement (moving a pixel at a time instead a tile at a time) you have to check for hit detection on every corner of the sprite.
Title: Hit detection with xlib
Post by: Shazane Koronova on January 15, 2007, 08:37:00 am
I too have a problem with collision detection.

this is my code, X and Y are the coordinates of the sprite and are always multiples of 8:

c1-->
CODE
ec1
If [A](X/8,Y/8)=0
c2
ec2

in most places I get an invalid dimension error, and where I don't get that it just doesn't detect the collision and overwrites the tile.
Title: Hit detection with xlib
Post by: tifreak on January 15, 2007, 08:45:00 am
http://tifreakware.net/tutorials/83p/b/tifw/les8.htm

That tutorial explains hit detection using matrices, lists and strings. Not the greatest in the world, but it should help you out with learning how to create a good, simple hit detection routine...  
Title: Hit detection with xlib
Post by: necro on January 15, 2007, 08:49:00 am
yeah, would need to show more more code like how the player's drawing code works to be sure, but I think you need to swich the x and y in your case.
Title: Hit detection with xlib
Post by: Shazane Koronova on January 15, 2007, 09:06:00 am
QUOTE
Title: Hit detection with xlib
Post by: tifreak on January 16, 2007, 02:25:00 am
I think you would be better off having other variables represent the x and y, and get rid of the /8 for each. When the character moves, just update the variables. This way, it will not error out when it moves around the screen. :)smile.gif
Title: Hit detection with xlib
Post by: xiaden on October 30, 2007, 06:40:00 am
If it doesn't work when you are at location 0,0 thats because there is no 0 in a matrix.  your map is also offset in the topleft direction by one tile, right? i would just change your formula to:
c1-->
CODE
ec1if [a](Y/8+1,X/8+1) = ... whatever you had here..c2
ec2
that should fix it, and your map might get a lill bigger =P it you get errors on the outer edges now, thats because your matrixes arn't the same size.