Hiho,
hab mal vor langer langer Zeit versucht Pong zu machen, hab gerade mal paar Bugs behoben damit ichs auchmal posten kann
nur Multiplayer bis jetzt:
Spoiler anzeigen
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
HotKeySet("{ESC}", "_ende")
[/autoit] [autoit][/autoit] [autoit]_GDIPlus_Startup()
[/autoit] [autoit][/autoit] [autoit]; Variablen
[/autoit] [autoit][/autoit] [autoit]Global $Difficult = 1.7
[/autoit] [autoit][/autoit] [autoit]Global $begin, $Firstball=True
Global $Speed = 1.0, $SpeedBalken = 10
Global $pointsleft = 0, $pointsright = 0
Global $BewegungSenkrecht = Random(5, 7, 1), $BewegungWaagerecht = Random(5, 7, 1)
Global $ballpos1 = @DesktopWidth / 2, $ballpos2 = @DesktopHeight / 2 - 50
Global $Strichpos1 = @DesktopHeight / 2 - 70, $Strichpos2 = @DesktopHeight / 2 + 70
Global $RStrichpos1 = @DesktopHeight / 2 - 70, $RStrichpos2 = @DesktopHeight / 2 + 70
Global $Titel = "Pong", $Rahmenbreite = 10
; GUI
Global $hGUI = GUICreate($Titel, @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, BitOR($WS_EX_TOPMOST, 0x0))
Global $hwnd = WinGetHandle($Titel)
GUISetBkColor(0x0)
$Willkommen = GUICtrlCreateLabel("Willkommen bei Pong made by Greek", @DesktopWidth / 4, @DesktopHeight / 2 - 150, 600, 200)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 40)
Global $Spielstand = GUICtrlCreateLabel("0:0", @DesktopWidth / 2, @DesktopHeight / 15, 200, 100)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 40)
GUICtrlSetState(-1, $GUI_HIDE)
$LevelL=GUICtrlCreateLabel ( "Los gehts!!", @DesktopWidth/2-100, @DesktopHeight/2-100, 300, 200 )
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 40)
GUICtrlSetState(-1, $GUI_HIDE)
Local $accel[4][2] = [["w"],["s"],["{UP}"],["{DOWN}"]]
GUISetAccelerators($accel)
GUISetState(@SW_SHOW)
[/autoit] [autoit][/autoit] [autoit]Do
Sleep(10)
Until _IsPressed("0D") Or _IsPressed("20")
GUICtrlSetState($Willkommen, $GUI_HIDE)
GUICtrlSetState($LevelL, $GUI_SHOW)
Sleep ( 1500 )
GUICtrlSetState($LevelL, $GUI_HIDE)
GUICtrlSetState($Spielstand, $GUI_SHOW)
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwnd)
Global $hPenRahmen = _GDIPlus_PenCreate(0xFF0000FF, 15, 2)
Global $hPen = _GDIPlus_PenCreate(0xFFFFFFFF, 15, 2)
Global $hpen_Del = _GDIPlus_PenCreate(0xFF000000, 15, 2)
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos1, 100, $Strichpos2, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $Strichpos1, @DesktopWidth - 100, $Strichpos2, $hPen)
_DrawRahmen()
Sleep ( 500 )
[/autoit] [autoit][/autoit] [autoit]AdlibEnable('_Zyklus', 10)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
Func _ende()
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_PenDispose($hPen)
_GDIPlus_PenDispose($hPenRahmen)
_GDIPlus_PenDispose($hpen_Del)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>_ende
Func Onautoitexit()
_GDIPlus_GraphicsDispose($hGraphic)
_GDIPlus_PenDispose($hPen)
_GDIPlus_PenDispose($hPenRahmen)
_GDIPlus_PenDispose($hpen_Del)
_GDIPlus_Shutdown()
Exit
EndFunc ;==>Onautoitexit
Func _DrawRahmen()
_GDIPlus_GraphicsDrawLine($hGraphic, $Rahmenbreite / 2, 0, $Rahmenbreite / 2, @DesktopHeight, $hPenRahmen)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, $Rahmenbreite / 2, @DesktopWidth, $Rahmenbreite / 2, $hPenRahmen)
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - $Rahmenbreite / 2, 0, @DesktopWidth - $Rahmenbreite / 2, @DesktopHeight, $hPenRahmen)
_GDIPlus_GraphicsDrawLine($hGraphic, 0, @DesktopHeight - $Rahmenbreite / 2, @DesktopWidth, @DesktopHeight - $Rahmenbreite / 2, $hPenRahmen)
$PenColor=_GDIPlus_PenGetColor ( $hPenRahmen )
If $PenColor=0xFF0000FF Then
_GDIPlus_PenSetColor( $hPenRahmen, 0xFFFF0000 )
ElseIf $PenColor=0xFFFF0000 Then
_GDIPlus_PenSetColor( $hPenRahmen, 0xFF00FF00 )
ElseIf $PenColor=0xFF00FF00 Then
_GDIPlus_PenSetColor ( $hPenRahmen, 0xFFFFFF00 )
ElseIf $PenColor=0xFFFFFF00 Then
_GDIPlus_PenSetColor ( $hPenRahmen, 0xFF0000FF )
EndIf
EndFunc ;==>_DrawRahmen
Sleep( 500 )
$begin=TimerInit()
Func _Zyklus()
If _IsPressed('57') Then
_hoch()
EndIf
If _IsPressed('53') Then
_runter()
EndIf
If _IsPressed('26') Then
_hoch2()
EndIf
If _IsPressed('28') Then
_runter2()
EndIf
_ball()
_DetectCollision()
_ScoreUpdate()
EndFunc ;==>_Zyklus
Func _hoch()
If $Strichpos1 >= 25 Then
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos2 - $SpeedBalken, 100, $Strichpos2, $hpen_Del)
$Strichpos1 -= $SpeedBalken
$Strichpos2 -= $SpeedBalken
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos1, 100, $Strichpos2, $hPen)
EndIf
EndFunc ;==>_hoch
Func _runter()
If $Strichpos2 <= @DesktopHeight - 25 Then
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos1, 100, $Strichpos1 + $SpeedBalken, $hpen_Del)
$Strichpos1 += $SpeedBalken
$Strichpos2 += $SpeedBalken
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos1, 100, $Strichpos2, $hPen)
EndIf
EndFunc ;==>_runter
Func _hoch2()
If $RStrichpos1 >= 25 Then
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $RStrichpos2 - $SpeedBalken, @DesktopWidth - 100, $RStrichpos2, $hpen_Del)
$RStrichpos1 -= $SpeedBalken
$RStrichpos2 -= $SpeedBalken
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $RStrichpos1, @DesktopWidth - 100, $RStrichpos2, $hPen)
EndIf
EndFunc ;==>_hoch2
Func _runter2()
If $RStrichpos2 <= @DesktopHeight - 25 Then
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $RStrichpos1, @DesktopWidth - 100, $RStrichpos1 + $SpeedBalken, $hpen_Del)
$RStrichpos1 += $SpeedBalken
$RStrichpos2 += $SpeedBalken
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $RStrichpos1, @DesktopWidth - 100, $RStrichpos2, $hPen)
EndIf
EndFunc ;==>_runter2
Func _ball()
$ball = _GDIPlus_GraphicsDrawArc($hGraphic, $ballpos1, $ballpos2, 15, 15, 180, 360, $hpen_Del)
If $Firstball Then $Speed=1.0
$ballpos2 += $BewegungSenkrecht * $Speed
$ballpos1 += $BewegungWaagerecht * $Speed
$ball = _GDIPlus_GraphicsDrawArc($hGraphic, $ballpos1, $ballpos2, 15, 15, 180, 360, $hPen)
$Firstball = False
EndFunc ;==>_ball
Func _DetectCollision()
If $ballpos1 <= 120 Then
If ($ballpos2 >= $Strichpos1) And ($ballpos2 <= $Strichpos2) Then ; kollision
_RedrawLeftPlayer()
_RedrawRightPlayer()
$Speed=Random( 1, $Difficult )
If $BewegungWaagerecht < 0 Then
$BewegungWaagerecht = Random(5, 7, 1)
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos1, 100, $Strichpos2, $hPen)
EndIf
ElseIf $ballpos1 < 100 Then
setzeausgang(1)
Sleep(1500)
_DrawRahmen()
$Firstball=True
EndIf
EndIf
If $ballpos1 >= @DesktopWidth - 135 Then
If ($ballpos2 >= $RStrichpos1) And ($ballpos2 <= $RStrichpos2) Then ; kollision
_RedrawLeftPlayer()
_RedrawRightPlayer()
$Speed=Random( 1, $Difficult )
If $BewegungWaagerecht > 0 Then
$BewegungWaagerecht = Random(-7, -5, 1)
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $RStrichpos1, @DesktopWidth - 100, $RStrichpos2, $hPen)
EndIf
ElseIf $ballpos1 > @DesktopWidth - 100 Then
setzeausgang(0)
Sleep(1500)
_DrawRahmen()
$Firstball=True
EndIf
EndIf
If $ballpos1 >= @DesktopWidth - 40 And $BewegungWaagerecht > 0 Then
$BewegungWaagerecht = Random(-7, -5, 1)
_DrawRahmen()
EndIf
If $ballpos1 < 30 And $BewegungWaagerecht < 0 Then
$BewegungWaagerecht = Random(5, 7, 1)
_DrawRahmen()
EndIf
If $ballpos2 >= @DesktopHeight - 40 And $BewegungSenkrecht > 0 Then
$BewegungSenkrecht = Random(-7, -5, 1)
_DrawRahmen()
EndIf
If $ballpos2 < 30 And $BewegungSenkrecht < 0 Then
$BewegungSenkrecht = Random(5, 7, 1)
_DrawRahmen()
EndIf
EndFunc ;==>_DetectCollision
[/autoit] [autoit][/autoit] [autoit]Func setzeausgang($points)
If ($points < 1) Or ($points > 0) Then SetError(1)
Switch $points
Case 0
$pointsleft += 1
GUICtrlSetData($Spielstand, $pointsleft & ':' & $pointsright)
Case 1
$pointsright += 1
GUICtrlSetData($Spielstand, $pointsleft & ':' & $pointsright)
EndSwitch
;Ball und Schläger übermalen
_GDIPlus_GraphicsDrawArc($hGraphic, $ballpos1, $ballpos2, 15, 15, 180, 360, $hpen_Del)
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, 13, @DesktopWidth - 100, @DesktopHeight - 13, $hpen_Del)
_GDIPlus_GraphicsDrawLine($hGraphic, 100, 13, 100, @DesktopHeight - 13, $hpen_Del)
;Ball läuft zufallsweise in eine der 4 Richtungen
If Random(0, 1, 1) Then
$BewegungSenkrecht = Random(1, 11, 1)
Else
$BewegungSenkrecht = Random(-11, -1, 1)
EndIf
If Random(0, 1, 1) Then
$BewegungWaagerecht = Random(1, 11, 1)
Else
$BewegungWaagerecht = Random(-11, -1, 1)
EndIf
$ballpos1 = @DesktopWidth / 2
$ballpos2 = @DesktopHeight / 2 - 50
$Strichpos1 = @DesktopHeight / 2 - 70
$Strichpos2 = @DesktopHeight / 2 + 70
$RStrichpos1 = @DesktopHeight / 2 - 70
$RStrichpos2 = @DesktopHeight / 2 + 70
$ball = _GDIPlus_GraphicsDrawArc($hGraphic, $ballpos1, $ballpos2, 15, 15, 180, 360, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos1, 100, $Strichpos2, $hPen)
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $Strichpos1, @DesktopWidth - 100, $Strichpos2, $hPen)
EndFunc ;==>setzeausgang
Func _ScoreUpdate()
$dif=TimerDiff( $begin )
If $dif>=100 Then
GUICtrlSetData($Spielstand, $pointsleft & ':' & $pointsright)
$begin=TimerInit()
EndIf
EndFunc
Func _RedrawRightPlayer()
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos2 - $SpeedBalken, 100, $Strichpos2, $hpen_Del)
_GDIPlus_GraphicsDrawLine($hGraphic, 100, $Strichpos1, 100, $Strichpos2, $hPen)
EndFunc
Func _RedrawLeftPlayer()
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $RStrichpos2 - $SpeedBalken, @DesktopWidth - 100, $RStrichpos2, $hpen_Del)
_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - 100, $RStrichpos1, @DesktopWidth - 100, $RStrichpos2, $hPen)
EndFunc
- Leertaste starten
- W und S den linken Spieler lenken
- Pfeil hoch und Pfeil Runter rechten Spieler lenken
- ESC beenden
Diffcult ist auf 1.7 , ist schon recht schwer so
Hoffe es läuft einigermassen Bugfrei, war damals mein erstest Projekt mit GDI+.
Gruss Greek