AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Pong v1.0

 
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Jon



Joined: 28 Apr 2004
Posts: 349

PostPosted: Sun Apr 24, 2005 5:47 pm    Post subject: Pong v1.0 Reply with quote

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.asp

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
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


Last edited by Jon on Tue May 24, 2005 10:59 pm; edited 13 times in total
Back to top
View user's profile Send private message Send e-mail
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Sun Apr 24, 2005 5:53 pm    Post subject: Reply with quote

After several games my highest score was 7 in a 1st-to-10 game with the comp Embarassed lol.
Nice one Jon Smile
_________________
GitHubScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Rajat



Joined: 28 Mar 2004
Posts: 1687

PostPosted: Sun Apr 24, 2005 6:06 pm    Post subject: Reply with quote

Error 404
_________________
Back to top
View user's profile Send private message
polyethene



Joined: 11 Aug 2004
Posts: 5248
Location: UK

PostPosted: Sun Apr 24, 2005 6:07 pm    Post subject: Reply with quote

http://www.autohotkey.net/fileman/user/pub/pong.zip

Sorry, I forgot the proper directory when I was changing the permissions.
_________________
GitHubScriptsIronAHK Contact by email not private message.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Jon



Joined: 28 Apr 2004
Posts: 349

PostPosted: Sun Apr 24, 2005 6:33 pm    Post subject: Reply with quote

Thanks Titan.
Back to top
View user's profile Send private message Send e-mail
Belial



Joined: 26 Jun 2005
Posts: 40
Location: Portugal

PostPosted: Mon Jul 11, 2005 12:30 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
Elevator_Hazard



Joined: 28 Oct 2006
Posts: 297
Location: US

PostPosted: Sun Mar 04, 2007 3:20 am    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message
Jon



Joined: 28 Apr 2004
Posts: 349

PostPosted: Sat Mar 10, 2007 12:01 pm    Post subject: Reply with quote

Elevator_Hazard wrote:
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.
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group