Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

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

Aquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|*escreva a sua justificativa*}}.

Acredita-se que este artigo ainda seja válido no contexto original (quando ele foi escrito)

Brick-Breaker is a simple arcade game where the player moves a paddle on the screen and bounces a ball towards bricks at the top of the screen. When the ball hits a brick it breaks and the ball bounces back - the objective of the game is to destroy all the bricks. This is the second article explaining the PySymbian implementation of Brick-Breaker - it covers the different brick functions.

## Contents |

## Introduction

In the Part 1 of this article series the slider functions were discussed. In this article we discuss the different brick functions.

The brick functions include functions for drawing the number of bricks needed and to erase the required bricks. We discuss the following functions:

: draw number of bricks**draw_bricks**: erase bricks**erase_bricks**

## Source code

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.

(no comments yet)