also wie er sich nach dem anspielen und auslaufen verhält.
vielleicht kann mir wer dazu eine formel bereitstellen.
Bin leider kein Mathe ass

Grüße.
Code: Alles auswählen
ball\speed - 0.1
dt = time - ball\starttime
v = ball\speed * dt
x = v * dt
ball\posx + (gCos(ball\rotation) * x)
ball\posy + (gSin(ball\rotation) * x)
Code: Alles auswählen
InitSprite()
InitMouse()
InitKeyboard()
If OpenWindow(0, 0, 0, 800, 600, "Fussball", #PB_Window_ScreenCentered) = 0: End: EndIf
If OpenWindowedScreen(WindowID(0), 0, 0, 800, 600) = 0: End: EndIf
SetFrameRate(60)
Procedure.f gSin(Ang.f)
ProcedureReturn Sin(Radian(Ang))
EndProcedure
Procedure.f gCos(Ang.f)
ProcedureReturn Cos(Radian(Ang))
EndProcedure
Procedure.f dist(X1.f, Y1.f, X2.f, Y2.f)
dX.f = X1 - X2
dY.f = Y1 - Y2
ProcedureReturn Sqr((dX * dX) + (dZ * dZ))
EndProcedure
Procedure.f gATan(a.f, b.f)
ang.f = (ATan(a / b) * 57.2957795)
If b < 0
ang + 180
EndIf
ang + 90
If ang < 0 : ang + 360 : EndIf
If ang > 359 : ang - 360 : EndIf
If (ang < -359) Or (ang > 359): ang = 0: EndIf
ProcedureReturn ang
EndProcedure
Structure strBall
xpos.f
ypos.f
dir.f
speed.f
jump.f
up.f
EndStructure
ball.strBall
ball\xpos = 450
ball\ypos = 350
ball\dir = 45
ball\speed = 0
ball\jump = 0
Repeat
e = WindowEvent()
ExamineKeyboard()
ExamineMouse()
mx = MouseX()
my = MouseY()
If (KeyboardReleased(#PB_Key_Space))
d.f = dist(mx, my, ball\xpos, ball\ypos)
If (d < 30 And d > 3)
c = (ball\xpos - mx)
b = (ball\ypos - my)
a = gATan(b, c)
ball\dir = a
If (d < 5)
d = 5
EndIf
ball\speed = 60 / d
ball\up = 40 / d
EndIf
EndIf
ball\xpos + gSin(ball\dir) * ball\speed
ball\ypos - gCos(ball\dir) * ball\speed
ball\speed * 0.99
ball\jump + ball\up
ball\up - 0.1
If (ball\jump <= 0)
ball\jump = 0
ball\up * -0.5
EndIf
If (ball\xpos < 7)
ball\xpos = 8
ball\speed * 0.75
ball\dir = 180 - (ball\dir - 180)
EndIf
If (ball\xpos > 792)
ball\xpos = 791
ball\speed * 0.75
ball\dir = 180 + (180 - ball\dir)
EndIf
If (ball\ypos < 7)
ball\ypos = 8
ball\speed * 0.75
ball\dir = 270 - (ball\dir - 270)
EndIf
If (ball\ypos > 592)
ball\ypos = 591
ball\speed * 0.75
ball\dir = 270 + (270 - ball\dir)
EndIf
If (ball\dir > 360)
ball\dir - 360
EndIf
If (ball\dir < 0)
ball\dir + 360
EndIf
ClearScreen(RGB(50, 150, 30))
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Outlined)
FrontColor(RGB(255, 255, 255))
Circle(400, 300, 100)
Line(400, 0, 1, 600)
Box(-1, 150, 100, 300)
Box(701, 150, 100, 300)
DrawingMode(#PB_2DDrawing_Default)
FrontColor(RGB(35, 100, 20))
Circle(ball\xpos, ball\ypos, 7)
FrontColor(RGB(255, 255, 255))
Circle(ball\xpos, ball\ypos - ball\jump, 10)
FrontColor(RGB(255, 0, 0))
Box(mx-10, my-10, 20, 20)
FrontColor(RGB(255, 255, 255))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10, 10, "[SPACE] = Schuss")
DrawText(10, 25, "[ESC] = Ende")
StopDrawing()
FlipBuffers()
Until KeyboardReleased(#PB_Key_Escape)
Code: Alles auswählen
If SpriteCollision(#sprite_ball,ball\posx,ball\posy,\sprite,\posx,\posy)
If ball\rotation = 0 Or ball\rotation = 90
ball\rotation = 180
ElseIf ball\rotation = 180
ball\rotation = 90
EndIf
ball\speed = 0.1
EndIf