Archived:How to develop brick-breaker game in PySymbian - Part 1
hamishwillee
(Talk | contribs) m (Text replace - " PyS60 " to " PySymbian ") |
hamishwillee
(Talk | contribs) m (Hamishwillee - Adding missing translation link) |
||
| (5 intermediate revisions by one user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | [[Category:PySymbian]][[Category:How To]][[Category:Code Snippet]][[Category:Games]] | |
| − | + | {{Abstract|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 first article explaining the PySymbian implementation of Brick-Breaker - it covers the different slider functions in detail.}} | |
| − | {{ | + | |
| − | + | ||
| − | + | {{ArticleMetaData <!-- v1.1 --> | |
| + | |sourcecode= <!-- Link to example source code e.g. [[Media:The Code Example ZIP.zip]] --> | ||
| + | |installfile= <!-- Link to installation file (e.g. [[Media:The Installation File.sis]]) --> | ||
| + | |devices= <!-- Devices tested against - e.g. ''devices=Nokia 6131 NFC, Nokia C7-00'') --> | ||
| + | |sdk= <!-- SDK(s) built and tested against (e.g. [http://linktosdkdownload/ Qt SDK 1.1.4]) --> | ||
| + | |platform= <!-- Compatible platforms - e.g. Symbian^1 and later, Qt 4.6 and later --> | ||
| + | |devicecompatability= <!-- Compatible devices e.g.: All* (must have internal GPS) --> | ||
| + | |dependencies= <!-- Any other/external dependencies e.g.: Google Maps Api v1.0 --> | ||
| + | |signing= <!-- Signing requirements - empty or one of: Self-Signed, DevCert, Manufacturer --> | ||
| + | |capabilities= <!-- Capabilities required by the article/code example (e.g. Location, NetworkServices. --> | ||
| + | |keywords= <!-- APIs, classes and methods (e.g. QSystemScreenSaver, QList, CBase --> | ||
| + | |id= <!-- Article Id (Knowledge base articles only) --> | ||
| + | |language= <!-- Language category code for non-English topics - e.g. Lang-Chinese --> | ||
| + | |translated-by= <!-- [[User:XXXX]] --> | ||
| + | |translated-from-title= <!-- Title only --> | ||
| + | |translated-from-id= <!-- Id of translated revision --> | ||
| + | |review-by= <!-- After re-review: [[User:username]] --> | ||
| + | |review-timestamp= <!-- After re-review: YYYYMMDD --> | ||
| + | |update-by= <!-- After significant update: [[User:username]]--> | ||
| + | |update-timestamp= <!-- After significant update: YYYYMMDD --> | ||
| + | |creationdate= 20090706 | ||
| + | |author= [[User:Nirpsis]] | ||
| + | }} | ||
| + | {{FeaturedArticle|timestamp=20090802}} | ||
==Development tools== | ==Development tools== | ||
| − | + | # Text editor - notepad is sufficient. | |
| − | + | # PySymbian - preferred version: PySymbian 1.4.5 stable release | |
| − | + | # PySymbian script shell - preferred version: PySymbian 1.4.5 stable release | |
| − | + | ||
| − | + | ||
The PySymbian tools can be downloaded from [http://sourceforge.net/projects/pys60/files/pys60/1.4.5/ Sourceforge resources]. | The PySymbian tools can be downloaded from [http://sourceforge.net/projects/pys60/files/pys60/1.4.5/ Sourceforge resources]. | ||
| Line 26: | Line 45: | ||
* time module | * time module | ||
| − | |||
==Functions== | ==Functions== | ||
The following functions are used in Brick Breaker game. | The following functions are used in Brick Breaker game. | ||
| − | + | # <tt>'''draw_screen'''</tt>: draw black screen in canvas. | |
| − | + | # <tt>'''draw_slider'''</tt>: draw slider. | |
| − | + | # <tt>'''leftkey'''</tt>: control the slider by left key. | |
| − | + | # <tt>'''rightkey'''</tt>: control the slider by right key. | |
| − | + | # <tt>'''draw_bricks'''</tt>: draw number of bricks. | |
| − | + | # <tt>'''erase_bricks'''</tt>: erase bricks. | |
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
| − | + | ||
==Initializing slider parameter== | ==Initializing slider parameter== | ||
| Line 164: | Line 177: | ||
=Related Links= | =Related Links= | ||
| − | * [[How to develop brick-breaker game in | + | * [[How to develop brick-breaker game in PySymbian - Part 2]] |
| − | * [[How to develop brick-breaker game in | + | * [[How to develop brick-breaker game in PySymbian - Part 3]] |
| − | * [[Introduction to | + | * [[Introduction to PySymbian]] |
| + | <!-- Translation --> [[pt:Como desenvolver o jogo brick-breaker em PySymbian - Parte 1]] | ||
Revision as of 10:32, 17 September 2012
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 first article explaining the PySymbian implementation of Brick-Breaker - it covers the different slider functions in detail.
Article Metadata
Contents |
Development tools
- Text editor - notepad is sufficient.
- PySymbian - preferred version: PySymbian 1.4.5 stable release
- PySymbian script shell - preferred version: PySymbian 1.4.5 stable release
The PySymbian tools can be downloaded from Sourceforge resources.
The following modules are used when developing this application:
- appuifw module
- sysinfo module
- graphics module
- e32 module
- key_codes module
- random module
- math module
- time module
Functions
The following functions are used in Brick Breaker game.
- draw_screen: draw black screen in canvas.
- draw_slider: draw slider.
- leftkey: control the slider by left key.
- rightkey: control the slider by right key.
- draw_bricks: draw number of bricks.
- erase_bricks: erase bricks.
Initializing slider parameter
Before discussing, any functions in detail - let us define some of the slider parameters.
#SLIDER PARAMETERS#####
SliderX1=120
SliderY1=305
SliderX2=160
SliderY2=315
SliderSpeed=22
SliderColor=RED
import sysinfo
TotalScreenWidth=sysinfo.display_pixels()[1]
draw_screen()
By using this function, We create a black screen in canvas. The definition of the draw_screen() is as follows:
#defining draw function
def draw_screen():
#Set the screen to full
appuifw.app.screen = 'full'
#Global variable for application UI
global canvas
canvas = appuifw.Canvas(redraw_callback=handle_redraw)
appuifw.app.body = canvas
appuifw.app.exit_key_handler = quit
#Global variable for application UI
global img
img = graphics.Image.new(canvas.size)
#Clear the image
img.clear(BLACK)
handle_redraw(None)
draw_slider()
By using this function, we create a slider in canvas using keyboard shortcuts. The definition of the draw_screen() is as follows:
#defining slider function
def draw_slider():
global canvas
#Keyboard shortcuts
canvas.bind(key_codes.EKeyLeftArrow,lambda: leftkey())
canvas.bind(key_codes.EKeyRightArrow,lambda: rightkey())
appuifw.app.body = canvas
appuifw.app.exit_key_handler = quit
#draw the rectangle
img.rectangle((SliderX1,SliderY1,SliderX2,SliderY2),fill=SliderColor)
handle_redraw(None)
leftkey()
The leftkey() is called from the draw_slider() function. By using this function, we can move the slider to left side by pressing left key. Thus, the code of leftkey() function is as follows:
#defining leftkey function
def leftkey():
if (SliderX1>0):
#draw the rectangle
img.rectangle((SliderX1, SliderY1, SliderX2, SliderY2),fill=BLACK)
#globally define variables
global img, canvas,SliderX1, SliderY1, SliderX2, SliderY2
#defining the slider coordinate X1 and X2
SliderX1=SliderX1-SliderSpeed
SliderX2=SliderX2-SliderSpeed
img.rectangle((SliderX1, SliderY1, SliderX2, SliderY2),fill=SliderColor)
#appuifw.note(u"Left arrow was pressed")
handle_redraw(None)
rightkey()
The rightkey() is called from the draw_slider() function. By using this function, we can move the slider to right side by pressing right key. Thus the code of rightkey() function is as follows:
#defining right key function
def rightkey():
if (SliderX2<TotalScreenWidth):
#if (SliderX2<sysinfo.display_pixels()[1]):
#draw rectangle
img.rectangle((SliderX1, SliderY1, SliderX2, SliderY2),fill=BLACK)
#globally define variables
global img, canvas,SliderX1, SliderY1, SliderX2, SliderY2
#defining the slider coordinate X1 and X2
SliderX1=SliderX1+SliderSpeed
SliderX2=SliderX2+SliderSpeed
img.rectangle((SliderX1, SliderY1, SliderX2, SliderY2),fill=SliderColor)
#appuifw.note(u"Left arrow was pressed")
handle_redraw(None)
That finishes the slider functions (Part 1) for the Brick-Breaker Game.
The next article in the series : Part 2 for brick-Breaker, would cover Brick functions for this game.
Screenshots
These screenshots demonstrate the Slider and its movable position on canvas. The screenshots are relevant only to Part 1.


