Page 1 of 1
Here are the most beautiful breakout of Century
Posted: Tue Feb 15, 2011 1:41 pm
by dobro
; Version Purebasic 4.00/4.51
; Prg réalisé par Dobro le 24/05/2005
debut:
Resultat = openconsole ()
enablegraphicalconsole (1)
consolecursor (0)
consoletitle ( " The most beautiful breakout of all time " )
;{; Preambule :
consolecolor (12,0 )
consolelocate (17,1)
print ( " The most beautiful breakout of all time " )
consolecolor (15,0 )
consolelocate (3,2)
print ( " This program requires a CORE14 to 108 GHz to run properly " )
consolecolor (14,0 )
consolelocate (22,5)
print ( " Your Score is: " + str ( point )+ " points" )
point =0
consolecolor (10,0 )
consolelocate (10,10)
print ( "pressed [space] to play" )
consolelocate (10,11)
print ( " then the key is pressed [space] to start the ball " )
consolelocate (10,12)
print ( " arrows direct the racket " )
consolecolor (15,0 )
consolelocate (1,25)
print ( " Program realized by Dobro in PureBasic v3.93 on a ZX81! " )
yy:
Chaine$ = inkey ()
Resultat = rawkey ()
If str (Resultat)<> "32" ;
Chaine$= ""
Goto yy
EndIf
;}
clearconsole ()
Chaine$= ""
xr=35
yr=20
ybal=19
xbal=35
sensy=-1
sensx=1
bord$= "bas"
Dim brique(60,15)
Dim couleur(15)
; initialise le tableau
For yb=5 To 15 Step 2
For xb=15 To 59 Step 2
brique(xb,yb)=1
Next xb
Next yb
; initialise les couleurs des briques
For coul=1 To 15
couleur(coul)= random (10)+5
Next coul
; **********************************
Gosub affiche
Repeat
; ********** position de la balle ****************************
Gosub position_balle
; ****************************************************************
delay (50)
;{; ************ le clavier ******************
Chaine$ = inkey ()
Resultat = rawkey ()
If str (Resultat)= "39" ; fleche droite
xr=xr+4 : If xr>58: xr=58: EndIf ; ceci determine le blocage de la raquette
EndIf
If str (Resultat)= "37" ; fleche gauche
xr=xr-4: If xr<4: xr=4: EndIf
EndIf
If str (Resultat)= "32" ; espace
start=1
EndIf
; ****************************************
;}
If start=1 ; la balle est lancé (gachette)
ybal=ybal+sensy
xbal=xbal+sensx
EndIf
;{ ; *************** collision bord ****************
If xbal >66 ; (touche bord droit)
Gosub position_balle
sensx=-sensx
bord$= "droit"
EndIf
If xbal <8 ; (touche bord gauche)
Gosub position_balle
sensx=-sensx
bord$= "gauche"
EndIf
If ybal >22 ; (touche bord bas)
Gosub position_balle
sensy=-sensy
bord$= "bas"
EndIf
If ybal <2 ; (touche bord haut)
Gosub position_balle
sensy=-sensy
bord$= "haut"
EndIf
; ******************************************
; ************ si collision entre ball et raquette ***********
If start=1
If ( xbal=xr+4 Or xbal=xr+5 Or xbal=xr+6 Or xbal=xr+7 ) And ybal=20
raquette=1
EndIf
If ( xbal=xr+3 Or xbal=xr+8 ) And ybal=20
raquette=2
EndIf
EndIf
; *****************************************************************
;}
Gosub affiche
ForEver
;{ ; AFFICHE
;- affiche
affiche:
; ClearConsole()
; ************* les briques *******************************
For yb=5 To 15 Step 2
For xb=15 To 59 Step 2
consolecolor (couleur(yb), 0)
consolelocate (xb,yb)
If ybal>20 ; partie perdu
Chaine$= ""
closeconsole ()
Goto debut
EndIf
; ************* si collision entre balle et brique *************
If (xbal=xb And ybal=yb) And start=1 And brique(xb,yb)=1
brique(xb,yb)=0 ; la brique disparait
point = point +10 ; le score
Gosub position_balle
If bord$= "gauche" Or bord$= "droit" :sensx=-sensx: EndIf
If bord$= "bas" Or bord$= "haut" : sensy=-sensy : EndIf
EndIf
; ****************************************************************
If raquette=1
raquette=0
sensy=-sensy
EndIf
If raquette=2
raquette=0
sensy=-sensy
sensx=-sensx
EndIf
If brique(xb,yb)=1
print ( "=" )
Else
print ( " " )
EndIf
Next xb
Next yb
; **************************************************
; ********* affiche la raquette **********************
consolelocate (xr,yr) ; position la raquette
consolecolor (15, 0)
print ( chr (32)+ " ===== " + chr (32)) ; la raquette
consolelocate (0,yr-1)
print ( space (66)) ; efface les résidus
consolelocate (0,yr+1)
print ( space (66)) ; efface les résidus
; ****************************************************
; ************** les bords *******************
For y=0 To 24
consolelocate (7,y)
print ( "|" )
consolelocate (67,y)
print ( "|" )
Next y
For x=0 To 79
consolelocate (x,1)
print ( "-" )
consolelocate (x,23)
print ( "-" )
Next x
; ********** LE SCORE ********************
consolelocate (70,3)
consolecolor (11, 0)
print ( "points" )
consolelocate (72,4)
consolecolor (11, 0)
print ( str ( point ))
; *********************************************
Return
;}
;{;POSITION BALLE
position_balle:
If sensy<0 And sensx>0 ; va a droite ; ça monte
consolecolor (14, 0)
consolelocate (xbal,ybal) ; position la balle
print ( "o" ) ; la balle
consolelocate (xbal-1,ybal+1) ; position la balle
print ( " " ) ; la balle
Goto su2
EndIf
If sensy<0 And sensx<0 ; va a gauche ; ça monte
consolecolor (14, 0)
consolelocate (xbal,ybal) ; position la balle
print ( "o" ) ; la balle
consolelocate (xbal+1,ybal+1) ; position la balle
print ( " " ) ; la balle
Goto su2
EndIf
If sensy>0 And sensx>0 ; va a droite ça descend
consolecolor (14, 0)
consolelocate (xbal,ybal) ; position la balle
print ( "o" ) ; la balle
consolelocate (xbal-1,ybal-1) ; position la balle
print ( " " ) ; la balle
Goto su2
EndIf
If sensy>0 And sensx<0 ; va a gauche ça descend
consolecolor (14, 0)
consolelocate (xbal,ybal) ; position la balle
print ( "o" ) ; la balle
consolelocate (xbal+1,ybal-1) ; position la balle
print ( " " ) ; la balle
Goto su2
EndIf
su2:
Return
;}
Re: Here are the most beautiful breakout of Century
Posted: Tue Feb 15, 2011 3:35 pm
by rsts
Nice, but since I'm not a gamer, it needs an "easy" mode.
cheers
Re: Here are the most beautiful breakout of Century
Posted: Wed Feb 16, 2011 1:47 am
by Demivec
My hiscore and the end of my patience reached at 330 points!

