AutoHotkey Community

It is currently May 26th, 2012, 7:02 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Pong v1.0
PostPosted: April 24th, 2005, 6:47 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
I've put together a very simple game of ping pong using autohotkey.

Image

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 May 24th, 2005, 11:59 pm, edited 13 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2005, 6:53 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
After several games my highest score was 7 in a 1st-to-10 game with the comp :oops: lol.
Nice one Jon :)

_________________
GitHubScriptsIronAHK Contact by email not private message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2005, 7:06 pm 
Offline

Joined: March 28th, 2004, 3:53 pm
Posts: 1870
Error 404

_________________
Image


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2005, 7:07 pm 
Offline
User avatar

Joined: August 11th, 2004, 1:47 am
Posts: 5347
Location: UK
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: April 24th, 2005, 7:33 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
Thanks Titan.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 11th, 2005, 1:30 am 
Offline

Joined: June 26th, 2005, 9:43 pm
Posts: 40
Location: Portugal
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 4th, 2007, 4:20 am 
Offline

Joined: October 28th, 2006, 2:14 am
Posts: 297
Location: US
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


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 10th, 2007, 1:01 pm 
Offline

Joined: April 28th, 2004, 1:12 pm
Posts: 349
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.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Apollo, Bing [Bot], fusion1920, infogulch, Scratch and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group