fb:porticula NoPaste
Hüpfender Ball
Uploader: | Jojo |
Datum/Zeit: | 06.12.2008 00:38:56 |
/'
steuerung:
pfeil oben: ball höher dopsen lassen
pfeil links/rechts: was wohl? :P
http://freebasic.net/forum/viewtopic.php?t=11762
'/
Screen 21,32,,1
Randomize Timer
Type player
x As Double
y As Double
sx As Double
sy As Double
ox As Double
oy As Double
End Type
Dim ball As player
Cls
Dim As Double tot,e,g
'Elasticity
e=1
'Gravity
g=0.1 '.01
ball.x = Rnd * 1260 + 10
ball.y = Rnd * 930 + 30
ball.sx = Rnd * 2 - 1
ball.sy = Rnd * 2 - 1
Do
ball.ox = ball.x
ball.oy = ball.y
ball.sy += g
ball.x += ball.sx
ball.y += ball.sy
'Limit the vectorspeed
If Abs(ball.sy) > 5 Then
ball.sy -= Sgn(ball.sy) * g
EndIf
'Check boundaries
If ball.x<10 Or ball.x>1270 Then ball.sx = -ball.sx
If ball.y<10 Then ball.sy = -ball.sy:ball.sy=ball.sy*e
If ball.y>1020 Then
ball.y=1020*2-ball.y
ball.sy=-ball.sy*e
If MultiKey(72) Then ball.sy -= 2
If Not MultiKey(75) And Not MultiKey(77) Then ball.sx /= 2
If MultiKey(75) then ball.sx -= 1
If MultiKey(77) then ball.sx += 1
EndIf
'In case they get stuck on the 'roof'
If ball.y<1 Then ball.y=20:ball.sy=Abs(ball.sy)
'Calc total vectorspeed
tot=tot+Abs(ball.sy)
'debug
Locate 1,1:Print "Total energy:";tot:tot=0
Circle(ball.x,ball.y),3,,,,,F
Sleep 1
Circle(ball.x,ball.y),3,0,,,,F
Loop Until MultiKey(1)