×
Namespaces

Variants
Actions

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

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngAquivado: 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.

Article Metadata
Article
Created: nirpsis (16 Jul 2009)
Last edited: hamishwillee (08 May 2013)
Featured Article
02 Aug
2009

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:

  1. draw_bricks: draw number of bricks
  2. 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.


Draw screen.JPG BrickBreaker.JPG Erase brick.JPG

Related links

This page was last modified on 8 May 2013, at 08:17.
90 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×