 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Lequi* Guest
|
Posted: Fri Aug 31, 2007 1:16 pm Post subject: Pong - the ultimate retro game |
|
|
its one or my first scripts done with ahk so i wanted to ask if i can optimize sth, i can for sure let the code look better with more comments etc but i dont comment much normaly
at first u can simply test the game and post suggestions or improvements here. many thanks in advance
The lastest version of this script is now further below in this same topic. |
|
| Back to top |
|
 |
Charon the Hand
Joined: 07 Aug 2007 Posts: 4
|
Posted: Fri Aug 31, 2007 3:18 pm Post subject: |
|
|
| This is pretty impressive. One minor problem is when the paddle is at the bottom of the screen, half of it wraps around to the top. Also the bounces were a little wierd when I got my paddle there almost too late to catch the ball. Overall, a very cool little script. |
|
| Back to top |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 502
|
Posted: Fri Aug 31, 2007 3:25 pm Post subject: |
|
|
Very Nice! I like it. I havent had a chance to play it a lot, but does the computer ever miss? I havent seen it miss once... _________________
HTH...
 |
|
| Back to top |
|
 |
Lequi Guest
|
Posted: Fri Aug 31, 2007 5:54 pm Post subject: |
|
|
| Code: | | settimer, pcmove, 1 ;<--- sets pc difficult |
thats the timer triggering the pc movement, 1 ms is quite fast if its too hard you can change 1 ms to 15 (beatable) or even 30, that would be quite easy.
you can also change the ball base speed and its increasing speed every 3 sek if you want
| Code: | if SW < 1300 ;<--- sets the ball speed
speed = 10
else
speed = 15 |
if your monitor is 1280 x xxx or below u need to change the upper line, in my case, 1680x 1050, i need to change the lower one |
|
| Back to top |
|
 |
aCkRiTe
Joined: 21 Jul 2006 Posts: 502
|
Posted: Fri Aug 31, 2007 6:48 pm Post subject: |
|
|
Thanks! Guess I should have taken a look at you code comments...  _________________
HTH...
 |
|
| Back to top |
|
 |
Lequi Guest
|
Posted: Fri Aug 31, 2007 7:02 pm Post subject: |
|
|
| i got sounds too, which truly make this game retro style, is there a way to attach them to this forum? i got no space where i could upload them :/ |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5884
|
|
| Back to top |
|
 |
Lequi
Joined: 31 Aug 2007 Posts: 29
|
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5884
|
Posted: Fri Aug 31, 2007 9:09 pm Post subject: |
|
|
Add this to the top of the script:
| Code: | SetWorkingDir, %A_ScriptDir%
IfNotExist, pong_board_bounce.wav, UrlDownloadToFile
, http://www.autohotkey.net/~Lequi/pong_board_bounce.wav
, pong_board_bounce.wav
IfNotExist, pong_goal.wav, UrlDownloadToFile
, http://www.autohotkey.net/~Lequi/pong_goal.wav
, pong_goal.wav
IfNotExist, pong_wall_bounce.wav, UrlDownloadToFile
, http://www.autohotkey.net/~Lequi/pong_wall_bounce.wav
, pong_wall_bounce.wav |
 |
|
| Back to top |
|
 |
Lequi
Joined: 31 Aug 2007 Posts: 29
|
Posted: Fri Aug 31, 2007 9:26 pm Post subject: |
|
|
cause i cant edit my first post, (wasnt registered to that point of time) here the new version: this now downloads the sound files if you dont have them alrdy and the hotkeys only work if pong is the active window
| Code: | | Scroll down a few posts to see the latest script |
thx skan
edit: changed buttons to progress bar in order to change colors, looks a bit more retro 
Last edited by Lequi on Fri Aug 31, 2007 9:33 pm; edited 1 time in total |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5884
|
Posted: Fri Aug 31, 2007 9:33 pm Post subject: |
|
|
| Lequi wrote: | | cause i cant edit my first post, (wasnt registered to that point of time) |
A moderator can alter the ownership of the title post.
Send a PM to one of them ( maybe Titan )
| Lequi previously wrote: | | a suggestion from me is to hide the mouse cursor, anyone knows how to manage that? |
Here is a working demo. Adapt it to your needs:
| Code: | DllCall("ShowCursor", UInt,False )
Gui, Show, w400 h300, No Cursor Zone
OnExit, QuitScript
Return
GuiClose:
QuitScript:
DllCall("ShowCursor", UInt,True )
ExitApp
Return |
 |
|
| Back to top |
|
 |
Lexikos
Joined: 17 Oct 2006 Posts: 2558 Location: Australia, Qld
|
Posted: Sat Sep 01, 2007 5:16 am Post subject: |
|
|
Heh, nice. The first thing I did after trying it - I added: | Code: | Gui, +LastFound
WinSet, TransColor, Black | above | Code: | | gui, +toolwindow +alwaysontop |
 |
|
| Back to top |
|
 |
