Page 1 of 1

Simple breakout in Hollywood

Posted: Tue Nov 09, 2010 11:00 pm
by ArtBlink
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

Re: Simple breakout in Hollywood

Posted: Sun Aug 07, 2016 11:00 pm
by mjnurney
Excellent

Re: Simple breakout in Hollywood

Posted: Sat Sep 24, 2016 6:51 pm
by fjudde
ArtBlink wrote:Hello,

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

Re: Simple breakout in Hollywood

Posted: Tue Jan 29, 2019 8:17 pm
by Figgy78
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
		p_UpdateScreen()
		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

Function p_UpdateScreen()
	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()
	p_UpdateScreen()
	Flip()
Forever
EndDoubleBuffer()

Re: Simple breakout in Hollywood

Posted: Tue Jan 29, 2019 8:36 pm
by Bugala
Nice little example. Only disappointment was that there was no win condition. I broke all the bricks and it just continued.

Re: Simple breakout in Hollywood

Posted: Tue Jan 29, 2019 10:22 pm
by Figgy78
Good point. I shall try and correct that.

The obvious next step would be to have multiple levels

Re: Simple breakout in Hollywood

Posted: Mon May 20, 2019 1:40 pm
by amyren
That is a cool small game.
I did apply a couple of changes for my own mod.
Not so much, but added the option to select Mouse or Keyboard to control the pad, and added a message for the player who complete the game, with the option to start again.

Apart from adding new levels, I think the game needs to get a bit more challenging. If one could change the angle of the ball depending on where on the bat you hit it would make the ball more unpredictable.

Code: Select all

/****************************************************************
**                                                             **
** Name:        Simple Breakout                                **
** Author:      ArtBlink & Figgy/CtZ & amyren                  **
** Version:     1.2                                            **
** Date:        05.20.2019                                     **
** Interpreter: Hollywood 7.1                                  **
** Function:    Simple Breakout clone tutorial game            **
**                                                             **
** History:                                                    **
**                                                             **
**                                                             **
** 1.2: (05.20.2019)                                           **
** - Added Mouse control and completed game message            **
**                                                             **
** 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,#YELLOW)  ; 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

Repeat
	TextOut (120, 128, "Use Mouse (M)")
	TextOut (112, 144, "Or Keybd (K)")
	If IsKeyDown("M") = True Or IsKeyDown("m") = True
		MouseMode = 1
		Break
	ElseIf IsKeyDown("K") = True Or IsKeyDown("k") = True
		MouseMode = 0	
		Break
	EndIf
Forever	

Function p_GameOver()
	Repeat
		Cls
		p_UpdateScreen()
		If score > 199
			TextOut(80, 128, "WELL DONE, YOU WON!")
		Else
			TextOut (120, 128, "GAME OVER!")
		EndIf
		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

Function p_UpdateScreen()
	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()
	If score = 200 Then p_GameOver()		
	DisplayBrush(2, XBall, YBall)
EndFunction

Function p_MoveBumper()
	If MouseMode = 1 
		BumperXpos = MouseX()
	Else
		If IsKeyDown("LEFT") = True Then BumperXPos = BumperXPos - BumperSpeed
		If IsKeyDown("RIGHT") = True Then BumperXPos = BumperXPos + BumperSpeed
	EndIf	
	;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()
EscapeQuit(True)
Repeat
	Cls()
	p_MoveBall()
	p_MoveBumper()
	p_UpdateScreen()
	Flip()
Forever
EndDoubleBuffer()