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######Draw_bricks()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
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:
def draw_bricks():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
i=0
x1=brick_x
y1=brick_y+(j*(brick_height+Vertical_Separator))
x2=x1+brick_width
y2=y1+brick_height
while (i
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:def erase_bricks(number):
global x1,y1,x2,y2, brick_x, brick_y, brick_width, brick_height,number_of_bricks, Horizontal_Separator,Vertical_Separator,number_of_linesThat finishes the brick functions (Part 2) for the Brick-Breaker Game.
i=0
if (number < i="number" x1="brick_x" y1="brick_y" x2="x1+brick_width" y2="y1+brick_height" fill=" BLACK)"> (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
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
img.rectangle((x1+ (i*brick_width),y1,x2+ (i*brick_width)-Horizontal_Separator,y2),fill= BLACK)
handle_redraw(None)
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:
Post a Comment