Lequi
Joined: 31 Aug 2007 Posts: 29
|
Posted: Sat Sep 01, 2007 11:04 am Post subject: |
|
|
this is the latest version
change some more things and now its easier to configurate it like you want
edit: included ingame difficult config for those who cant change the code (compiled version)
- added impossible mode (believe me, it is )
| Code: |
;configuration area:
color1 = Lime ; color of the players paddle, colorname or hexcode
color2 = Lime ; color of the computer paddle, "
color3 = Lime ; color of the ball, "
transparent_background = 0 ; enter 1 to have a complete transparent background, 0 for a black bg
random_angle = 15 ; determines angle of incidence = angle of reflection, if 0 it is mathematicaly
; correct, 50 or more is totaly random
;end of configuration
;ingame config
gui, 3:default
gui, margin, 15 ,15
gui, font, s13
Gui, Add, Text,, Instructions:
gui, font, s10
gui, add, text,, F1 for help.`nLeft Mouseclick to start the ball`nP for Pause`nCtrl+x for exit`nS to toggle sound on/off
gui, font, s13
Gui, Add, Text,, Choose your difficulty:
gui, font, s10
Gui, Add, Button, gBeg w350 h25 x20 y200, Beginner
Gui, Add, Button, gInt wp hp xp yp+30, Intermediate
Gui, Add, Button, gHard wp hp xp yp+30, Hard
Gui, Add, Button, gimp wp hp xp yp+30, Impossible
Gui, Show,autosize, Ping Pong
return
Beg:
pc_difficulty = 30
pc_board_speed = 15
ball_speed = 15
ball_increasing_speed = 2
gui, destroy
goto go_ahead
return
Int:
pc_difficulty = 20
pc_board_speed = 23
ball_speed = 23
ball_increasing_speed = 4
gui, destroy
goto go_ahead
return
Hard:
pc_difficulty = 1
pc_board_speed = 30
ball_speed = 30
ball_increasing_speed = 5
gui, destroy
goto go_ahead
return
imp:
imp =1
pc_difficulty = 1
pc_board_speed = 30
ball_speed = 35
ball_increasing_speed = 7
gui, destroy
goto go_ahead
return
go_ahead:
#persistent
SetWorkingDir, %A_ScriptDir%
IfNotExist, pong_board_bounce.wav, UrlDownloadToFile
, http://www.autohotkey.net/~Lequi/pong_board_bounce.wav
, pong_board_bounce.wav
IfNotExist, pong_goal.wav, UrlDownloadToFile
, http://www.autohotkey.net/~Lequi/pong_goal.wav
, pong_goal.wav
IfNotExist, pong_wall_bounce.wav, UrlDownloadToFile
, http://www.autohotkey.net/~Lequi/pong_wall_bounce.wav
, pong_wall_bounce.wav
SW := A_ScreenWidth
SH := A_ScreenHeight
SW_2 := A_ScreenWidth/2
SH_2 := A_ScreenHeight/2
right_goal := SW-30
right_block := SW-80
lower_bounce := SH-20
xpos_board2 := SW-50
points0= 0
points1= 0
check= 1
sound = 1
gui,1:default
DllCall("ShowCursor", UInt,False )
if transparent_background
{
Gui, +LastFound
WinSet, TransColor, Black
}
gui, +toolwindow +alwaysontop
gui, color, black
temp := SW_2-0.1*SW
gui, font, s35
Gui, Add, Text, -wrap vstats cLime x%temp% y50 w200, %points0% : %points1%
temp := SW_2-100
temp2 := SH_2-50
Gui, add, text, vpause cLime x%temp% y%temp2%, Paused
guicontrol, hide, pause
gui, add, progress, Background%color3% vball w20 h20 x%sw_2% y%sh_2%
temp := SH_2-50
gui, add, progress, Background%color1% vboard1 x50 y%temp% w30 h100
gui, add, progress, Background%color2% vboard2 x%xpos_board2% y%temp% w30 h100
temp := SW-0.1*SW
gui, font, s15
gui, add, text, vvsound cgray x%temp% y30, Sound: On
gui, show, w%sw% h%sh%
settimer, mousemove, 10
settimer, pcmove, %pc_difficulty%
settimer, balance, 3000
if SW < 1300
offset := ball_speed-5
else
offset := ball_speed
goto init
return
init:
KeyWait, LButton, D
if check
goto start
return
start:
check=0
pi := (4*Atan(1))
loop
{
random, angle, 0, 360
;msgbox %angle%
if angle between 45 and 135
continue
if angle between 225 and 315
continue
else
break
}
goto move
return
mousemove: ;player board moving
if not check
{
mousegetpos,, mousey
mousey -= 65
guicontrol, move, board1, x50 y%mousey%
}
return
pcmove:
GuiControlGet, board2, Pos
GuiControlGet, ball, Pos
bally -= 50
if xpos < %SW_2% ; ball in player half
{
dif := abs(board2y - SH_2)
if dif < 20
pc_offset =0
else
pc_offset = %pc_board_speed%
if board2y < %SH_2%
{
pc_ypos := board2y + pc_offset
}
else
{
pc_ypos := board2y - pc_offset
}
guicontrol, move, board2, x%xpos_board2% y%pc_ypos%
}
else ; ball in pc's half
{
dif := abs(board2y - bally)
if dif < 20
pc_offset =0
else
pc_offset = 20
if board2y < %bally%
{
pc_ypos := board2y + pc_offset
}
else
{
pc_ypos := board2y - pc_offset
}
if imp
guicontrol, move, board2, x%xpos_board2% y%bally%
else
guicontrol, move, board2, x%xpos_board2% y%pc_ypos%
}
return
move: ;ball moving
loop
{
rad := angle * pi/180
GuiControlGet, ball, Pos
xpos := ballx + cos(rad)*offset
ypos := bally + sin(rad)*offset
guicontrol, move, ball, x%xpos% y%ypos%
if bounce
{
offset -=30
bounce =0
}
sleep 1
;bounce
random, rnd, -%random_angle%, %random_angle%
if xpos > %right_block% ;right side block
{
diff := ypos-pc_ypos
if diff between 0 and 100
{
bounce = 1
offset += 30
if sound
soundplay, %a_workingdir%\pong_board_bounce.wav
angle := 180-angle+rnd
}
}
if xpos > %right_goal% ;right side goal
{
if sound
soundplay, %a_workingdir%\pong_goal.wav
points0++
GuiControl,, stats, %points0% : %points1%
guicontrol, move, ball, x%sw_2% y%sh_2%
bounce =0
if SW < 1300
offset := ball_speed-5
else
offset := ball_speed
KeyWait, LButton, D
goto start
}
if xpos < 90
{
diff := ypos-mousey
if diff between -30 and 100 ;left side block
{
bounce = 1
offset += 30
if sound
soundplay, %a_workingdir%\pong_board_bounce.wav
angle := 180-angle+rnd
}
}
if xpos < 30 ;left side goal
{
if sound
soundplay, %a_workingdir%\pong_goal.wav
points1++
GuiControl,, stats, %points0% : %points1%
guicontrol, move, ball, x%sw_2% y%sh_2%
bounce =0
if SW < 1300
offset := ball_speed-5
else
offset := ball_speed
KeyWait, LButton, D
goto start
}
if ypos > %lower_bounce% ;lower side
{
bounce = 1
offset += 30
if sound
soundplay, %a_workingdir%\pong_wall_bounce.wav
angle := 360-angle+rnd
}
if ypos < 0 ;upper side
{
bounce = 1
offset += 30
if sound
soundplay, %a_workingdir%\pong_wall_bounce.wav
angle := 360-angle+rnd
}
}
return
balance:
offset+= %ball_increasing_speed%
return
#IfWinActive, ahk_class AutoHotkeyGUI
s:: ;sound toggle
if sound
{
sound = 0
guicontrol, , vsound, Sound:%a_space%Off
}
else
{
sound = 1
guicontrol, , vsound, Sound:%a_space%On
}
return
#IfWinActive, ahk_class AutoHotkeyGUI ;help
F1::
gui, 1:-alwaysontop
gui, 2:margin, 15 ,15
gui, 2:destroy
gui, 2:font, s13
gui, 2:add, text, , Left Mouseclick to start the ball`nP for Pause`nStrg+x for exit`nS to toggle sound on/off
gui, 2:add, button, default yp+90 x100, Close
gui, 2:show, autosize, Help
return
2ButtonClose:
2guiclose:
2guiescape:
gui, 2:destroy
gui,1: +alwaysontop
return
#IfWinActive, ahk_class AutoHotkeyGUI ;pause
p::
gui, 1:-alwaysontop
DllCall("ShowCursor", UInt,True )
guicontrol, show, pause
settimer, mousemove, off
settimer, pcmove, off
settimer, balance, off
sleep, 200
KeyWait, P, D
gui, 1:+alwaysontop
DllCall("ShowCursor", UInt,false )
guicontrol, hide, pause
settimer, mousemove, on
settimer, pcmove, on
settimer, balance, on
return
#IfWinActive, ahk_class AutoHotkeyGUI ;exit
3guiclose:
guiclose:
^x::
DllCall("ShowCursor", UInt,True )
exitapp
return
|
Last edited by Lequi on Mon Sep 03, 2007 12:07 pm; edited 3 times in total |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10467
|
Posted: Sun Sep 02, 2007 3:11 am Post subject: |
|
|
| Although I can't easily assign a guest post to a registered user, I did edit the topmost post to refer to the new version of the script. If you prefer, I could split this topic so that your registered post becomes the topmost post of a new topic. |
|
| Back to top |
|
 |
Lequi
Joined: 31 Aug 2007 Posts: 29
|
Posted: Sun Sep 02, 2007 11:32 am Post subject: |
|
|
thats already perfect, thank you chris  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|