rem
rem AGK Application 108 19
rem MR
//Jump over the Box Example
SetDisplayAspect( 4.0/3.0 )
setvirtualresolution(10,10) //10x10 Meter
setphysicsscale(1) //belongs resolution! default 1 unit = 1 meter
SetPhysicsGravity(0 , 50)
setphysicsdebugon()
#constant groupground 1
#constant groupobject 2
//Player
spr = CreateSprite(0)
SetSpriteSize (spr,0.5,2)
SetSpritePosition(spr,2.5,5)
SetSpritePhysicsOn(spr,2)
SetSpriteDepth(spr,0)
SetSpritePhysicsCanRotate (spr,0)
SetSpritePhysicsMass (spr,60)
setspritephysicsisbullet(spr,1)
SetSpritePhysicsFriction(spr,0.1)
SetSpritePhysicsRestitution(spr,0.25)
SetSpritePhysicsDamping(spr,0.25)
//Box
box = CreateSprite(0)
SetSpriteColor (box,233,75,80,255)
SetSpriteSize (box,1,-1)
SetSpritePosition(box,6,10-2)
SetSpritePhysicsON(box,2)
SetSpritePhysicsMass (box,2)
SetSpritePhysicsCanRotate(box,1)
SetSpritePhysicsFriction(box,0.75)
SetSpritePhysicsRestitution(box,0.25)
SetSpritePhysicsDamping(box,0.5)
SetSpriteGroup( box, groupobject )
//Ground
gr = CreateSprite(0)
SetSpriteColor (gr,128,128,128,255)
SetSpriteSize (gr,10,0.1)
SetSpritePosition(gr,0,10-0.05)
SetSpritePhysicsON(gr,1)
SetSpritePhysicsMass(gr,2)
SetSpritePhysicsCanRotate(gr,0)
SetSpritePhysicsFriction(gr,0.75)
SetSpritePhysicsRestitution(gr,0.5)
SetSpritePhysicsDamping(gr,0.5)
SetSpriteGroup( gr, groupground )
do
print("Use Cursor Left/Right, Space for Jump")
// Move Player to Left and Right
ix#=0.0
iy#=0.0
if GetRawKeyState(39) = 1
ix#=50.0
elseif GetRawKeyState(37) = 1
ix#=-50.0
endif
//Jump
if GetRawKeypressed(32) = 1
if AtGround(spr)=1 then iy#=-750.0
endif
if ix#<>0.0 or iy#<>0.0 then setspritephysicsimpulse(spr,getspritexbyoffset(spr),getspriteybyoffset(spr),ix#,iy#)
Sync()
loop
end
function AtGround(spr)
ret=0
c=GetSpriteFirstContact(spr)
do
if c=0 then exit
sprcontact=GetSpriteContactSpriteID2()
if sprcontact<>0
group=getspritegroup(sprcontact)
if group=groupobject or group=groupground
ret=1
exit
endif
endif
c=GetSpriteNextContact()
loop
endfunction ret
Help make AGK better by submitting an example for this command! (All examples are subject to approval)