×
Namespaces

Variants
Actions
Revision as of 08:55, 18 September 2012 by hamishwillee (Talk | contribs)

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

From Nokia Developer Wiki
Jump to: navigation, search

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 third and final article explaining the PySymbian implementation of Brick-Breaker - it covers code for the moving ball, intializing the bricks parameter, slider parameter and sequence of calling functions.

Article Metadata
Article
Created: nirpsis (21 Jul 2009)
Last edited: hamishwillee (18 Sep 2012)
Featured Article
02 Aug
2009

Contents

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 PySymbian.

In this article we 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.


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 module
import e32,random
import time
import appuifw
import graphics
import math
BLACK=(0,0,0)
GREEN=(0,255,0)
RED=(255,0,0)
running=1
 
#define exit function
def quit():
global running
running=0
 
appuifw.app.exit_key_handler=quit
 
#Set the screen to large
appuifw.app.screen='large'
 
#Create an instance of Canvas and set it as the application's body
canvas=appuifw.Canvas()
appuifw.app.body=canvas
j,k=canvas.size
 
#define circle coordinate
x1vel=10
y1vel=10
x1=150
y1=300
speed=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.

General diagram brickbreaker.JPG BrickBreaker final.JPG


This concludes the series of articles about creating the game.

Related Links

178 page views in the last 30 days.
×