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.
Pong - the ultimate retro game
Started by
Lequi*
, Aug 31 2007 12:16 PM
17 replies to this topic
#1
-
Posted 31 August 2007 - 12:16 PM
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.
#2
-
Posted 31 August 2007 - 02:18 PM
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...
#3
-
Posted 31 August 2007 - 02:25 PM
HTH...
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
if SW < 1300 ;<--- sets the ball speed speed = 10 else speed = 15if 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
#4
-
Posted 31 August 2007 - 04:54 PM
Thanks! Guess I should have taken a look at you code comments...
#5
-
Posted 31 August 2007 - 05:48 PM
HTH...
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
#6
-
Posted 31 August 2007 - 06:02 PM
Impressive!
<!-- m -->https://ahknet.autoh...dex.php?act=reg<!-- m -->
i got no space where i could upload them
<!-- m -->https://ahknet.autoh...dex.php?act=reg<!-- m -->
#7
-
Posted 31 August 2007 - 06:24 PM
right click, save target as, dont change name and save the files where the pong file is
https://ahknet.autoh...oard_bounce.wav
https://ahknet.autoh...i/pong_goal.wav
https://ahknet.autoh...wall_bounce.wav
edit: any suggestions for further features or code improvements are welcome and another game is coming soon
a suggestion from me is to hide the mouse cursor, anyone knows how to manage that?
https://ahknet.autoh...oard_bounce.wav
https://ahknet.autoh...i/pong_goal.wav
https://ahknet.autoh...wall_bounce.wav
edit: any suggestions for further features or code improvements are welcome and another game is coming soon
a suggestion from me is to hide the mouse cursor, anyone knows how to manage that?
#8
-
Posted 31 August 2007 - 07:25 PM
right click, save target as, dont change name and save the files where the pong file is
https://ahknet.autoh...oard_bounce.wav
https://ahknet.autoh...i/pong_goal.wav
https://ahknet.autoh...wall_bounce.wav
edit: any suggestions for further features or code improvements are welcome
Add this to the top of the script:
SetWorkingDir, %A_ScriptDir% IfNotExist, pong_board_bounce.wav, UrlDownloadToFile , https://ahknet.autohotkey.com/~Lequi/pong_board_bounce.wav , pong_board_bounce.wav IfNotExist, pong_goal.wav, UrlDownloadToFile , https://ahknet.autohotkey.com/~Lequi/pong_goal.wav , pong_goal.wav IfNotExist, pong_wall_bounce.wav, UrlDownloadToFile , https://ahknet.autohotkey.com/~Lequi/pong_wall_bounce.wav , pong_wall_bounce.wav
#9
-
Posted 31 August 2007 - 08:09 PM
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
thx skan
edit: changed buttons to progress bar in order to change colors, looks a bit more retro
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
#10
-
Posted 31 August 2007 - 08:26 PM
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 )
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:
DllCall("ShowCursor", UInt,False ) Gui, Show, w400 h300, No Cursor Zone OnExit, QuitScript Return GuiClose: QuitScript: DllCall("ShowCursor", UInt,True ) ExitApp Return
#11
-
Posted 31 August 2007 - 08:33 PM
Heh, nice. The first thing I did after trying it - I added:
Gui, +LastFound WinSet, TransColor, Blackabove
gui, +toolwindow +alwaysontop8)
#12
-
Posted 01 September 2007 - 04:16 AM
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 )
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 )
;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 , https://ahknet.autohotkey.com/~Lequi/pong_board_bounce.wav , pong_board_bounce.wav IfNotExist, pong_goal.wav, UrlDownloadToFile , https://ahknet.autohotkey.com/~Lequi/pong_goal.wav , pong_goal.wav IfNotExist, pong_wall_bounce.wav, UrlDownloadToFile , https://ahknet.autohotkey.com/~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
#13
-
Posted 01 September 2007 - 10:04 AM
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.
#14
-
Posted 02 September 2007 - 02:11 AM