Re: Here are the most beautiful breakout of Century
Posted: Wed Feb 16, 2011 10:28 am
by dobro
Demivec wrote:My hiscore and the end of my patience reached at 330 points!


Cool !

Re: Here are the most beautiful breakout of Century
Posted: Thu Feb 17, 2011 6:45 am
by Frarth
The racket does not go as smoothly as the ball, which makes it hard to keep the ball up. Two times I reached 440 points and that is as far as I will go.
Nice code though. Thankx for sharing!
Re: Here are the most beautiful breakout of Century
Posted: Thu Feb 17, 2011 2:26 pm
by Foz
Nice, but here's a version where you don't have to guess the location of the bat
Code: Select all
; Version Purebasic 4.00/4.51
; Prg réalisé par Dobro le 24/05/2005
Resultat = OpenConsole ()
EnableGraphicalConsole (1)
debut:
ClearConsole()
ConsoleCursor (0)
ConsoleTitle ( " The most beautiful breakout of all time " )
;{; Preambule :
ConsoleColor (12,0 )
ConsoleLocate (17,1)
Print ( " The most beautiful breakout of all time " )
ConsoleColor (15,0 )
ConsoleLocate (3,2)
Print ( " This program requires a CORE14 to 108 GHz to run properly " )
ConsoleColor (14,0 )
ConsoleLocate (22,5)
Print ( " Your Score is: " + Str ( point )+ " points" )
point =0
ConsoleColor (10,0 )
ConsoleLocate (10,10)
Print ( "pressed [space] to play" )
ConsoleLocate (10,11)
Print ( " then the key is pressed [space] to start the ball " )
ConsoleLocate (10,12)
Print ( " arrows direct the racket " )
ConsoleColor (15,0 )
ConsoleLocate (1,25)
Print ( " Program realized by Dobro in PureBasic v3.93 on a ZX81! " )
yy:
Chaine$ = Inkey ()
Resultat = RawKey ()
If Str (Resultat)<> "32" ;
Chaine$= ""
Goto yy
EndIf
;CloseConsole ()
;}
ClearConsole ()
Chaine$= ""
xr=35
yr=20
ybal=19
xbal=35
sensy=-1
sensx=1
bord$= "bas"
Dim brique(60,15)
Dim couleur(15)
; initialise le tableau
For yb=5 To 15 Step 2
For xb=15 To 59 Step 2
brique(xb,yb)=1
Next xb
Next yb
; initialise les couleurs des briques
For coul=1 To 15
couleur(coul)= Random (10)+5
Next coul
; **********************************
Gosub affiche
Repeat
; ********** position de la balle ****************************
Gosub position_balle
; ****************************************************************
Delay (50)
;{; ************ le clavier ******************
Chaine$ = Inkey ()
Resultat = RawKey ()
If Str (Resultat)= "39" ; fleche droite
xr=xr+4 : If xr>58: xr=58: EndIf ; ceci determine le blocage de la raquette
EndIf
If Str (Resultat)= "37" ; fleche gauche
xr=xr-4: If xr<4: xr=4: EndIf
EndIf
If Str (Resultat)= "32" ; espace
start=1
EndIf
; ****************************************
;}
If start=1 ; la balle est lancé (gachette)
ybal=ybal+sensy
xbal=xbal+sensx
EndIf
;{ ; *************** collision bord ****************
If xbal >66 ; (touche bord droit)
Gosub position_balle
sensx=-sensx
bord$= "droit"
EndIf
If xbal <8 ; (touche bord gauche)
Gosub position_balle
sensx=-sensx
bord$= "gauche"
EndIf
If ybal >22 ; (touche bord bas)
Gosub position_balle
sensy=-sensy
bord$= "bas"
EndIf
If ybal <2 ; (touche bord haut)
Gosub position_balle
sensy=-sensy
bord$= "haut"
EndIf
; ******************************************
; ************ si collision entre ball et raquette ***********
If start=1
If ( xbal=xr+4 Or xbal=xr+5 Or xbal=xr+6 Or xbal=xr+7 ) And ybal=20
raquette=1
EndIf
If ( xbal=xr+3 Or xbal=xr+8 ) And ybal=20
raquette=2
EndIf
EndIf
; *****************************************************************
;}
Gosub affiche
ForEver
;{ ; AFFICHE
;- affiche
affiche:
; ClearConsole()
; ************* les briques *******************************
For yb=5 To 15 Step 2
For xb=15 To 59 Step 2
ConsoleColor (couleur(yb), 0)
ConsoleLocate (xb,yb)
If ybal>20 ; partie perdu
Chaine$= ""
Goto debut
EndIf
; ************* si collision entre balle et brique *************
If (xbal=xb And ybal=yb) And start=1 And brique(xb,yb)=1
brique(xb,yb)=0 ; la brique disparait
point = point +10 ; le score
Gosub position_balle
If bord$= "gauche" Or bord$= "droit" :sensx=-sensx: EndIf
If bord$= "bas" Or bord$= "haut" : sensy=-sensy : EndIf
EndIf
; ****************************************************************
If raquette=1
raquette=0
sensy=-sensy
EndIf
If raquette=2
raquette=0
sensy=-sensy
sensx=-sensx
EndIf
If brique(xb,yb)=1
Print ( "=" )
Else
Print ( " " )
EndIf
Next xb
Next yb
; **************************************************
; ********* affiche la raquette **********************
ConsoleLocate (xr,yr) ; position la raquette
ConsoleColor (15, 0)
Print ( Chr (32)+ " ===== " + Chr (32)) ; la raquette
ConsoleLocate (0,yr-1)
Print ( Space (66)) ; efface les résidus
ConsoleLocate (0,yr+1)
Print ( Space (66)) ; efface les résidus
; ****************************************************
; ************** les bords *******************
For y=0 To 24
ConsoleLocate (7,y)
Print ( "|" )
ConsoleLocate (67,y)
Print ( "|" )
Next y
For x=0 To 79
ConsoleLocate (x,1)
Print ( "-" )
ConsoleLocate (x,23)
Print ( "-" )
Next x
; ********** LE SCORE ********************
ConsoleLocate (70,3)
ConsoleColor (11, 0)
Print ( "points" )
ConsoleLocate (72,4)
ConsoleColor (11, 0)
Print ( Str ( point ))
; *********************************************
Return
;}
;{;POSITION BALLE
position_balle:
If sensy<0 And sensx>0 ; va a droite ; ça monte
ConsoleColor (14, 0)
ConsoleLocate (xbal,ybal) ; position la balle
Print ( "o" ) ; la balle
ConsoleLocate (xbal-1,ybal+1) ; position la balle
Print ( " " ) ; la balle
Goto su2
EndIf
If sensy<0 And sensx<0 ; va a gauche ; ça monte
ConsoleColor (14, 0)
ConsoleLocate (xbal,ybal) ; position la balle
Print ( "o" ) ; la balle
ConsoleLocate (xbal+1,ybal+1) ; position la balle
Print ( " " ) ; la balle
Goto su2
EndIf
If sensy>0 And sensx>0 ; va a droite ça descend
ConsoleColor (14, 0)
ConsoleLocate (xbal,ybal) ; position la balle
Print ( "o" ) ; la balle
ConsoleLocate (xbal-1,ybal-1) ; position la balle
Print ( " " ) ; la balle
Goto su2
EndIf
If sensy>0 And sensx<0 ; va a gauche ça descend
ConsoleColor (14, 0)
ConsoleLocate (xbal,ybal) ; position la balle
Print ( "o" ) ; la balle
ConsoleLocate (xbal+1,ybal-1) ; position la balle
Print ( " " ) ; la balle
Goto su2
EndIf
su2:
Return
;}
Re: Here are the most beautiful breakout of Century
Posted: Thu Feb 17, 2011 3:02 pm
by dobro
your version bug in my house !!
no collision with raquette and ball to the down-left of screen

Re: Here are the most beautiful breakout of Century
Posted: Thu Feb 17, 2011 4:12 pm
by Foz
Sheesh, no pleasing some people!
I've updated my code accordingly...
Re: Here are the most beautiful breakout of Century
Posted: Thu Feb 17, 2011 4:25 pm
by dobro
Thanks
