## Simple breakout in Hollywood

The place for any Hollywood tutorials
Posts: 437
Joined: Mon Nov 01, 2010 10:37 am
Location: Albert - France
Contact:

### Simple breakout in Hollywood

Hello,

I post this small code, good fun...

Code: Select all

``````@VERSION 4,0
@DISPLAY{WIDTH=320,HEIGHT=256}
CreateBrush(1,8,8,#GREEN)
CreateBrush(2,4,4,#RED)
CreateBrush(3,40,8,#BLUE)
CreateBrush(4,2,2,#WHITE)
CreateBrush(5,40,2,#WHITE)
CreateBrush(6,1,8,#WHITE)
CreateBrush(7,8,1,#WHITE)
MixBrush(1,6,128)
MixBrush(1,7,128)
MixBrush(2,4,128)
MixBrush(3,5,128)
Local XBarre=0
Local XBall=0
Local YBall=128
Local Vie=3
Local Score=0
Local XSens=1
Local YSens=-1
Local Renvoie=False
Local Casse=False
/*Attention, Tableau, le premier chiffre est la coordonnée X des briques*/
/*Le Deuxième Chiffre ET le Numéro de Brush, 1 étant la Brush Brique*/
LIGNE={}
LIGNE={0,1,8,1,16,1,24,1,32,1,40,1,48,1,56,1,64,1,72,1,80,1,88,1,96,1,104,1,112,1,
120,1,128,1,136,1,144,1,152,1,160,1,168,1,176,1,184,1,192,1,200,1,208,1,216,1,224,
1,232,1,240,1,248,1,256,1,264,1,272,1,280,1,288,1,296,1,304,1,312,1,320,1}
Function Ball()
XBall=XBall+XSens
YBall=Yball+YSens
If XBall=312 Then XSens=-1
If XBall=0 Then XSens=1
If YBall=10 Then YSens=1
Renvoie=Collision(#BRUSH,3,XBarre,248,2,XBall,YBall)
For x=1 To 81 Step 2
If ligne[x]<>1 Then ligne[x-1]=-50
Casse=Collision(#BRUSH,2,XBall,yball,1,Ligne[x-1],20)
If Casse=True
Ysens=1
Ligne[x]=4
Score=Score+10
EndIf
Next
If Renvoie=True Then Ysens=-1
If YBall=256
Ysens=-1
Vie=Vie-1
EndIf
DisplayBrush(2,XBall,Yball)
EndFunction

Function Ecran()
For x=1 To 81 Step 2
DisplayBrush(Ligne[x],Ligne[x-1],20)
Next
TextOut(0,0,"Score : ")
TextOut(80,0,Score)
TextOut(260,0,"Vie : ")
TextOut(310,0,Vie)
EndFunction
``````
Respect

mjnurney
Posts: 8
Joined: Sun Nov 29, 2015 10:41 pm

### Re: Simple breakout in Hollywood

Excellent

fjudde
Posts: 20
Joined: Tue Dec 01, 2015 2:59 pm
Location: Stockholm, Sweden

### Re: Simple breakout in Hollywood

I post this small code, good fun...
Can't get it to run? Is all the code attached? seems something is missing?
_____________________________________
Hollywood 6.1

Figgy78
Posts: 32
Joined: Wed Oct 11, 2017 9:13 am

### Re: Simple breakout in Hollywood

As ArtBlink seems to have vanished, I thought I would give it a go and finish his code as an exercise.

I changed a few things:
- Translated everything to English from French (Thank you Google).
- Doubled the width of the bricks.
- Added a way to end the game and start over
- Added a variable for ball speed.

I might add some more fun stuff to this, but for now, this will have to do.

If you have any suggestions on how to improve my code, please don't hesitate to shout it out.
Enjoy!

Code: Select all

``````/****************************************************************
**                                                             **
** Name:        Simple Breakout                                **
** Author:      ArtBlink & Figgy/CtZ                           **
** Version:     1.1                                            **
** Date:        01.29.2019                                     **
** Interpreter: Hollywood 7.1                                  **
** Function:    Simple Breakout clone tutorial game            **
**                                                             **
** History:                                                    **
**                                                             **
** 1.1: (01.29.2019)                                             **
** - Made playable by Figgy/CtZ                                **
**                                                             **
** 1.0: (11.10.10)                                             **
** - Unfinished game posted on Hollywood-mal forums            **
**                                                             **
****************************************************************/
@VERSION 7,0
@DISPLAY{WIDTH = 320, HEIGHT = 256, MODE = "WINDOWED"}
CreateBrush(1,16,8,#GREEN)  ; BRICK
CreateBrush(2,4,4, #RED)   ; BALL
CreateBrush(3,40,8,#BLUE)  ; BUMPER
CreateBrush(4,2,2,#WHITE)  ; Ball highlight
CreateBrush(5,40,2,#WHITE) ; Bumper Highlight
CreateBrush(6,1,8,#WHITE)  ; Brick highlight, left side
CreateBrush(7,15,1,#WHITE)  ; BRick highlight, top
MixBrush(1,6,128) ; Add left highlight to brick
MixBrush(1,7,128) ; Add top highlight to brick
MixBrush(2,4,128) ; Add highlight to ball
MixBrush(3,5,128) ; Add highlight to Bumper

Function p_GameOver()
Repeat
Cls
TextOut (120, 128, "GAME OVER!")
TextOut (112, 144, "PLAY AGAIN ?")
If IsKeyDown("y") = True Or IsKeyDown("Y") = True
p_NewGame()
Break
ElseIf IsKeyDown("n") = True Or IsKeyDown("N") = True
End
EndIf

Flip
Forever
EndFunction

Function p_NewGame()
; Reset variables
XBall = 0
YBall = 128
Lives = 3
Score = 0
BallSpeed = 2
MoveX = BallSpeed
MoveY = -BallSpeed
BumperHit = False
BumperSpeed = 3
BumperXPos = 140
BrickHit = False

/* Attention: The first digit is the X coordinate of the bricks.*/
/* The second digit is the brush number, brush 1 being the brick */
Lines = {0,1,16,1,32,1,48,1,64,1,80,1,96,1,112,1,128,1,144,1,160,1,176,1,192,1,208,1,224,1,240,1,256,1,272,1,288,1,304,1,320,1}
EndFunction

For x = 1 to 41 Step 2
DisplayBrush(Lines[x], Lines[x - 1], 20)
Next

TextOut (8, 8, "Score : ")
TextOut (88, 8, Score)
TextOut (252, 8, "Lives : ")
TextOut (302, 8, Lives)
EndFunction

Function p_MoveBall()
XBall = XBall + MoveX ; Move ball left or right
YBall = YBall + MoveY ; Move ball up or down
If XBall > 312 Then MoveX = -(BallSpeed)
If XBall < 0 Then MoveX = BallSpeed
If YBall < 10 Then MoveY = BallSpeed

BumperHit = Collision(#BRUSH, 3, BumperXPos, 238, 2, XBall, YBall) ; Check if the BALL(Brush2) collides with the BUMPER(Brush3) at specified x/y-coordinates

For x = 1 To 41 Step 2 ; For each BRICK
If Lines[x] <> 1 Then Lines[x-1] = -50 ; If a brick is hit, move it off the screen -50 pixels.

BrickHit = Collision(#BRUSH, 2, XBall, YBall, 1, Lines[x-1], 20) ; Check if the BALL(Brush2) collides with a BRICK(Brush1) at specified x/y-coordinates

If BrickHit = True
MoveY = BallSpeed ; Move ball downward if it hits a brick
Lines[x] = 4 ; ??????
Score = Score + 10
EndIf
Next

If BumperHit = True Then MoveY = -1 ; Move ball up if it hits the BUMPER

If YBall >= 256 ; Move ball up if it hits wall at bottom
XBall = 0
YBall = 128
MoveY = -BallSpeed
Lives = Lives -1
EndIf

If Lives <= 0 Then p_GameOver()

DisplayBrush(2, XBall, YBall)
EndFunction

Function p_MoveBumper()
If IsKeyDown("LEFT") = True Then BumperXPos = BumperXPos - BumperSpeed
If IsKeyDown("RIGHT") = True Then BumperXPos = BumperXPos + BumperSpeed

OldBumperXPos = BumperXPos

; Check if Bumper is exiting screen
If BumperXPos < 0 Then BumperXPos = 0
If BumperXPos > 280 Then BumperXPos = 280

DisplayBrush(3, BumperXPos, 240) ; Update Bumper position
EndFunction

; Main loop
; ---------

p_NewGame
BeginDoubleBuffer()
Repeat
Cls()
p_MoveBall()
p_MoveBumper()
Flip()
Forever
EndDoubleBuffer()
``````

Bugala
Posts: 715
Joined: Sun Feb 14, 2010 7:11 pm

### Re: Simple breakout in Hollywood

Nice little example. Only disappointment was that there was no win condition. I broke all the bricks and it just continued.

Figgy78
Posts: 32
Joined: Wed Oct 11, 2017 9:13 am

### Re: Simple breakout in Hollywood

Good point. I shall try and correct that.

The obvious next step would be to have multiple levels