ioa747 Posted December 5 Posted December 5 (edited) What can I say, the holidays are coming, ho ho ho Happy holidays to all of you with health and joy. prologue: Pong is one of the first computer games that ever created, Research Interview Series #16: Allan Alcorn, the creator of Pong This is a simple outline variation "tennis like" game, that helped me kill my time expandcollapse popup; https://www.autoitscript.com/forum/topic/212523-tennispong/ ;---------------------------------------------------------------------------------------- ; Title...........: TennisPong.au3 ; Description.....: Pong is one of the first computer games that ever created, ; this a simple outline "tennis like" game ; AutoIt Version..: 3.3.16.1 Author: ioa747 Script Version: 1.0 ; Note............: Testet in Win10 22H2 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <Misc.au3> #include <WinAPISysWin.au3> HotKeySet("{ESC}", "_Exit") _Pong() Func _Pong() Local $iWidth = @DesktopWidth, $iHeight = @DesktopHeight Local $iBallSize = 25 Local $iPaddleWidth = 200, $iPaddleHeight = 165 Local $iBallX = $iWidth / 2, $iBallY = $iHeight / 2 Local $iBallSpeedX = 15, $iBallSpeedY = 15 Local $iPaddleX = ($iWidth / 2) - ($iPaddleWidth / 2) Local $iPaddelSpace = 30 Local $iScore = 0 ; Create score GUI as parent Local $hDisplay = GUICreate("TennisPong", 150, 50, $iWidth - 160, 3, $WS_POPUP, BitOR($WS_EX_COMPOSITED, $WS_EX_LAYERED, $WS_EX_TOPMOST, $WS_EX_TRANSPARENT)) Local $idScore = GUICtrlCreateLabel($iScore, 0, 0, 150, 50, $SS_CENTER) GUICtrlSetFont(-1, 30, 800, 0, "MS Sans Serif") GUICtrlSetColor(-1, 0x00FF21) GUISetBkColor(0x000000, $hDisplay) WinSetTrans($hDisplay, "", 80) GUISetState(@SW_SHOW, $hDisplay) ; Create paddle GUI Local $hPaddle = GUICreate("", $iPaddleWidth, $iPaddleHeight, $iPaddleX, $iHeight - $iPaddleHeight + $iPaddelSpace, _ $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDisplay) GUICtrlCreatePic(".\res\paddel2.gif", 0, 0, 0, 0) ; Create ball GUI Local $hBall = GUICreate("", $iBallSize, $iBallSize, $iBallX, $iBallY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_MDICHILD), $hDisplay) GUICtrlCreatePic(".\res\Tball.gif", 0, 0, 0, 0) GUISetState(@SW_SHOW, $hPaddle) GUISetState(@SW_SHOW, $hBall) While 1 Local $aMPos = MouseGetPos() $iPaddleX = $aMPos[0] ; Keep paddle within screen If $iPaddleX < 0 Then $iPaddleX = 0 If $iPaddleX > $iWidth - $iPaddleWidth Then $iPaddleX = $iWidth - $iPaddleWidth ; Move the ball $iBallX += $iBallSpeedX $iBallY += $iBallSpeedY ; Ball collision with top If $iBallY <= 0 Then $iBallSpeedY = -$iBallSpeedY Beep(300, 100) EndIf ; Ball collision with left and right If $iBallX <= 0 Or $iBallX >= ($iWidth - $iBallSize) Then $iBallSpeedX = -$iBallSpeedX Beep(200, 100) EndIf ; Ball collision with paddle If ($iBallX >= $iPaddleX And $iBallX <= ($iPaddleX + $iPaddleWidth) And _ $iBallY >= ($iHeight - $iPaddleHeight - $iBallSize + $iPaddelSpace)) And _ $iBallY <= ($iHeight - $iPaddleHeight - $iBallSize + $iPaddelSpace + $iBallSize / 2) Then $iBallSpeedY = -$iBallSpeedY Beep(300, 100) $iScore += 1 GUICtrlSetData($idScore, $iScore) EndIf ; Reset ball if it goes out of bounds If $iBallY > $iHeight Then $iBallX = $iWidth / 2 $iBallY = $iHeight / 2 Sleep(3000) $iScore = 0 GUICtrlSetData($idScore, $iScore) Beep(200, 200) EndIf WinMove($hPaddle, "", $iPaddleX, $iHeight - $iPaddleHeight) WinMove($hBall, "", $iBallX, $iBallY) ; Check for exit If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop Sleep(30) WEnd GUIDelete() EndFunc ;==>_Pong ;---------------------------------------------------------------------------------------- Func _Exit() Exit EndFunc ;==>_Exit ;---------------------------------------------------------------------------------------- TennisPong.zip have fun Thank you very much Edited December 6 by ioa747 Dan_555, CYCho and argumentum 3 I know that I know nothing
argumentum Posted December 6 Posted December 6 (edited) ..added "demo mode" 😇 Spoiler ... ;~ HotKeySet("{ESC}", "_Exit") ... Local $iDemoMode = 0 ; set to 1 to "demo mode" ( play by itself ) Local $iWidth = @DesktopWidth, $iHeight = @DesktopHeight ... While 1 If _IsPressed("26") Then $iDemoMode = 0 ; OFF ; UP ARROW key If _IsPressed("28") Then $iDemoMode = 1 ; ON ; DOWN ARROW key If _IsPressed("1B") Then ExitLoop ; Exit ; ESC key ... If $iDemoMode Then $iPaddleX = $iBallX - ($iPaddleWidth / 2) ; Ball collision with paddle ... WinMove($hPaddle, "", ($iDemoMode ? $iBallX - ($iPaddleWidth / 2) : $iPaddleX), $iHeight - $iPaddleHeight) WinMove($hBall, "", $iBallX, $iBallY) ... Because I enjoy watching it Edited December 6 by argumentum ioa747 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now