rem AGK Application
setsyncrate(60,1)
setbordercolor(128,128,128)
SetDisplayAspect( 4.0/3.0 )
#constant PHYS_STATIC = 1
#constant PHYS_DYNAMIC = 2
#constant PHYS_KINEMATIC = 3
#constant PSQUARE = 2
#constant PCIRCLE = 1
global ball
global bat
MainLoop()
end
function MainLoop()
state=0
Init()
do
//Abprall
if GetPhysicsCollision( ball, bat ) //must me in correct order else no collision^^
dx#=getspritexbyoffset(ball)-getspritexbyoffset(bat)
print(dx#)
vx#=dx#/2.0
vy#=0
SetSpritePhysicsImpulse( ball, getspritexbyoffset(ball),getspriteybyoffset(ball), vx#, vy# )
endif
//print(getrawlastkey())
//Links / Rechts bewegen
if GetRawKeyState(37)
if x#>-4 then x#=x#-0.1
//SetSpritePhysicsImpulse( bat, getspritexbyoffset(bat),getspriteybyoffset(bat), x#,0 )
setspritepositionbyoffset(bat,getspritexbyoffset(bat)+x#,getspriteybyoffset(bat))
elseif GetRawKeyState(39)
if x#< 4 then x#=x#+0.1
//SetSpritePhysicsImpulse( bat, getspritexbyoffset(bat),getspriteybyoffset(bat), x#,0 )
setspritepositionbyoffset(bat,getspritexbyoffset(bat)+x#,getspriteybyoffset(bat))
else
x#=x# / 1.1
endif
px#=getspritexbyoffset(bat)
if px#<getspritewidth(bat)/2
px#=getspritewidth(bat)/2
x#=0
endif
if px#>100-getspritewidth(bat)/2
px#=100-getspritewidth(bat)/2
x#=0
endif
setspritepositionbyoffset(bat,px#,90) //getspriteybyoffset(bat))
//Mit bewegen
if state=0
setspritephysicsvelocity(ball,0,0)
setspritephysicsangularvelocity(ball,0)
setspritepositionbyoffset(ball,getspritexbyoffset(bat),getspriteybyoffset(bat)-getspriteheight(bat)/2-getspriteheight(ball)/2)
if GetRawKeyState(32) //Space
state=1
endif
endif
//Abschießen
if state=1
setspritephysicsvelocity(ball,getspritephysicsvelocityx(bat),0)
SetSpritePhysicsImpulse( ball, getspritexbyoffset(ball),getspriteybyoffset(ball), x#,-10 )
state=2
endif
//Ball runter ziehen wie Gravitation
SetSpritePhysicsforce( ball, getspritexbyoffset(ball),getspriteybyoffset(ball), 0,1 )
//Neu Start
if getspriteybyoffset(ball)>100+getspriteheight(ball)
state=0
setspritephysicsvelocity(ball,0,0)
setspritephysicsangularvelocity(ball,0)
setspritephysicsvelocity(bat,0,0)
x#=0
endif
Sync()
loop
endfunction
function Init()
//SetPhysicsDebugOn()
SetPhysicsWallBottom(0)
SetPhysicsWallLeft(1)
SetPhysicsWallRight(1)
SetPhysicsWallTop(1)
setphysicsgravity(0,0)
//iball=loadimage("ball.png")
ball = createsprite(iball)
SetSpritePhysicsOn ( ball, PHYS_DYNAMIC )
setspritesize(ball,2,-1)
SetSpritePhysicsFriction ( ball, 0.5 )
setspriteshape(ball,PCIRCLE)
SetSpritePhysicsAngularDamping(ball, 0.5)
SetSpritePhysicsRestitution( ball, 1.0 )
SetSpritePhysicsMass ( ball, 0.1 )
setSpritePhysicsCanRotate (ball,1)
setspritepositionbyoffset(ball,50,80)
SetSpritePhysicsIsBullet(ball,1)
//ibat=loadimage("bat.png")
bat = createsprite(iBat)
SetSpritePhysicsOn ( bat, PHYS_KINEMATIC) // PHYS_DYNAMIC) //PHYS_KINEMATIC )
setspritesize(bat,10,-1)
setspriteshape(bat,PSQUARE)
SetSpritePhysicsRestitution( bat, 0.0 )
SetSpritePhysicsMass ( bat, 1 )
setSpritePhysicsCanRotate (bat,0)
setspritepositionbyoffset(bat,50,90)
endfunction