i made a physic example with your code.
if you will have a bounce at the window borders you need also physic sprites.
you can disable the rotate by SetSpritePhysicsCanRotate ( iSpriteIndex, rotate )
see also GetSpriteHitTest ( iSpriteIndex, x, y ) for your input screen buttons.
//AGK 2.0.20
//MR
global upbutton = 10
global rightbutton = 20
global leftbutton = 30
global downbutton = 40
// set window properties
SetWindowTitle( "TopSecret" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
SetPhysicsDebugOn()
SetPhysicsScale(1.0 / 1024.0)
SetPhysicsGravity(0,0)
LoadTheSprites()
#constant f= 1000
do
forcex=0
forcey=0
If button(leftbutton) = 1
forcex = forcex -f
endif
If button(rightbutton) = 1
forcex = forcex +f
endif
If button(upbutton) = 1
forcey = forcey -f
endif
If button(downbutton) = 1
forcey = forcey +f
endif
print("force x = "+str(forcex)+" y = "+str(forcey))
SetSpritePhysicsForce(1,GetSpriteXByOffset(1),GetSpriteyByOffset(1),forcex,forcey)
Sync()
loop
function LoadTheSprites ()
LoadImage ( 8, "level.png" )
CreateSprite ( 8, 8)
//Player
loadimage (1,"bluebean.png")
createsprite (1,1)
SetSpritePhysicsOn( 1, 2 ) //2=dynamic
//input pad
LoadImage (10,"butt.png" )
CreateSprite ( upbutton, 10 )
setspriteposition (upbutton,100,280)
LoadImage (20,"butt.png" )
CreateSprite ( leftbutton, 20 )
setspriteposition (leftbutton,20,360)
LoadImage (30,"butt.png" )
CreateSprite ( rightbutton, 30 )
setspriteposition (rightbutton,180,360)
LoadImage (40,"butt.png" )
CreateSprite ( downbutton, 40 )
setspriteposition (downbutton,100,440)
//obstacle
loadimage (4, "easy.jpg")
createsprite (4,4)
SetSpritePhysicsOn( 4, 1 ) //1=static
SetSpritePosition ( 4, 650, 300 )
endfunction
Function button(sprite)
returnValue = 0 `reset value for check
If GetPointerX() > GetSpriteXByOffset( sprite ) - ( GetSpriteWidth( sprite ) / 2 )
If GetPointerX() < GetSpriteXByOffset( sprite ) + ( GetSpriteWidth( sprite ) / 2 )
If GetPointerY() > GetSpriteYByOffset( sprite ) - ( GetSpriteHeight( sprite ) / 2 )
If GetPointerY() < GetSpriteYByOffset( sprite ) + ( GetSpriteHeight( sprite ) / 2 )
If GetPointerState() = 1
returnValue = 1
Endif
Endif
Endif
Endif
Endif
EndFunction returnValue
AGK (Steam) V2.0.19 : Windows 10 Pro 64 Bit : AMD (16.3.2) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)