Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Pong v1.0


  • Please log in to reply
7 replies to this topic
Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
I've put together a very simple game of ping pong using autohotkey.

Posted Image

You will need to save the following file to the same directory as the script-

http://hometown.aol....RMC137/ball.bmp (right click>Save as)

If the above link doesn't work-
https://ahknet.autoh...er/pub/ball.bmp


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.brinkst...Acsell/pong.asp

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


polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
After several games my highest score was 7 in a 1st-to-10 game with the comp :oops: lol.
Nice one Jon :)

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004
Error 404

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


polyethene
  • Members
  • 5519 posts
  • Last active: May 17 2015 06:39 AM
  • Joined: 26 Oct 2012
https://ahknet.autoh...er/pub/pong.zip

Sorry, I forgot the proper directory when I was changing the permissions.

autohotkey.com/net Site Manager

 

Contact me by email (polyethene at autohotkey.net) or message tidbit


Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Thanks Titan.

Belial
  • Members
  • 40 posts
  • Last active: Jan 19 2007 03:21 AM
  • Joined: 26 Jun 2005
Damn game, sometimes when the ball hits the button [not in the middle] it scores a point to the Computer ... That is called cheating =X ... My High-Score was 8, but usually I score 5-6
Belial

Elevator_Hazard
  • Members
  • 297 posts
  • Last active: Feb 07 2011 12:10 AM
  • Joined: 28 Oct 2006
So I know that this is an old post, but I have a question: Can this be a way to upload files to the internet without using ftp? I would like to know... I am assuming that the values at the end of the url in the script are for info to upload on a file... But I need to know stuff like this as an alternative for ftp usage.
Changed siggy at request of ahklerner :D

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004

So I know that this is an old post, but I have a question: Can this be a way to upload files to the internet without using ftp? I would like to know... I am assuming that the values at the end of the url in the script are for info to upload on a file... But I need to know stuff like this as an alternative for ftp usage.


It actually stored the score in a database as plain text. The asp script took several parameters e.e.

htttp://mywebsite/my.asp?username=Jon&score=10

I' pretty sure asp supports file upload (I know PHP supports file upload) so you could probably use it for file upload as well e.g.

http://mywebsite/my.asp?filetoupload=c:\myfile.exe

If you can write an asp or php script to receive the file path as above then it could be used to upload files.