This is kind of an old project I made. I wanted to add a menu system and an option to select between playing against computer or 2 player, but I could not figure it out and had to resort to commenting out 1 or the other. The ball does not move very smooth since it just moves multiple pixels per move the faster it gets.
Hopefully someone will be encouraged or inspired by this, Here it is:
<!---*CraSH* Programmer: Peter Schooley Date: 9:42 AM 1/17/2008 Description: **---> ;*CraSH* ;Programmer: Peter Schooley ;Date: 3:42 PM 6/17/2007 ;Description: Its a pong clone. ;Controls ; Control+Shift+Z = Starts game ; w = 1st player up ; s = 1st player down ; up arrow = 2nd player up ; down arrow = 2nd player down ; ; Script Function: ; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder) ; #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. ; ; AutoHotkey Version: 1.x ; Language: English ; Platform: Win9x/NT ; Author: A.N.Other <[email protected]> ; ; Script Function: ; Template script (you can customize this template by editing "ShellNew\Template.ahk" in your Windows folder) ; #NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases. SendMode Input ; Recommended for new scripts due to its superior speed and reliability. SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. ^r::reload ^+s::edit ^+z:: GoSub, PlayGame return PlayGame: x1 := A_ScreenWidth/2 y1 := A_ScreenHeight/2 Ball_ImgW = 20 Ball_ImgH = 20 ScrnW := A_ScreenWidth-Ball_ImgW ScrnH := A_ScreenHeight-Ball_ImgH p1_pad_W = 13 p1_pad_H = 93 p1_pad_h_mid := p1_pad_H/2 p2_pad_W = 13 p2_pad_H = 93 p2_pad_h_mid := p2_pad_H/2 p1_pad_x := 20+p1_pad_w/2 p1_pad_y := y1-p1_pad_H/2 p2_pad_x := A_ScreenWidth-(20+p1_pad_w/2) p2_pad_y := y1-p2_pad_H/2 P1Color = Red P2Color = Blue P1Scorexpos := x1-200 P2Scorexpos := x1+100 p1_Score = 0 p2_Score = 0 ScoreToWin = 10 Random, GoSouth, 1, 2 Random, GoWest, 1, 2 ball_speeder = 20 p1_speeder = 30 p2_speeder = 30 Gosub, MakeBall Gosub, MakePlayerOne Gosub, MakePlayerTwo Gosub, PlayerOneScoreBoard Gosub, PlayerTwoScoreBoard loop { ;ball_speeder := ball_speeder+.1 WinMove, the_ball,, %x1%, %y1% Random, p2_bored, 1, 10 if (GoWest =1 and p2_bored <> 1) { if (p2_pad_y+p2_pad_h_mid > y1 and y1 > A_ScreenHeight*.1) { p2_pad_y := p2_pad_y-(1*p2_speeder) WinMove, p2_paddle,, %p2_pad_x%, %p2_pad_y% } else if (p2_pad_y+p2_pad_h_mid < y1 and y1 < A_ScreenHeight*.9) { p2_pad_y := p2_pad_y+(1*p2_speeder) WinMove, p2_paddle,, %p2_pad_x%, %p2_pad_y% } } if (p1_pad_y < y1 and p1_pad_y+p1_pad_H > y1) { ;msgbox inbetween p1 horizontally x1: %x1%, value: %p1_pad_x%+%p1_padw% if(p1_pad_x+p1_pad_W > x1) { ;msgbox HIT PLAYER 1, BOUNCE!! GoWest = 1 } } if (p2_pad_y < y1 and p2_pad_y+p2_pad_H > y1) { ;msgbox inbetween p2 horizontally if(p2_pad_x < x1+Ball_ImgW) { ;msgbox HIT PLAYER 2, BOUNCE!! GoWest = 0 } } if (x1 < 2) { GoWest = 1 p2_Score++ Gosub, UpdateOSD2 } if (x1 > ScrnW) { GoWest = 0 p1_Score++ Gosub, UpdateOSD } if (y1 < 2) GoSouth = 1 if (y1 > ScrnH) GoSouth = 0 if (GoWest = 1) x1 := x1+(1*ball_speeder) else x1 := x1-(1*ball_speeder) if (GoSouth = 1) y1 := y1+(1*ball_speeder) else y1 := y1-(1*ball_speeder) } return MakeBall: Gui, 1:Color, black, Gui, 1:Add, Picture, X0 Y0 H%Ball_ImgH% W%Ball_ImgW%, C:\ball.jpg Gui, 1:-Caption +ToolWindow +Disabled +AlwaysOntop +LastFound Gui, 1:Show, X%x1% Y%y1% W%Ball_ImgW% H%Ball_ImgH%, the_ball return MakePlayerOne: Gui, 4:Color,%P1Color%, Gui, 4:Add, Picture, X0 Y0 H%p1_pad_H% W%p1_pad_W%, C:\red_pong_paddle.bmp Gui, 4:-Caption +ToolWindow +Disabled +AlwaysOntop +LastFound Gui, 4:Show, X%p1_pad_x% Y%p1_pad_y% W%p1_pad_W% H%p1_pad_H%, p1_paddle return MakePlayerTwo: Gui, 5:Color,%P2Color%, Gui, 5:Add, Picture, X0 Y0 H%p2_pad_H% W%p2_pad_W%, C:\blue_pong_paddle.bmp Gui, 5:-Caption +ToolWindow +Disabled +AlwaysOntop +LastFound Gui, 5:Show, X%p2_pad_x% Y%p2_pad_y% W%p2_pad_W% H%p2_pad_H%, p2_paddle return PlayerOneScoreBoard: CustomColor = ffffff Gui 3:+LastFound +AlwaysOnTop -Caption +ToolWindow Gui, 3:Color, %CustomColor% Gui, 3:Font, s40 Gui, 3:Add, Text, vMyText c%P1Color%, 00 WinSet, TransColor, %CustomColor% 150 Gui, 3:Show, x%P1Scorexpos% y10 NoActivate return PlayerTwoScoreBoard: CustomColor = ffffff Gui 2:+LastFound +AlwaysOnTop -Caption +ToolWindow Gui, 2:Color, %CustomColor% Gui, 2:Font, s40 Gui, 2:Add, Text, vMyText2 c%P2Color%, 00 WinSet, TransColor, %CustomColor% 150 Gui, 2:Show, x%P2Scorexpos% y10 NoActivate return UpdateOSD: if (p1_Score >= ScoreToWin) GoSub, WinnerIs GuiControl,3:, MyText, %p1_Score% return UpdateOSD2: if (p2_Score >= ScoreToWin) GoSub, WinnerIs GuiControl,2:, MyText2, %p2_Score% return WinnerIs: if(p1 >= ScoreToWin) { msgbox Player1 Wins! } else { msgbox Player2 Wins! } MsgBox, 4,, Would you like to Play again? IfMsgBox Yes Reload else exitapp return ~w:: p1_pad_y := p1_pad_y-(1*p1_speeder) WinMove, p1_paddle,, %p1_pad_x%, %p1_pad_y% return ~s:: p1_pad_y := p1_pad_y+(1*p1_speeder) WinMove, p1_paddle,, %p1_pad_x%, %p1_pad_y% return ;Comment out the computer ai and un-comment the below to play 2 player /* ~up:: p2_pad_y := p2_pad_y-(1*p2_speeder) WinMove, p2_paddle,, %p2_pad_x%, %p2_pad_y% return ~down:: p2_pad_y := p2_pad_y+(1*p2_speeder) WinMove, p2_paddle,, %p2_pad_x%, %p2_pad_y% return */