AutoHotkey Community

It is currently May 25th, 2012, 6:38 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: August 31st, 2007, 1:16 pm 
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.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 3:18 pm 
Offline

Joined: August 7th, 2007, 8:36 pm
Posts: 8
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 3:25 pm 
Offline

Joined: July 21st, 2006, 6:13 am
Posts: 558
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...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 5:54 pm 
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


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 6:48 pm 
Offline

Joined: July 21st, 2006, 6:13 am
Posts: 558
Thanks! Guess I should have taken a look at you code comments... :P

_________________

HTH...


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 7:02 pm 
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 :/


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 7:24 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Impressive! :D

Lequi wrote:
i got no space where i could upload them :/


http://www.autohotkey.net/file/index.php?act=reg

:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 8:25 pm 
Offline

Joined: August 31st, 2007, 8:22 pm
Posts: 29
right click, save target as, dont change name and save the files where the pong file is
http://www.autohotkey.net/~Lequi/pong_board_bounce.wav
http://www.autohotkey.net/~Lequi/pong_goal.wav
http://www.autohotkey.net/~Lequi/pong_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?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 9:09 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
Lequi wrote:
right click, save target as, dont change name and save the files where the pong file is
http://www.autohotkey.net/~Lequi/pong_board_bounce.wav
http://www.autohotkey.net/~Lequi/pong_goal.wav
http://www.autohotkey.net/~Lequi/pong_wall_bounce.wav

edit: any suggestions for further features or code improvements are welcome :)


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


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 9:26 pm 
Offline

Joined: August 31st, 2007, 8:22 pm
Posts: 29
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 August 31st, 2007, 9:33 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 31st, 2007, 9:33 pm 
Offline
User avatar

Joined: December 26th, 2005, 4:40 pm
Posts: 8775
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


:)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2007, 5:16 am 
Offline

Joined: October 17th, 2006, 4:15 pm
Posts: 7501
Location: Australia
Heh, nice. The first thing I did after trying it - I added:
Code:
Gui, +LastFound
WinSet, TransColor, Black
above
Code:
gui, +toolwindow +alwaysontop
8)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 1st, 2007, 11:04 am 
Offline

Joined: August 31st, 2007, 8:22 pm
Posts: 29
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 September 3rd, 2007, 12:07 pm, edited 3 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2007, 3:11 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
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.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 2nd, 2007, 11:32 am 
Offline

Joined: August 31st, 2007, 8:22 pm
Posts: 29
thats already perfect, thank you chris :)


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Rajat and 6 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