Here's my very first entry in the 20-liner challenge, it's a retro-style clone of the original pong game.
It's VERY simple, there is no end, you just keep scoring and scoring and scoring and scoring... well you get the picture
Anyways, I coded this in about 1 hour, and I think it turned out quite well.
Please, comment.
DarkBASIC Professional Source
Sync On: Sync Rate 60: Set Text Font "Arial Black": Set Text To Bold: Set Text Size 24
#Constant CBALLSIZE = 16: #Constant CPADDLEWIDTH = 16: #Constant CPADDLEHEIGHT = 64: #Constant CBALLSPEED = 1
Global BallX#: Global BallY#: Global BallDX#: Global BallDY#: Global P1X#: Global P1Y#: Global P2X#: Global P2Y#: Global P1Score: Global P2Score: Global Score$
BallX# = (Screen Width( ) / 2) - (CBALLSIZE / 2): BallY# = (Screen Height( ) / 2) - (CBALLSIZE / 2): BallDX# = CBALLSPEED: BallDY# = CBALLSPEED
P1X# = 10: P1Y# = (Screen Height( ) / 2) - (CPADDLEHEIGHT / 2): P2X# = (Screen Width( ) - (CPADDLEWIDTH + 10)): P2Y# = P1Y#
Repeat: Cls Rgb(0, 0, 0)
If (UpKey( )): Dec P1Y#: EndIf: If (DownKey( )): Inc P1Y#: EndIf
If (BallY# < P2Y#): Dec P2Y#: EndIf: If (BallY# > (P2Y# + CPADDLEHEIGHT)): Inc P2Y#: EndIf
BallX# = (BallX# + BallDX#): BallY# = (BallY# + BallDY#)
If (BallY# < 0): BallDY# = -BallDY#: EndIf: If (BallY# > (Screen Height( ) - CBALLSIZE)): BallDY# = -BallDY#: EndIf: If (BallX# < 0): Inc P2Score: BallX# = (Screen Width( ) / 2) - (CBALLSIZE / 2): BallY# = (Screen Height( ) / 2) - (CBALLSIZE / 2): EndIf
If (BallX# > (Screen Width( ) - CBALLSIZE)): Inc P1Score: BallX# = (Screen Width( ) / 2) - (CBALLSIZE / 2): BallY# = (Screen Height( ) / 2) - (CBALLSIZE / 2): EndIf
If (P1Y# < 0): P1Y# = 0: EndIf: If (P1Y# > (Screen Height( ) - CPADDLEHEIGHT)): P1Y# = (Screen Height( ) - CPADDLEHEIGHT): EndIf: If (P2Y# < 0): P2Y# = 0: EndIf: If (P2Y# > (Screen Height( ) - CPADDLEHEIGHT)): P2Y# = (Screen Height( ) - CPADDLEHEIGHT): EndIf
If (InArea#(BallX#, BallY#, P1X#, P1Y#, CPADDLEWIDTH, CPADDLEHEIGHT) = 1): BallDX# = -BallDX#: BallDY# = -BallDY#: EndIf: If (InArea#((BallX# + CBALLSIZE), (BallY# + CBALLSIZE), P2X#, P2Y#, CPADDLEWIDTH, CPADDLEHEIGHT) = 1): BallDX# = -BallDX#: BallDY# = -BallDY#: EndIf
Box P1X#, P1Y#, (P1X# + CPADDLEWIDTH), (P1Y# + CPADDLEHEIGHT): Box P2X#, P2Y#, (P2X# + CPADDLEWIDTH), (P2Y# + CPADDLEHEIGHT): Box BallX#, BallY#, (BallX# + CBALLSIZE), (BallY# + CBALLSIZE)
Score$ = Str$(P1Score) + " : " + Str$(P2Score): Text (Screen Width( ) / 2) - (Text Width(Score$) / 2), 0, Score$
Sync
Until (EscapeKey( ))
Function InArea#(X#, Y#, X1#, Y1#, Width#, Height#): If (X# >= X1#) And (X# <= (X1# + Width#)): If (Y# >= Y1#) And (Y# <= (Y1# + Height#)): ExitFunction 1.0: EndIf: Else: ExitFunction 0.0: EndIf: EndFunction Ret#
RemStart
Function InArea#(X#, Y#, X1#, Y1#, Width#, Height#)
If (X# >= X1#) And (X# <= (X1# + Width#))
If (Y# >= Y1#) And (Y# <= (Y1# + Height#))
ExitFunction 1.0
EndIf
Else
ExitFunction 0.0
EndIf
EndFunction Ret#
RemEnd
18 lines total.
[img "http://www.dslreports.com/im/24426383/507.png"]