Hallo wie der name schon sagt geht es um Collisonen von Kugeln. Ich möchte für ein spiel das eine Kugel, die man frei bewegen kann einen ball anstößt und das dieser dann physikalisch richtig abprallt. Jedoch bekomme ich die rechung dafür nicht hin.
Spoiler anzeigen
#include <GuiConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>
HotKeySet("{ESC}", "_beenden")
Opt('MustDeclareVars', 1)
Opt('GuiOnEventMode', 1)
Opt ('MouseCoordMode', 0 )
Global $hGUI, $hWnd, $hGraphic, $Bitmap, $Buffer, $hPen, $msg
Global $width = 640
Global $height = 400
Global $titel = "Titel"
Global $version = " v1"
Global $rotate, $x = 288, $y = 168, $schwung, $auto_radius = 32
Global $ball_x = 400, $ball_y = 250, $ball_radius = 16, $ball_rotate, $ball_schwung
Global $pi = 3.14159265358979
Global $f,$w,$wi
;Global $dll = DllOpen("user32.dll")
$hGUI = GUICreate($Titel & $version, $width, $height,-1,-1)
$hWnd = WinGetHandle($Titel & $version)
GUISetState(@SW_SHOW)
;GUISetCursor(16)invisible
_GDIPlus_Startup ()
$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hWnd)
$Bitmap = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphic)
$Buffer = _GDIPlus_ImageGetGraphicsContext($Bitmap)
_GDIPlus_GraphicsSetSmoothingMode($Buffer, 4)
_GDIPlus_GraphicsClear($Buffer,0xFF000000)
$hPen = _GDIPlus_PenCreate (0xFF00FF00,4)
While 1
If $Rotate > 360 Then
$Rotate -=360
ElseIf $Rotate < 0 Then
$Rotate +=360
EndIf
If _IsPressed ("27") Then
$Rotate -= 5
ElseIf _IsPressed ("25") Then
$Rotate += 5
EndIf
If _IsPressed ("26") Then
$schwung -= 0.1
ElseIf _IsPressed ("28") Then
$schwung += 0.1
EndIf
If $schwung >= 10 Then $schwung = 10
If $schwung <= -10 Then $schwung = -10
If $schwung < 0 Then $schwung += 0.01
If $schwung > 0 Then $schwung -= 0.01
;##### Collision Seiten ################################################
If $x <= 0 Then
$rotate = -$rotate
$x += 1
EndIf
If $x >= 576 Then
$rotate = -$rotate
$x -= 1
EndIf
If $y <= 0 Then
$rotate += 90
$rotate = -$rotate
$rotate -= 90
$y += 1
EndIf
If $y >= 336 Then
$rotate += 90
$rotate = -$rotate
$rotate -= 90
$y -= 1
EndIf
;##### /Collision Seiten ###############################################
;#### Collision zwischen Auto und Kugel ###############################
If (sqrt(($x-$ball_x)*($x-$ball_x)+($y-$ball_y)*($y-$ball_y))< 32) Then
_collision ()
EndIf
;#### /Collision zwischen Auto und Kugel ##############################
$x += Sin (($rotate)*$Pi/180)*$schwung ;errechnet x
$y += Cos (($rotate)*$Pi/180)*$schwung ;errechnet y
$ball_x += Sin (($ball_rotate)*$Pi/180)*$ball_schwung ;errechnet x
$ball_y += Cos (($ball_rotate)*$Pi/180)*$ball_schwung ;errechnet y
$ball_schwung -= 0.01
If $ball_schwung < 0 Then $ball_schwung = 0
_zeichnen ()
Sleep(10)
WEnd
Func _collision ()
$ball_schwung = 1
Local $x1 ,$y1, $var1, $var2, $radToDeg = 180 / $pi
$x1 = $ball_x - $x
$y1 = $ball_y - $y
$var1 = $x1 / 64
$var2 = ACos ($var1) * $radToDeg
$ball_rotate = $var2
ToolTip ($x1 & " ; " & $y1 & " ; " & $var1 & " ; " & $var2)
EndFunc
Func _zeichnen ()
_GDIPlus_GraphicsClear($Buffer,0xFFFFFFFF)
_GDIPlus_GraphicsDrawPie ($Buffer,$x,$y,64,64,0 - $Rotate - 90,360,$hPen)
_GDIPlus_GraphicsDrawPie ($Buffer,$ball_x,$ball_y,32,32,0 - $ball_Rotate - 90,360,$hPen)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $Bitmap,0,0, $width, $height)
EndFunc
Func _beenden ()
_GDIPlus_GraphicsDispose ($hGraphic)
_GDIPlus_BitmapDispose($Bitmap)
_GDIPlus_GraphicsDispose($Buffer)
_GDIPlus_PenDispose ($hPen)
_GDIPlus_Shutdown ()
; DllClose ($dll)
Exit
EndFunc