Hi
Do you if there is a way to get a sprite slide over other sprites like blocks or enemies (with physic or not) ?
Here is my test code :
w = 1024
h = 768
SetVirtualResolution(w,h)
setphysicsscale(0.25)
SetPhysicsGravity(0, 0)
SetPhysicsDebugOn()
global spr
n = CreateSprite(0)
SetSpritePhysicsOn(n,2)
SetSpritesize(n, 32, 32)
//SetSpritePhysicsFriction(n,1)
SetSpritePhysicsRestitution( n, 1 )
SetSpritePhysicsCanRotate(n,0)
spr = n
// blocks in red
For i=0 to 10
n= i+1
createsprite(n,0)
SetSpritePosition(n, random(50,w) , random(50,h) )
SetSpritesize(n, 64,32)
SetSpritePhysicsOn(n, 1)
//SetSpritePhysicsFriction(n,1)
SetSpriteColor(n, 255,100,100,255)
next
//enemies in blue
For i=0 to 3
n= i+12
createsprite(n,0)
SetSpritePosition(n, random(50,w) , random(50,h) )
SetSpritesize(n, 64,32)
SetSpritePhysicsOn(n, 2)
SetSpritePhysicsMass(n, 1000)
SetSpritePhysicsFriction(n,0)
SetSpritePhysicsDamping(n,10)
SetSpritePhysicsCanRotate(n,0)
SetSpriteColor(n, 100,100,255,255)
next
global x, y, mx, my as float
do
if GetRawKeyPressed(27) = 1
exit
endif
if GetPointerstate() = 1
mx = GetPointerX()
my = GetPointerY()
endif
MoveToward(mx, my, 3)
print(str(mx) +"/" +str(my))
print(str(x) +"/" +str(y))
sync( )
loop
function GetAngle(x1#, y1#, x2#, y2#)
result = ATanFull(x1# - x2#, y1# - y2#)
endfunction result
function MoveToward(ciblx as float, cibly as float, speed)
x = getspritex(spr)
y = getspritey(spr)
sx = 0
sy = 0
speed =100
if x <> ciblx or y <> cibly
//angle = GetAngle(ciblx, cibly, GetSpriteX(spr), GetSpriteY(spr))
//SetSpriteAngle(spr, angle)
if x <> ciblx
/*
x = x + cos(ATan2((cibly - y),(ciblx - x)))* speed
*/
if abs(x - ciblx) <= 1
x = ciblx
endif
if x > ciblX
sx = -speed
elseif x < ciblX
sx = speed
endif
endif
if y <> cibly
/*
y = y + sin(ATan2((cibly - y),(ciblx - x)))* speed
*/
if abs(y - cibly) <= 1
y = cibly
endif
if y > cibly
sy = -speed
elseif y < cibly
sy = speed
endif
endif
SetSpritePhysicsVelocity(spr, sx, sy)
else
SetSpritePhysicsVelocity(spr, 0, 0)
endif
endfunction
thanks a lot
AGK2 tier1 - http://www.dracaena-studio.com