Collision...

BlitzMax Forums/BlitzMax Beginners Area/Collision...

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

lets see if this helps... and please note this is not supposed to be runable code :D

playerx:int
playery:int
objectx:int
objecty:int
size1:int
size2:int

while
cls
gosub move
gosub checkcollision
gosub draw
flip
wend

function move:
if keydown(key_left) then playerx=playerx-1
etc...
etc...
etc...
endfunction


function checkcollision:
if playerx+size1 > objectx then playerx+size1 = objectx
if playerx < objectx+size2 then playerx = objectx+size2

if playery+size1 > objecty then playery+size1 = objecty
if playery < objecty+size2 then playery = objecty+size2
endfunction


function draw:
setcolor 255,0,0
drawrect playerx,playery,size1,size1
setcolor 0,0,255
drawrect objectx,objecty,size2,size2
endfunction



turn that code into usable code and run it. You should be able to run into the object and be repelled.