Have improved collision detection slighly, but sprite still slides off box, I assume I have to set speed to 0, but can`t seem to figure out where to put it, in my code.
Also, not too sure about how to alter the bounding box on the sprite, to allow my character to collide properly, is it the OFFSET SPRITE command ?
An explanation or example or both
would be good !
Thanks D Ogre for your last post.
hide mouse
sync rate 60
y=400
jumping = 0
jump#=-8
direction = 2
speed = 1
create animated sprite 1,"man.png",4,4,1
box 240,430,280,450
get image 2,240,430,270,450,1
do
cls rgb(128,128,255)
box 0,450,640,480,rgb(255,0,0),rgb(100,100,100),rgb(150,150,0),rgb(255,0,0)
if spacekey() = 1
jumping = 1
endif
if jumping = 1
if jumping = 1 and leftkey() = 1 then x=x-2
if jumping = 1 and rightkey() = 1 then x=x+2
y= y + jump#
jump# = jump# + 0.5
if y > 400
y = 400
jumping = 0
jump# = -8
endif
endif
if leftkey()=1
if direction = 2 then mirror sprite 1
direction = 1
sprite 1,sprite x(1),sprite y(1),1
play sprite 1,1,16,200
x=x-speed
endif
if rightkey()=1
If direction = 1 then mirror sprite 1
direction = 2
sprite 1,sprite x(1),sprite y(1),1
play sprite 1,1,16,200
x=x+speed
endif
if x > 590 then x=590
if x < -15 then x=-15
set sprite 1,1,0
sprite 1,x,y,1
sprite 2,300,430,2
`----------------------------------------------------------------
`My attempt at object collision, pretty bad, if you land on box,
`and then try and move off you have to press spacekey to reset
`y pos
`----------------------------------------------------------------
if sprite exist(2)
collision=sprite collision(1,2)
if sprite collision(1,2) and direction = 2
x=x-speed
else
if sprite collision(1,2) and direction = 1
x=x+speed
endif
endif
if sprite collision(1,2) and jumping = 1
jumping=0
y=370
else
y=y
if jumping=0 and collision=0
y=400
endif
endif
endif
center text 320,yy,"Sprite x-pos : "+str$(x)
center text 320,yy+20,"Sprite y-pos : "+str$(y)
print "Collision : ",collision
loop
end