# Archived:How to develop brick-breaker game in PySymbian - Part 2

## Contents |

## Introduction

In the Part 1 of this article series the slider functions were discussed and one has an idea about how to create a moving slider for the Brick-breaker game. In this article - Part 2, we would learn about different brick functions.

Brick functions of this game include functions for drawing the number of bricks needed and erase the required bricks. Following functions are discussed in this article.

1.` draw_bricks`: draw number of bricks

2.` erase_bricks`: erase bricks

# Part 2

In this Brick-breaker game, we initialize some brick parameters. One can change the value of this parameter according to his customization requirements. The bricks can be replaced by certain fancy or game characters by birds or insects as shown in the following screenshot. The parameters for simple bricks used in this game are initialized as follows:

# Initializing bricks parameter######

brick_x=10

brick_y=40

brick_width=32

brick_height=20

number_of_bricks=7

number_of_lines=3

Horizontal_Separator=2

Vertical_Separator=3

BrickColour=BLUE

BrickBorder=GREEN

## draw_bricks()

By using this function, we can draw numbers of bricks in horizontal as well as vertical direction. Here, I have created total 30 bricks.

The defination of the draw_screen() is as follows:

#defining brick function

def draw_bricks():

#defining global variable

global x1,y1,x2,y2, brick_x, brick_y, brick_width, brick_height,number_of_bricks, Horizontal_Separator,Vertical_Separator,number_of_lines

j=0

while j<number_of_lines:

i=0

#define recatngle coordinate

x1=brick_x

y1=brick_y+(j*(brick_height+Vertical_Separator))

x2=x1+brick_width

y2=y1+brick_height

while (i<number_of_bricks):

drawing rectangle

img.rectangle((x1+ (i*brick_width),y1,x2+ (i*brick_width)-Horizontal_Separator,y2), width=1, outline=BrickBorder,fill= BrickColour)

i=i+1

handle_redraw(None)

j=j+1

## erase_bricks()

By using this function, we erase the bricks by passing the number of brick that is required to be earased. The definition of the add_location() could be as follows:

#define erase number

def erase_bricks(number):

#define global variable

global x1,y1,x2,y2, brick_x, brick_y, brick_width, brick_height,number_of_bricks, Horizontal_Separator,Vertical_Separator,number_of_lines

i=0

if (number < number_of_bricks):

i=number

x1=brick_x

y1=brick_y

x2=x1+brick_width

y2=y1+brick_height

#define global variable

img.rectangle((x1+ (i*brick_width),y1,x2+ (i*brick_width)-Horizontal_Separator,y2),fill= BLACK)

handle_redraw(None)

if (number < (2*number_of_bricks)) and (number > (number_of_bricks-1)):

i=number-number_of_bricks

x1=brick_x

y1=brick_y+(1*(brick_height+Vertical_Separator))

x2=x1+brick_width

y2=y1+brick_height

#drawing rectangle

img.rectangle((x1+ (i*brick_width),y1,x2+ (i*brick_width)-Horizontal_Separator,y2),fill= BLACK)

handle_redraw(None)

if (number < (3*number_of_bricks)) and (number > (2*number_of_bricks-1)):

i=number-(2*number_of_bricks)

x1=brick_x

y1=brick_y+(2*(brick_height+Vertical_Separator))

x2=x1+brick_width

y2=y1+brick_height

#drawing rectangle

img.rectangle((x1+ (i*brick_width),y1,x2+ (i*brick_width)-Horizontal_Separator,y2),fill= BLACK)

handle_redraw(None)

That finishes the brick functions (Part 2) for the Brick-Breaker Game.

The next article in the series- Part 3 for brick-Breaker , would cover Bouncing ball in canvas, game operation and would conclude this game.

## Screenshots

These screenshots demonstrate the Brick function on canvas. The screenshots are relevant only to Part 2.