2D collisions for adventure games

Blitz3D Forums/Blitz3D Programming/2D collisions for adventure games

Hello.

Sorry, I spent time with a large breasted beauty last night so didn't have time to do this, so here's a rough outline thrown together at lunchtime. Any comments welcome:
' Set up Waypoints
- For each screen, carrying out the following process will give us the ability to move on predefined paths and search for the quickest (step-wise as opposed to distance-wise) path from one waypoint to another.  I’d suggest that a screen designer might be useful here :o)
- Define Waypoints, ie, junctions on paths
- Define Waypoint links (ie, which waypoints link to which others).  This will provide vectors/step size between the points, eg:
    A->B = (0.5, -0.25)
    B->C = (0.1, -5)
    Automatically generate reverse links as well here, eg, B->A = (-0.5, 0.25).
- Define Available paths through points, eg, 
    A->B->E->F
    A->M
    B->N->O->K
-Automatically generate reverse paths as well here.
    The paths can be stored as strings so you’d have ABEF and AM and BNOK, and in reverse FEBA, AM and KONB.
' Set up Collision Points
- For each screen you’ll want to have objects to move in front of / behind.  The waypoint system allows you to move around the screen, the collision points will be where the player interacts with objects.
- Each collision object will have a front and back position, and a y-pos switch position.  As the player moves along the path, if they collide with this point, the player y-pos and the switch position are compared and the players z-position determined through this.

'Main Loop
Repeat
cls
DoPlayer()

'Draw Stuff on screen
DrawBackgroundImage()

For each object
	If object.z > player.z then 
DrawObject()
	Else
		If Player is not drawn
			DrawPlayer()
		Else
			DrawObject()
		End if
	End if
Next

DrawHUD()
DrawCursor()

Flip
Forever

Function DoPlayer()
If mouseclicked()
    Get closest waypoint to cursor position
    Search through waypoint pathlist for quickest path from current position to selected position
    Set Moving flag to true
End if

If Moving = true
    follow path, via linked waypoints, until destination waypoint reached or cursor position reached
    For each CollisionPoint
      If playercollides
         If player.oldy > player.newy then
           player.z = collisionpoint.frontposition
         else
           player.z = collisionpoint.backposition
         end if
         break;
      end if
next
If destination reached set moving = false
End if
End function

Or something like that anyway :o)

Goodbye.