Press Enter to start
Press Esc to end
Up and down arrow keys
A and Z keys
All else should be obvious... or remembered if you're over 45.
Happy holidays!
Code: Select all
//Get approximate computer speed to set paddle speed and ball speed
Timer>CSStart
Let>CStest=0
Repeat>CStest
Add>CStest,1
Until>CStest=10000
Timer>CSEnd
Let>PaddleSpeed={round(1/((%CSEnd%-%CSStart%)/10000))}
Let>AbsoluteBallSpeed={%PaddleSpeed%/15}
Let>BallXSpeed=AbsoluteBallSpeed
Let>BallYSpeed=0
Let>OverallBallSpeed=1
Let>MoveBallFlag=1
Let>NoCollideFlag=0
If>RPaddle={"RPaddle"}
Else
Macro>%Temp_Dir%RightPaddle.scp
EndIf
If>LPaddle={"LPaddle"}
Else
Macro>%Temp_Dir%LeftPaddle.scp
EndIf
//Press Esc key to quit
OnEvent>Key_down,VK27,0,Quit
//Press enter key to launch the ball
OnEvent>Key_down,VK13,0,Start
//Press CTRL + right arrow key to reset game
OnEvent>Key_Down,VK39,2,ResetGame
DeleteFile>%Temp_Dir%LeftPaddle.scp
DeleteFile>%Temp_Dir%RightPaddle.scp
Dialog>Dialog1
object Dialog1: TForm
Left = 533
Top = 101
Cursor = -1
HelpContext = 5000
BorderIcons = [biSystemMenu]
BorderStyle = bsNone
Caption = 'Ping'
ClientHeight = 330
ClientWidth = 779
Color = clBlack
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = True
Position = poScreenCenter
ShowHint = True
OnTaskBar = False
PixelsPerInch = 96
TextHeight = 13
object Label1: TLabel
Left = 338
Top = 8
Width = 32
Height = 13
Caption = '00'
end
object Label2: TLabel
Left = 410
Top = 8
Width = 32
Height = 13
Caption = '00'
end
object Panel1: TPanel
Left = 47
Top = 101
Width = 20
Height = 20
Cursor = -1
Color = clWhite
DragKind = dkDock
DragMode = dmAutomatic
ParentBackground = False
TabOrder = 0
end
object Panel2: TPanel
Left = 0
Top = 0
Width = 20
Height = 80
Cursor = -1
Color = clWhite
DockSite = True
DoubleBuffered = True
ParentBackground = False
ParentDoubleBuffered = False
TabOrder = 1
end
object Panel3: TPanel
Left = 168
Top = 0
Width = 20
Height = 80
Cursor = -1
Color = clWhite
DockSite = True
DoubleBuffered = True
ParentBackground = False
ParentDoubleBuffered = False
TabOrder = 2
end
object Panel4: TPanel
Left = 397
Top = 0
Width = 6
Height = 600
Cursor = -1
Color = clWhite
ParentBackground = False
TabOrder = 3
end
end
EndDialog>Dialog1
Dialog>Dialog2
object Dialog2: TForm
BorderIcons = []
Caption = 'Reset'
ClientHeight = 100
ClientWidth = 800
Position = poScreenCenter
object Panel1: TPanel
Left = 0
Top = 0
Width = 800
Height = 100
Caption = 'Press "Ctrl" + "Right Arrow" key to reset game and play again or "Esc" to quit.'
ParentBackground = False
ParentFont = False
TabOrder = 0
end
end
EndDialog>Dialog2
Let>ScreenW=800
Let>ScreenH=600
SetDialogProperty>Dialog1,,ClientWidth,ScreenW
SetDialogProperty>Dialog1,,ClientHeight,ScreenH
SetDialogProperty>Dialog1,Panel3,Left,{%ScreenW%-20}
SetDialogProperty>Dialog1,Panel2,Top,{(%ScreenH%/2)-40}
SetDialogProperty>Dialog1,Panel3,Top,{(%ScreenH%/2)-40}
SetDialogObjectFont>Dialog1,Label1,Courier,30,1,16777215
SetDialogObjectFont>Dialog1,Label2,Courier,30,1,16777215
SetDialogObjectFont>Dialog2,Panel1,Courier,12,1,111111
show>dialog1
LabelToVar>LeftPaddle,LeftData
LabelToVar>RightPaddle,RightData
WriteLn>%Temp_Dir%LeftPaddle.scp,wres,LeftData
WriteLn>%Temp_Dir%RightPaddle.scp,wres,RightData
StringReplace>Command_Line,",,Command_Line
ExtractFileName>Command_Line,ProcessName
LowerCase>ProcessName,ProcessName
Trim>ProcessName,ProcessName
If>ProcessName={"msched.exe"}
ExecuteFile>%Temp_Dir%RightPaddle.scp
ExecuteFile>%Temp_Dir%LeftPaddle.scp
Else
ExtractFileExt>ProcessName,ProcessExt
If>ProcessExt={".scp"}
ExecuteFile>%Temp_Dir%RightPaddle.scp
ExecuteFile>%Temp_Dir%LeftPaddle.scp
Else
Let>RP_Wait=0
Let>RP_Windowmode=0
RunProgram>"%Command_Line%" "/RPaddle=%Temp_Dir%RightPaddle.scp"
RunProgram>"%Command_Line%" "/LPaddle=%Temp_Dir%LeftPaddle.scp"
EndIf
EndIf
Let>WIN_USEHANDLE=1
GetWindowPos>%Dialog1.Handle%,DialogX,DialogY
MoveWindow>%Dialog1.Panel1.Handle%,390,290
Let>WIN_USEHANDLE=0
SRT>Start
If>MoveBallFlag=1
Let>MoveBallFlag=0
GetDialogProperty>Dialog1,Panel1,Top,BallY
GetDialogProperty>Dialog1,Panel1,Left,BallX
Random>4,BallDirection
If>BallDirection=0
//Do nothing
EndIf
If>BallDirection=1
Let>BallXSpeed=%BallXSpeed%*-1
EndIf
If>BallDirection=2
Let>BallYSpeed=-0.1
EndIf
If>BallDirection=3
Let>BallXSpeed=%BallXSpeed%*-1
Let>BallYSpeed=-0.1
EndIf
EndIf
END>Start
Timer>StartTime
Label>Loop
If>MoveBallFlag=0
Gosub>Ball
EndIf
//Wait>0.01
Goto>Loop
SRT>Collided
GetDialogProperty>Dialog1,Panel1,Top,CurY
GetDialogProperty>Dialog1,Panel1,Left,CurX
GetDialogProperty>Dialog1,Panel%Collided_var_1%,Top,PaddlePanelY
If>{((%CurY%-%PaddlePanelY%)>70)and((%CurY%-%PaddlePanelY%)<81)}
Let>BallYSpeed={abs(0.5*%OverallBallSpeed%)}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>60)and((%CurY%-%PaddlePanelY%)<71)}
Let>BallYSpeed={abs(0.4*%OverallBallSpeed%)}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>50)and((%CurY%-%PaddlePanelY%)<61)}
Let>BallYSpeed={abs(0.3*%OverallBallSpeed%)}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>40)and((%CurY%-%PaddlePanelY%)<51)}
Let>BallYSpeed={abs(0.2*%OverallBallSpeed%)}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>30)and((%CurY%-%PaddlePanelY%)<41)}
Let>BallYSpeed={abs(0.1*%OverallBallSpeed%)}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>20)and((%CurY%-%PaddlePanelY%)<31)}
Let>BallYSpeed={abs(0*%OverallBallSpeed%)}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>10)and((%CurY%-%PaddlePanelY%)<21)}
Let>BallYSpeed={(abs(0.1*%OverallBallSpeed%))*-1}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>0)and((%CurY%-%PaddlePanelY%)<11)}
Let>BallYSpeed={(abs(0.2*%OverallBallSpeed%))*-1}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>-11)and((%CurY%-%PaddlePanelY%)<1)}
Let>BallYSpeed={(abs(0.3*%OverallBallSpeed%))*-1}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>-21)and((%CurY%-%PaddlePanelY%)<-9)}
Let>BallYSpeed={(abs(0.4*%OverallBallSpeed%))*-1}
Goto>EndCollided
EndIf
If>{((%CurY%-%PaddlePanelY%)>-31)and((%CurY%-%PaddlePanelY%)<-19)}
Let>BallYSpeed={(abs(0.5*%OverallBallSpeed%))*-1}
Goto>EndCollided
EndIf
Let>NoCollideFlag=1
Goto>NoCollide
Label>EndCollided
RegistryReadKey>HKEY_LOCAL_MACHINE,SYSTEM\ControlSet001\Control\Class\{4D36E96C-E325-11CE-BFC1-08002BE10318}\0005\Settings\filter\rear,MasterMute,res
If>res=00
LibFunc>kernel32,Beep,r,1000,50
EndIf
If>BallXSpeed>0
Let>BallXSpeed={%AbsoluteBallSpeed%*-1*%OverallBallSpeed%}
Else
Let>BallXSpeed={%AbsoluteBallSpeed%*%OverallBallSpeed%}
EndIf
Timer>EndTime
If>{(%EndTime%-%StartTime%)>5000}
Let>OverallBallSpeed=%OverallBallSpeed%*1.1
Timer>StartTime
EndIf
Label>NoCollide
END>Collided
SRT>Quit
CloseDialog>Dialog2
Exit>0
END>Quit
SRT>Ball
Let>WIN_USEHANDLE=1
Let>BallX={%BallX%+%BallXSpeed%}
Let>BallXPos={round(%BallX%)}
Let>BallY={%BallY%+%BallYSpeed%}
Let>BallYPos={round(%BallY%)}
SetDialogProperty>Dialog1,Panel1,Top,BallYPos
SetDialogProperty>Dialog1,Panel1,Left,BallXPos
If>{%BallX%<10}
Let>BallXSpeed=%BallXSpeed%*-1
EndIf
//Bounce off the side walls
If>{(%BallY%>(%ScreenH%-20))or(%BallY%<0)}
Let>BallYSpeed=%BallYSpeed%*-1
EndIf
//We're at the limits is there a paddle waiting?
If>{(%BallX%>(%ScreenW%-39))}
GoSub>Collided,3
EndIf
If>{%BallX%<19}
GoSub>Collided,2
EndIf
If>NoCollideFlag=1
Let>NoCollideFlag=0
Let>MoveBallFlag=1
SetDialogProperty>Dialog1,Panel1,Top,290
SetDialogProperty>Dialog1,Panel1,Left,390
If>BallX>400
GetDialogProperty>Dialog1,Label1,Caption,Score
Add>Score,1
VBEval>right("00"&"%Score%",2),Score
If>%Score%>10
SetDialogProperty>Dialog1,Label1,Left,220
SetDialogProperty>Dialog1,Label1,Caption, %Score%%crlf%Winner!
Wait>2
Show>Dialog2,
Else
SetDialogProperty>Dialog1,Label1,Caption,Score
EndIf
Else
GetDialogProperty>Dialog1,Label2,Caption,Score
Add>Score,1
VBEval>right("00"&"%Score%",2),Score
If>%Score%>10
SetDialogProperty>Dialog1,Label2,Caption, %Score%%crlf%Winner!
Wait>2
Show>Dialog2,
Else
SetDialogProperty>Dialog1,Label2,Caption,Score
EndIf
EndIf
LibFunc>kernel32,Beep,r,200,700
Let>MoveBallFlag=1
Let>BallXSpeed=AbsoluteBallSpeed
Let>BallYSpeed=0
Let>OverallBallSpeed=1
EndIf
Let>WIN_USEHANDLE=0
END>Ball
SRT>ResetGame
SetDialogProperty>Dialog1,Label1,Left,338
SetDialogProperty>Dialog1,Label1,Caption,00
SetDialogProperty>Dialog1,Label2,Caption,00
CloseDialog>Dialog2
END>ResetGame
//We need separate scripts for paddle movement so they can be independent.
/*
LeftPaddle:
//Exit>0
OnEvent>Key_Down,VK90,0,LDown
OnEvent>Key_Down,VK65,0,LUp
Let>WIN_USEHANDLE=1
Timer>LastUpMove
Timer>LastDownMove
Let>Msg_Ypos=10
Let>kk=0
GetWindowPos>%Dialog1.Handle%,DialogX,DialogY
GetWindowSize>%Dialog1.Handle%,DialogW,DialogH
SRT>LUp
Timer>NextMove
Add>kk,1
If>{(%NextMove%-%LastUpMove%)>%PaddleSpeed%}
GetWindowPos>%Dialog1.Panel2.Handle%,WinX,Location
Let>Location={round(%Location%-%DialogY%-10)}
Let>WinX=%WinX%-%DialogX%
Timer>LastUpMove
EndIf
If>Location>0
MoveWindow>%Dialog1.Panel2.Handle%,WinX,Location
EndIf
END>LUp
SRT>LDown
Timer>NextMove
If>{(%NextMove%-%LastDownMove%)>%PaddleSpeed%}
GetWindowPos>%Dialog1.Panel2.Handle%,WinX,Location
Let>Location={round(%Location%-%DialogY%+10)}
Let>WinX=%WinX%-%DialogX%
Timer>LastDownMove
EndIf
If>Location<520
MoveWindow>%Dialog1.Panel2.Handle%,WinX,Location
EndIf
END>LDown
Label>Loop
IfWindowOpen>%Dialog1.handle%
Else
Exit>0
EndIf
Wait>0.01
Goto>Loop
*/
/*
RightPaddle:
//Exit>0
OnEvent>Key_Down,VK40,0,RDown
OnEvent>Key_Down,VK38,0,RUp
Timer>LastUpMove
Timer>LastDownMove
Let>WIN_USEHANDLE=1
GetWindowPos>%Dialog1.Handle%,DialogX,DialogY
GetWindowSize>%Dialog1.Handle%,DialogW,DialogH
SRT>RUp
Timer>NextMove
If>{(%NextMove%-%LastUpMove%)>%PaddleSpeed%}
GetWindowPos>%Dialog1.Panel3.Handle%,WinX,Location
Let>Location={round(%Location%-%DialogY%-10)}
Let>WinX=%WinX%-%DialogX%
Timer>LastUpMove
EndIf
If>Location>0
MoveWindow>%Dialog1.Panel3.Handle%,WinX,Location
EndIf
END>RUp
SRT>RDown
Timer>NextMove
If>{(%NextMove%-%LastDownMove%)>%PaddleSpeed%}
GetWindowPos>%Dialog1.Panel3.Handle%,WinX,Location
Let>Location={round(%Location%-%DialogY%+10)}
Let>WinX=%WinX%-%DialogX%
Timer>LastDownMove
EndIf
If>Location<520
MoveWindow>%Dialog1.Panel3.Handle%,WinX,Location
EndIf
END>RDown
Label>Loop
IfWindowOpen>%Dialog1.handle%
Else
Exit>0
EndIf
Wait>0.01
Goto>Loop
*/