jajaja.
ich wollte euch ja nur testen ob ihr den fehler schön findet!
GDI+ Kometenschweif
-
-
jajaja.
ich wollte euch ja nur testen ob ihr den fehler schön findet!Ne, den find ich hässlich!
-
Und zu den Berechnungen, du musst im Grunde nur das, was du bei _IsPressed() stehen hast, ohne das _IsPressed() schreiben^^
If 25 Then $iX -= $bewegung
[/autoit]
If 26 Then $iY -= $bewegung
If 27 Then $iX += $bewegung
If 28 Then $iY += $bewegungPassiert recht wenig so
-
Zitat
Passiert recht wenig so
Wieso nur?
Jede Bedingung ist wahr und der Ball wird in alle 4 Richtungen gleichteitig bewegt. Wie effektiv... -
clezZ
das mit den richtungen musste mir dann nochmal erklären! -
Zitat von »clezZ«
Und zu den Berechnungen, du musst im Grunde nur das, was du bei _IsPressed() stehen hast, ohne das _IsPressed() schreiben^^AutoIt-QuellcodeCode kopieren
1
2
3
4If 25 Then $iX -= $bewegung
If 26 Then $iY -= $bewegung
If 27 Then $iX += $bewegung
If 28 Then $iY += $bewegungPassiert recht wenig so
Im Grunde!!!!!
Des ist aber nicht dein ernst, oder?
-
Sorry, habs falsch rübergebracht...
Sollte nen Scherz werden -
doch!
ich blicke das einfach nicht
ich bin einfach schlecht in berechnungen/formeln/mathe
meine anfänge taten nichts (bewegten nur in eine richtung egal was ich tat -
Sorry, habs falsch rübergebracht...
Sollte nen Scherz werdenDas hoffe ich jetzt mal!!!
-
Zitat
doch!
ich blicke das einfach nicht
ich bin einfach schlecht in berechnungen/formeln/mathe
meine anfänge taten nichts (bewegten nur in eine richtung egal was ich tat
Im Forum gab es schon 2 Umsetzungen von Pong mit GDI+ (eine ist von mir) , guck die mal an. Es ist wirklich viel einfacher als du dir vorstellst ;). -
Alizame: Ein Tipp: Schau mal in die Signatur von name22, vielleicht ist da was hilfreiches dabei
-
names pong = nur variablen und 0 sinn für mich
habe es mir bevor ich angefangen habe das angeschaut -
Ich bin auch nicht sehr bewandert in GDI+ (sprich: so gut wie null Erfahrung )
Würd mich also auch mal interessieren, wie das funzt... -
Zitat
names pong = nur variablen und 0 sinn für mich
Und dabei war das mein wohl einfachstes GDI+ Script (Beispiele ausgeschlossen)...
Ignorier doch mal alle Variablen die nichts mit dem Ball zu tun haben.Also...
Ich habe nicht nur die Position des Balls sondern auch die Entfernung in Pixeln um die er bei jeder Frame bewegt wird in Variablen gespeichert. D.h. Ich kann einfach das Vorzeichen der Variablen für die "Geschwindigkeit" ändern (Multiplikation mit -1) um den Ball in die exakt gegenüberliegende Richtung fliegen zu lassen.
Tut mir leid ich bin leider schlecht im erklären... -
ich habe es hingekriegt!
ball prallt ab!nurnoch richtungen ordentlich bestimmen und siehe da , es geht! -
name22: So, hab dein Pong mal etwas "benutzerfreundlich" gemacht
Spoiler anzeigen
[autoit]#include <GDIPlus.au3>
[/autoit]
#include <GUIConstants.au3>
#include <Misc.au3>Global $GUIWidth = 600 ;Breite GUI
Global $GUIHeight = 400 ;Höhe GUI
Global $BallWidth = 10 ;Breite Punkt
Global $BallHeight = 10 ;Höhe Punkt
Global $PadHeight1 = 60 ;Höhe des linken Pads
Global $PadHeight2 = 60 ;Höhe des rechten Pads
Global $PadWidth1 = 10 ;Breite des linken Pads
Global $PadWidth2 = 10 ;Breite des rechten Pads
Global $GUIColorBG = 0xFF000000 ;Farbe GUI
Global $BallColor = 0xFFFFFFFF ;Farbe Punkt
Global $Pad1Color = 0xFFFFFFFF ;Farbe des linken Pads
Global $Pad2Color = 0xFFFFFFFF ;Farbe des rechten Pads
Global $LineColor = 0xFFFFFFFF ;Farbe der MittellinieGlobal $Score1 = 0
Global $Score2 = 0
Global $iXBall = $GUIWidth / 2 - $BallWidth / 2
Global $iYBall = Random($BallHeight + 10, $GUIHeight - $BallHeight - 10)
Global $iXPad1 = 10
Global $iYPad1 = $GUIHeight / 2 - $PadHeight1 / 2
Global $iXPad2 = $GUIWidth - $PadWidth2 - 10
Global $iYPad2 = $GUIHeight / 2 - $PadHeight2 / 2
Global $StepYBallIf Random(1, 2, 1) = 1 Then
Global $StepXBall = 5
Else
Global $StepXBall = -5
EndIf
Do
$StepYBall = Random(-5, 5, 1)
Until Not $StepYBall = 0$hWnd = GUICreate("GDI+ Pong by Name22", $GUIWidth, $GUIHeight)
GUISetState(@SW_SHOW)_GDIPlus_Startup()
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hWnd)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics($GUIWidth, $GUIHeight, $hGraphic)
Global $Buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
_GDIPlus_GraphicsSetSmoothingMode($Buffer, 2)
_GDIPlus_GraphicsClear($Buffer, $GUIColorBG)
Global $hBrush1 = _GDIPlus_BrushCreateSolid($BallColor)
Global $hBrush2 = _GDIPlus_BrushCreateSolid($Pad1Color)
Global $hBrush3 = _GDIPlus_BrushCreateSolid($Pad2Color)
Global $hBrush4 = _GDIPlus_BrushCreateSolid($LineColor)AdlibRegister("_Draw", 20)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
AdlibUnRegister()
_GDIPlus_BrushDispose($hBrush1)
_GDIPlus_BrushDispose($hBrush2)
_GDIPlus_BrushDispose($hBrush3)
_GDIPlus_BrushDispose($hBrush4)
_GDIPlus_GraphicsDispose($Buffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_Shutdown()
Exit
EndSwitch
If Not WinActive($hWnd) = 0 Then
If _IsPressed("57") And $iYPad1 >= 0 Then $iYPad1 -= 2
If _IsPressed("53") And $iYPad1 <= $GUIHeight - $PadHeight1 Then $iYPad1 += 2
If _IsPressed("26") And $iYPad2 >= 0 Then $iYPad2 -= 2
If _IsPressed("28") And $iYPad2 <= $GUIHeight - $PadHeight2 Then $iYPad2 += 2
EndIf
WEndFunc _Draw()
_GDIPlus_GraphicsClear($Buffer, $GUIColorBG)
_GDIPlus_GraphicsFillRect($Buffer, $iXPad1, $iYPad1, $PadWidth1, $PadHeight1, $hBrush2)
_GDIPlus_GraphicsFillRect($Buffer, $iXPad2, $iYPad2, $PadWidth2, $PadHeight2, $hBrush3)
For $i = 0 To Round($GUIHeight / 30) - 1
_GDIPlus_GraphicsFillRect($Buffer, $GUIWidth / 2 - 15, $i * 60, 10, 30, $hBrush4)
Next
_GDIPlus_GraphicsFillEllipse($Buffer, $iXBall, $iYBall, $BallWidth, $BallHeight, $hBrush1)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hBitmap, 0, 0, $GUIWidth, $GUIHeight)
$iXBall += $StepXBall
$iYBall += $StepYBall
Switch $iXBall
Case $iXPad1 + $PadWidth1 - 5 To $iXPad1 + $PadWidth1
If $iYBall >= $iYPad1 - $BallHeight / 2 And $iYBall <= $iYPad1 + $PadHeight1 + $BallHeight / 2 Then $StepXBall = $StepXBall * - 1
[/autoit]
Case $iXPad2 - $PadWidth2 To $iXPad2 - $PadWidth2 + 5
If $iYBall >= $iYPad2 - $BallHeight / 2 And $iYBall <= $iYPad2 + $PadHeight2 + $BallHeight / 2 Then $StepXBall = $StepXBall * - 1
EndSwitch
If $iYBall >= $GUIHeight - $BallHeight Then $StepYBall = $StepYBall * - 1
If $iYBall <= 0 Then $StepYBall = $StepYBall * - 1
If $iXBall <= 0 Then
$Score2 += 1
WinSetTitle($hWnd, "", "Player 1: " & $Score1 & " | Player 2: " & $Score2)
Sleep(1000)
$iXBall = $GUIWidth / 2 - $BallWidth / 2
$iYBall = Random($BallHeight + 10, $GUIHeight - $BallHeight - 10)
$iYPad1 = $GUIHeight / 2 - $PadHeight1 / 2
$iYPad2 = $GUIHeight / 2 - $PadHeight2 / 2
If Random(1, 2, 1) = 1 Then
$StepXBall = 5
Else
$StepXBall = -5
EndIf
Do
$StepYBall = Random(-5, 5, 1)
Until Not $StepYBall = 0
EndIf
If $iXBall >= $GUIWidth - $BallWidth Then
$Score1 += 1
WinSetTitle($hWnd, "", "Player 1: " & $Score1 & " | Player 2: " & $Score2)
Sleep(1000)
$iXBall = $GUIWidth / 2 - $BallWidth / 2
$iYBall = Random($BallHeight + 10, $GUIHeight - $BallHeight - 10)
$iYPad1 = $GUIHeight / 2 - $PadHeight1 / 2
$iYPad2 = $GUIHeight / 2 - $PadHeight2 / 2
If Random(1, 2, 1) = 1 Then
$StepXBall = 5
Else
$StepXBall = -5
EndIf
Do
$StepYBall = Random(-5, 5, 1)
Until Not $StepYBall = 0
EndIf
EndFunc ;==>_Draw -
so versteht man das besser!DANKE!
-
So, ich mache jetzt mal eine neue Version meines Pongs.
Mit Backbuffer etc. ^^. -
hmmm..
es macht nachm 3. mal abprallen nen fehler, kreige den aber irgendwie nicht weg!Spoiler anzeigen
[autoit]#cs ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit]AutoIt Version: 3.3.5.6 (beta)
[/autoit] [autoit][/autoit] [autoit]
Author: AlizameScript Function:
[/autoit] [autoit][/autoit] [autoit]
It make a kometenschweif#ce ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit]; Script Start - Add your code below here
[/autoit] [autoit][/autoit] [autoit]
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <Misc.au3>;###
[/autoit] [autoit][/autoit] [autoit]
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Kometenschweif by Alizame", 800, 600)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
;###$farbewei = 0xFFFFFFFF
[/autoit] [autoit][/autoit] [autoit]
$farbeschwar = 0xFFFFFFFF
$Ball = 40
$iX = 400
$iY = 300
$iXold = 400
$iYold = 300
$bewegung = 5
$richtung = 1_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]
$hGraphics = _GDIPlus_GraphicsCreateFromHWND($Form1)
$hBitmap = _GDIPlus_BitmapCreateFromGraphics(800,600,$hGraphics)
$Buffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
$bWei = _GDIPlus_BrushCreateSolid($farbewei)
$bSch = _GDIPlus_BrushCreateSolid($farbeschwar)
$smooth = _GDIPlus_GraphicsSetSmoothingMode($hGraphics,2)
_ReDraw ()While 1
[/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($Buffer)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_BrushDispose($bWei)
_GDIPlus_BrushDispose($bSch)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
Exit
EndSwitch
;~ If _IsPressed("25") Then $iX -= $bewegung
If $richtung = 1 Then
$iX -= $bewegung
$iY -= $bewegung
ElseIf $richtung = 2 Then
$iX -= $bewegung
$iY += $bewegung
ElseIf $richtung = 3 Then
$iX += $bewegung
$iY -= $bewegung
ElseIf $richtung = 4 Then
$iX += $bewegung
$iY += $bewegung
EndIf
;~ If _IsPressed("26") Then $iY -= $bewegung
;~ If _IsPressed("27") Then $iX += $bewegung
;~ If _IsPressed("28") Then $iY += $bewegung
If $iX <> $iXold Or $iY <> $iYold Then _ReDraw ()
WEndFunc _ReDraw ()
[/autoit] [autoit][/autoit] [autoit]
_PosCorrect ()
_GDIPlus_GraphicsClear($Buffer,$bSch)
_GDIPlus_GraphicsFillEllipse($Buffer,$iX,$iY,$Ball,$Ball,$bWei)
_GDIPlus_GraphicsDrawImageRect($hGraphics,$hBitmap,0,0,800,600)
$iXold = $iX
$iYold = $iY
EndFuncFunc _PosCorrect()
[/autoit]
If $iX < 0 Then $richtung = 4
If $iY < 0 Then $richtung = 2
If $iX > 760 Then $richtung = 1
If $iY > 560 Then $richtung = 3
ToolTip("x="&$iX&@CRLF&"y="&$iY&@CRLF&$richtung,0,0)
EndFunc -
Ich sag's nur ungern, aber das kann man einfacher, effektiver und kürzer lösen ;).
-