Flaky maze collision detection

BlitzPlus Forums/BlitzPlus Beginners Area/Flaky maze collision detection

OzBlitzManic(Posted 2005) [#1]
Hi again all.

Sorry about the huge post, but I think this is difficult to explain.
I have managed to get a little further in my endeavours, but yet again have hit a wall. I am now able to display my map, and my tank sprite (32x32 image) moves around it. I have (attempted) placed in some collision detection code along the lines of:

I declared some temporary local variables to hold the players position then when the player presses a key, we use the following code to see if the player is moving to a position that = 1 which means a wall, so the player cant move there

If maze(Px/WallWidth,Py/WallHeight) = 1 Then
Px = Tempx
Py = Tempy
EndIf

Problem is, this works, Sometimes!. I'm thinking it has something to do with the precision required to move around, maybe someone can throw me a clue as to help with moving around the maze a little eaiser while we are at it.

Anyway, here is the code I have for now, its starting to get pretty big (well for me and coding anyway...). I will probably change things later to use TYPES, but for now I dont know enuff about TYPES, so I will look into that later.

not sure if this helps, but here are the 2 sprite images I created for this game: My Tanks Sprites

Basically I am after help with (but not neccesarily source hints, even putting me on the right track improving my algorithm or pseudocode will be useful :-)

1. Fixing the collision detection issues I have.
2. Making it easier to move around the maze, its too precise at the moment.
3. I want to have several game levels, and have added about 5, but havent a clue as to how to read these into my ReadMaze function since I dont know how to pass a variable to the Restore function. It tried Restore PlayerLevel, but it spat the dummy coz the levels are called Level1, Level2 etc.

Any tips would be appreciated.



CS_TBL(Posted 2005) [#2]
quite simple: you only checked the top-left coordinate right now, meaning that you can drive downwards into a wall until the TOP pixel hits it.. ofcourse you need to check all 4 corners of the tank! And if you eventually have smaller objects, then you might even have to check in-between coordinates as well..

Additionally: if you have a closed map you don't need to check the map-boundaries with:

If Px < MinXPos Then Px = MinXPos
If Px > MaxXPos Then Px = MaxXPos
If Py < MinYPos Then Py = MinYPos
If Py > MaxYPos Then Py = MaxYPos

Naturally, you need to set the initial tank-coordinate to 32,32 then..

This boundaries-checking caused the tank to react properly at the edges of the map and weird in the rest of the map. Things like that *can* cause fuss, therefor it's best to use the actual map as edge, and a real screen coordinate.. (what if your wallwidth/height changes? you need to setup values all again then!).