I've put together a very simple game of ping pong using autohotkey.
You will need to save the following file to the same directory as the script-
http://hometown.aol.co.uk/JRMC137/ball.bmp (right click>Save as)
If the above link doesn't work-
http://autohotkey.net/file/user/pub/ball.bmp
Code:
Gui,Color, D1FCD3, 912206
Gui, Add, Picture, x157 y31 w20 h20, %a_workingdir%\ball.bmp
Gui, Add, Button, x126 y10 w80 h20,
Gui, Add, Button, x138 y405 w80 h20,
Gui, Add, GroupBox, x6 y0 w330 h430,
Gui, Show, h438 w344, Pong v1.0
gui, 2:+owner ; Make #2 window owned by script's main window.
Gui,2:Color, F1FEF2, 912206
Gui,2: -caption
Gui, 2:Add, Text, x24 y11 w90 h20, Computers Score
Gui, 2:Add, Text, x116 y12 w56 h16, Your Score
Gui, 2:Font, cBlue s18 bold,
Gui, 2:Add, Text, x36 y34 w40 h30, 0
Gui, 2:Add, Text, x126 y34 w40 h30, 0
Gui, 2:Add, GroupBox, x6 y-11 w190 h90,
Gui, 2:Add, GroupBox, x116 y14 w60 h60,
Gui, 2:Add, GroupBox, x26 y14 w60 h60,
WinGetPos, winX, winY, winWidth, winHeight, Pong
winX+=%winWidth%
Gui, 2:Show, x%winX% y%winY% h85 w203, Score
winactivate, Pong
sleep, 2000
SetTimer, Button1, 260
SetTimer, Button2, 100
Random, BStartXPos, 10, 340
ControlMove, Static1, %BStartXPos%, 60, , , Pong
starty=60
dir=down
go=left
inc=1
setbatchlines, -1
loop
{
if dir=down
starty+=8
if dir=up
starty-=8
if go=left
BStartXPos+=%inc%
if go=right
BStartXPos-=%inc%
if BStartXPos >= 330
{
go=right
Random, inc, 0, 6
}
if BStartXPos <= 10
{
go=left
Random, inc, 0, 8
}
if starty = 420
{
dir=up
ControlGetPos, bposX, , , , Static1, Pong
ControlGetPos, batposX, , , , Button2, Pong
if bposX not between %batposX% and % batposX+80
{
YourScore+=1
SetTimer, Button1, off
SetTimer, Button2, off
sleep, 500
SetTimer, Button1, on
SetTimer, Button2, on
ControlSetText, Static3, %YourScore%, Score
}
}
if starty=60
{
dir=down
ControlGetPos, bposX, , , , Static1, Pong
ControlGetPos, batposX, , , , Button1, Pong
if bposX not between %batposX% and % batposX+80
{
CompScore+=1
SetTimer, Button1, off
SetTimer, Button2, off
sleep, 500
SetTimer, Button1, on
SetTimer, Button2, on
ControlSetText, Static4, %CompScore%, Score
}
}
ControlMove, Static1, %BStartXPos%, %starty%, , , Pong
}
Button1:
Ball1pos:=BStartXPos-40
ControlMove, Button1, %Ball1pos%, , , , Pong
return
Button2:
ifwinactive, Pong
{
MouseGetPos, MPosX
MPosX-=40
ControlMove, Button2, %MPosX%, , , , Pong
}
return
GuiClose:
ExitApp
This one will update your scores online so that the scores can be compared. It is the best out of 10 between you and the computer. When the combined scores equals 10 you will get a message asking for your username. When you have entered your username (you can make one up) the score board will be displayed online.
You can view the scoreboard here-
http://www50.brinkster.com/Acsell/pong.aspCode:
Gui,Color, D1FCD3, 912206
Gui, Add, Picture, x157 y31 w20 h20, %a_workingdir%\ball.bmp
Gui, Add, Button, x126 y10 w80 h20,
Gui, Add, Button, x138 y405 w80 h20,
Gui, Add, GroupBox, x6 y0 w330 h430,
Gui, Show, h438 w344, Pong v1.0
gui, 2:+owner ; Make #2 window owned by script's main window.
Gui,2:Color, F1FEF2, 912206
Gui,2: -caption
Gui, 2:Add, Text, x24 y11 w90 h20, Computers Score
Gui, 2:Add, Text, x116 y12 w56 h16, Your Score
Gui, 2:Font, cBlue s18 bold,
Gui, 2:Add, Text, x36 y34 w40 h30, 0
Gui, 2:Add, Text, x126 y34 w40 h30, 0
Gui, 2:Add, GroupBox, x6 y-11 w190 h90,
Gui, 2:Add, GroupBox, x116 y14 w60 h60,
Gui, 2:Add, GroupBox, x26 y14 w60 h60,
WinGetPos, winX, winY, winWidth, winHeight, Pong
winX+=%winWidth%
Gui, 2:Show, x%winX% y%winY% h85 w203, Score
winactivate, Pong
sleep, 2000
SetTimer, Button1, 260
SetTimer, Button2, 100
Random, BStartXPos, 10, 340
ControlMove, Static1, %BStartXPos%, 60, , , Pong
starty=60
dir=down
go=left
inc=1
CompScore=0
YourScore=0
setbatchlines, -1
loop
{
if dir=down
starty+=8
if dir=up
starty-=8
if go=left
BStartXPos+=%inc%
if go=right
BStartXPos-=%inc%
if BStartXPos >= 330
{
go=right
Random, inc, 0, 6
}
if BStartXPos <= 10
{
go=left
Random, inc, 0, 8
}
if starty = 420
{
dir=up
ControlGetPos, bposX, , , , Static1, Pong
ControlGetPos, batposX, , , , Button2, Pong
if bposX not between %batposX% and % batposX+80
{
YourScore+=1
SetTimer, Button1, off
SetTimer, Button2, off
sleep, 500
SetTimer, Button1, on
SetTimer, Button2, on
ControlSetText, Static3, %YourScore%, Score
}
}
if starty=60
{
dir=down
ControlGetPos, bposX, , , , Static1, Pong
ControlGetPos, batposX, , , , Button1, Pong
if bposX not between %batposX% and % batposX+80
{
CompScore+=1
SetTimer, Button1, off
SetTimer, Button2, off
sleep, 500
SetTimer, Button1, on
SetTimer, Button2, on
ControlSetText, Static4, %CompScore%, Score
}
}
ControlMove, Static1, %BStartXPos%, %starty%, , , Pong
totscore:=CompScore+YourScore
if totscore = 10
{
if CompScore>%YourScore%
updatescores(CompScore, "Win")
else
updatescores(CompScore, "Lose")
ControlSetText, Static4, 0, Score
ControlSetText, Static3, 0, Score
MsgBox, 36, Game Over, Play again?
IfMsgBox, No
Exitapp
Else
reload
}
}
Button1:
Ball1pos:=BStartXPos-40
ControlMove, Button1, %Ball1pos%, , , , Pong
return
Button2:
ifwinactive, Pong
{
MouseGetPos, MPosX
MPosX-=40
ControlMove, Button2, %MPosX%, , , , Pong
}
return
updatescores(score, outcome)
{
InputBox, UserInput, You %outcome%! with a score of %score%, Enter your User Name below to add your score to the scoreboard, , 300, 135
if ErrorLevel <> 0
return
If UserInput=
return
run, iexplore.exe http://www50.brinkster.com/Acsell/pong.asp?Score=%score%&UserName=%UserInput%
return
}
GuiClose:
ExitApp