|
Post by alovon on Jan 3, 2010 1:36:33 GMT -5
Ok so I'm making a small game using a tilemap and I'm having problems concerning collisions. I can't currently upload the code because I only have my phone for internet but I can give you a general brief on how everything works. The game is simple. It loads the player sprite and the tilemap then it centers the player and shifts the tilemap around to make it seem as if the player is moving. The players goal is to get to the red X in every level. Certian tiles are meant to block you or cause damage. I just don't know how to make you collide with those tiles using my movement system. Thanks in advance for any suggestions.
|
|
|
Post by Wayne Rayner on Jan 3, 2010 8:36:12 GMT -5
well this isn't going to be much help but, I remember dj linux helping me out on this type of thing for my maze game. I have searched my usb's and this forum and I can't seem to find it. I will keep looking so that you can get a source for how to do collision detection. my best guess would be something along the lines like this if player_spr = tile2 then health = - 1 that would be for the tile that hurts the player. and I wouldn't know how the other collision works but it should be similar and remember to declare all variables I hope I find the maze source code and I hope I have helped Wayne Rayner [Edit] Try this link it is to my maze help topic basic4gl.proboards.com/index.cgi?board=B4glhelp&action=display&thread=2508&page=1
|
|
|
Post by alovon on Jan 3, 2010 14:04:39 GMT -5
Thanks for the help, however after a few hours of attempting to work out the problem I just decided to change the movement system. Now all I get is an array index out of range error. The player moves about by increments of five. There are about 30 pixles of space between each tile. I'm really not sure what I did wrong now.
|
|
|
Post by alovon on Jan 3, 2010 14:07:35 GMT -5
Haha! Fixed it. I did my math wrong... Sadface. But I fixed the problem and now the game is running smooth. Thanks for all the help!
|
|
|
Post by alovon on Jan 7, 2010 0:08:22 GMT -5
Ok I've swapped the movement system back to the original one I had stated earlier. With a bit of extra math I got it to work fine. My next problem is this. I have my collision system in place but it isnt 100% accurate. I was wondering if there is any way to improve this.
if Tiles((PlayerX/32),(PlayerY/32))<>1then 'Movement functions (This adds + or - 5 to the x or y depending on which key was pressed) else 'anti-movement functions (This does the opposite of the last mentioned movement function to reposition the player after moving over a 'solid' tile) end if
Thanks in advance for any help.
|
|
|
Post by shadow008 on Jan 7, 2010 8:06:47 GMT -5
try something like this instead: *insert movement code here *suggestion to use sprsetvel(playerVelX,playerVelY) for movement for this to work properly... if *your not already using it *COLLISION DETECTION if Tiles((playerX/32)+5,(PlayerY/32)) <> 1 then playerVelX = 0 endif that would be only one of the 4 directions (moving right) but just put the rest of the directions collision detection in succesion then after all collision detection put sprsetvel(playerVelX,playerVelY) - to update movement that has worked for me e.g.
|
|
|
Post by crazynate on Jan 7, 2010 9:44:55 GMT -5
no, Tiles((playerX/32)+5,(PlayerY/32)) will detect collision for a tile 5 tiles away. Try Tiles((playerX+5)/32,(PlayerY/32))
When i was trying to make a side-scroller, ive noticed that if the movement and sprite sizes arent proportional, that it's easy to get stuck in a wall or floor. ie - if the sprites are 30*30 and movement is 5 will work better than if the sprites are 32*32 and movement is 5 correct me if im wrong, and did i explain that well enough?
|
|
|
Post by shadow008 on Jan 7, 2010 12:21:39 GMT -5
oh yeah whoops try this instead: Tiles((playerX +5)/32,(playerY)/32)
|
|
|
Post by crazynate on Jan 7, 2010 12:36:41 GMT -5
Try Tiles((playerX+5)/32,(PlayerY/32)) try this instead: Tiles((playerX +5)/32,(playerY)/32) Just out of curiosity, shadow is your middle name "repetitive"?
|
|
|
Post by Darkjester on Jan 7, 2010 14:23:35 GMT -5
|
|
|
Post by shadow008 on Jan 7, 2010 14:34:23 GMT -5
Try Tiles((playerX+5)/32,(PlayerY/32)) try this instead: Tiles((playerX +5)/32,(playerY)/32) Just out of curiosity, shadow is your middle name "repetitive"? LOL!!!! *facepalm* no, actually i think its "retarded" i guess i didnt actually fully read what you posted...
|
|
|
Post by crazynate on Jan 7, 2010 15:30:11 GMT -5
So is the collision working better now, alovon?
|
|
|
Post by alovon on Jan 7, 2010 23:48:44 GMT -5
Yes the collisions are working much better. Thanks for all the suggestions. I have to play with thenumbers a bit untill the math is just right but it seems like it is working now. Thank you all.
|
|
|
Post by alovon on Jan 8, 2010 0:02:22 GMT -5
Actually I have another small question. This may only be able to be answered once I post the code (Which will be soon) for you guys to look at, but when I move the sprite around it stops a whole half of a tile early. I attempted to fix this by changing the +1 x or y to .5 but this only yeilded in the player getting stuck. Expect to see the code soon. The bitmaps are still in the works (especialy the player) but please let me know if you think they are game worthy as well.
|
|
|
Post by crazynate on Jan 8, 2010 0:12:21 GMT -5
i don't know either, i have the same problem with my collision. if you need me to, i can help with sprites
|
|