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

Introduction

Finally we have the last article in the series of "How to develop brick-breaker game in Python. If you have followed the previous articles in this series, then after finishing this one, you should be able to create your own Brick-breaker or similar game using PyS60.

In this article- Part 3, we would learn about the code for the moving ball, intializing the bricks parameter, slider parameter and sequence of calling functions. Let's discuss them in detail.

Part 3

Code for moving the ball

Here we have a little code for moving the ball in canvas. This ball is moving automatically.

Thus the code for moving the ball could be as follows:

`# import moduleimport e32,randomimport timeimport appuifwimport graphicsimport mathBLACK=(0,0,0)GREEN=(0,255,0)RED=(255,0,0)running=1 #define exit functiondef quit():    global running    running=0 appuifw.app.exit_key_handler=quit #Set the screen to largeappuifw.app.screen='large' #Create an instance of Canvas and set it as the application's bodycanvas=appuifw.Canvas()appuifw.app.body=canvasj,k=canvas.size #define circle coordinatex1vel=10y1vel=10x1=150y1=300speed=15 while running:    global x1,y1,x1vel,y1vel     if((x1<0) or(x1>j-15)):        x1vel=x1vel*-1    if ((y1<0) or (y1>k-15)):        y1vel=y1vel*-1    x1=x1+x1vel    y1=y1+y1vel    x2=x1+speed    y2=y1+speed     #draw circle    canvas.ellipse((x1,y1,x2,y2),outline=None,fill=RED)     # Sleep for 0.1    e32.ao_sleep(0.1)     #clear canvas    canvas.clear(BLACK)    e32.ao_yield()`

Sequence of calling functions

The defined functions need to be called in a proper sequence. sequence of calling functions are as follows:

`draw_screen()draw_slider()draw_bricks()erase_bricks(12) #Should be called when collision is detected- See Related Links app_lock = e32.Ao_lock()app_lock.wait()`

Screenshots

The this article in the series- Part 3 for brick-Breaker , cover whole brick breaker game in canvas.

We have concluded the series of articles related on "How to develop Brick-Breaker game. If you have followed this series, you would be able to create a Brick-Breaker game in Python for S60.

100 page views in the last 30 days.