ABSTRACT
pongyRoids is a fast-paced multi-controlled pong and
asteroids -inspired game developed to help practise
some useful programming techniques and
deconstruct a variety of project documentation
methods. This document contains some sample
planning documentation for the project.
Sumar D. Kudeep
sdk@developerCentral.com
pongyRoids
Developer documentation
Contents
Defining & understanding phase...........................................................................................................2
Program overview.............................................................................................................................2
Client requirements...........................................................................................................................2
Core functionality (required).........................................................................................................2
Extended functionality (not initially required)...............................................................................2
Planning & design phase........................................................................................................................3
Screen design.....................................................................................................................................3
Data dictionary..................................................................................................................................3
Structure chart..................................................................................................................................4
Algorithm design...............................................................................................................................5
pongyRoids....................................................................................................................................5
setup()...........................................................................................................................................6
newLevel().....................................................................................................................................6
draw()............................................................................................................................................7
keyPressed()..................................................................................................................................7
keyReleased()................................................................................................................................7
mousePressed().............................................................................................................................8
addBall()........................................................................................................................................8
moveBat()......................................................................................................................................9
moveBalls()....................................................................................................................................9
removeBall(balls, index)..............................................................................................................10
Implementing phase............................................................................................................................11
Testing & evaluating phase..................................................................................................................11
Maintaining phase...............................................................................................................................11
Extended functionality (not initially required).............................................................................11
1|Page
Defining & understanding phase
Program overview
pongyRoids is a fast-paced multi-controlled pong and asteroids - inspired game developed to help
practise some useful programming techniques and deconstruct a variety of project documentation
methods
Client requirements
The client for this project has specified a set of core functionality as well as extended functionality.
They require all core functionality before release, but would love us to consider features from the
extended functionality as well. The basic requirements list is given below:
Core functionality (required)
Moving bat – a bat that should move around the screen
controlled by the keyboard
New balls - balls should be able to be generated by the player,
one at a time, by pressing the mouse button. Each ball should
appear at the mouse location
Bouncing balls –Each ball should move independently around the screen, bouncing off the
left, top and right sides but should disappear after going below the bottom of the game
window. Balls should also bounce of the player’s bat.
Score – points should be gained on successful bouncing of a ball, but should be lost
whenever a ball drops off the bottom of the screen
Time-limited round – The game should be played in rounds, each round lasting for 30
seconds
Extended functionality (not initially required)
Friction – if the bat is moving when it hits a ball, it should
impart some of its speed to the ball
Gravity – all balls should be affected by gravity
Sound – sounds should occur when events such as generating
or bouncing a ball occur
Images – all objects should show as images - eg ‘balls’ could be represented as ghosts
No bat ‘glitches’ – balls should never get stuck inside the bat
Gems – add random gems into the game such as a ‘balls’ that replicate or a ‘boss’ character
Multiplayer – have more players, each player using a different ‘bat’ and set of control keys
Ball physics – have the balls bounce off eachother as well as the walls
Slider to adjust size of ‘balls’ array
Bullets – allow the player(s) to shoot
High scores file - store and load high scores in a text file
Context diagram
<work in progress>
2|Page
DataFlowDiagram
<work in progress>
Planning & design phase
Gantt chart
<work in progress>
Program-level test data
<work in progress>
Screen design
Data dictionary
Variable Data type Scope Description Example
name
bat Record Global Represents the player’s (400,350,200,20,2,-
(x, y, w, h, bat 1)
xSpeed, ySpeed)
balls Array of records Global Represents the collection [ (200,100,20,2,1),
(x, y, radius, of balls bouncing around (600,90,30,1,-1),
xSpeed, ySpeed) the screen (450,180,10,0,1) ]
score Integer Global The player’s score 130
startTime Integer Global The time, in milliseconds, 1277
that the current round
was started
3|Page
Structure chart
4|Page
Algorithm design
pongyRoids
Processing itself will manage the calling of the special
procedures with reserved names such as setup() and
draw(). Its pseudocode would like a little like this, though
needn’t be created by a pongyRoids programmer:
BEGIN pongyRoids
setup()
REPEAT
draw()
IF a key has been pressed THEN
keyPressed()
END IF
IF a key has been released THEN
keyReleased()
END IF
IF the mouse has been pressed THEN
mousePressed()
END IF
UNTIL the user presses the close control
END
5|Page
setup()
setup() runs once when the program starts. We should create a bat for the player in setup and call a
procedure to reset global variables ready for a new level (this same subprogram can be called later
whenever the player’s round ends).
BEGIN setup()
REM runs once when the program starts
Initialise the screen to a known size
bat=new bat()
newLevel()
END
newLevel()
newLevel() will be called from setup() when the game starts, but also after a round ends so is useful
as a separate procedure
BEGIN newLevel()
REM reset bat and ball data ready for a new level
Initialise all fields in the bat record
Initialise balls to an empty array of ball records
startTime=millis()
score=0
END
6|Page
draw()
Note that the plan for this draw loop asks you to call the moveBat() and moveBalls() subprograms.
If these don’t exist yet, you can either create empty stubs for them, or comment out the relevant
lines of code – and then remember to uncomment them as soon as you create the subprograms.
BEGIN draw() {
REM infinite loop runs until the player closes the program
IF (millis()-startTime<30000) THEN
clear the screen
moveBat()
moveBalls()
text(score, 50, 50)
ELSE
text("Game over", 50, 80)
noLoop()
END IF
END
Instead of changing the bat’s x position directly when a keypress is detected, it might be smoother to
set the player’s bat speed when a keypress is detected. When a key is released, we can set the
relevant speed field back to 0. This lets the player move the bat diagonally and change directions.
keyPressed() keyReleased()
BEGIN keyPressed() BEGIN keyReleased()
REM set the bat speed REM reset the bat speed
IF key is 'a' THEN IF key is 'a' OR key is 'd' THEN
bat.xSpeed=-5 bat.xSpeed=0
END IF END IF
…similar for s,d, and w keys …similar for vertical movement keys
END END
7|Page
mousePressed()
When the user presses the mouse, we should generate a new ball and add it to the array of balls.
mousePressed() is one of Processing’s special event-driven procedures like keyPressed.
BEGIN mousePressed()
REM add a new ball or restart
IF (millis()-startTime<30000) THEN
balls=addBall(balls, mouseX, mouseY)
ELSE
newLevel()
loop()
END IF
END
addBall()
addBall() will be called whenever the user presses the mouse to add a ball to the balls array.
An IPO chart and data dictionary for it are shown below.
ball[] addBall(ball[] balls, float x, float y)
REM add a new ball to the balls array at a given position
Initialise b as a new ball() record
Set the x and y fields of b to the x and y values passed in as parameters
Set the xSpeed, ySpeed and radius fields of b to random numbers
balls=(ball[])append(balls, b)
return balls
END
8|Page
moveBat()
BEGIN moveBat()
REM move the bat
Increment the bat’s x value by its xSpeed
Increment the bat’s y value by its xSpeed
IF (bat.x+bat.w>width) bat.x=bat.x-bat.xSpeed
IF (bat.y+bat.h>height) bat.y=bat.y-bat.ySpeed
Show the bat at its x, y position using its width and height
END
moveBalls()
BEGIN moveBalls()
REM move all the balls
FOR i=0 to balls.length-1
balls[i].x = balls[i].x+balls[i].xSpeed
balls[i].y = balls[i].y+balls[i].ySpeed
circle(balls[i].x, balls[i].y, balls[i].radius*2)
IF balls[i] is touching a side THEN
balls[i].xSpeed = balls[i].xSpeed * -1
END IF
IF balls[i] is touching the top THEN
balls[i].ySpeed = balls[i].ySpeed * -1
END IF
IF (touchingBat(balls[i])) THEN
balls[i].ySpeed = balls[i].ySpeed * -1
Increment score
END
IF (offScreen(balls[i]))
balls = remooveBall(balls, i)
Decrement score
END
END
END
9|Page
removeBall(balls, index)
ball[] removeBall(ball[] balls, int index)
REM remove a ball from the balls array at the given index
REM Shuffle down each ball record starting from the given index and shorten the array by one item
FOR i=index TO balls.length - 2
balls[i]=balls[i+1]
NEXT i
balls=(ball[])shorten(balls)
RETURN balls
END
10 | P a g e
Implementing phase
<work in progress>
Testing & evaluating phase
<work in progress>
Maintaining phase
Once you’ve managed to implement and successfully test the core required functionality, maintain
your game to include more features. Tips for some of these features are shown below.
Extended functionality (not initially required)
Friction – if the bat is moving when it hits a ball, it should
impart some of its speed to the ball
o balls[i].xSpeed = balls[i].xSpeed + bat.xSpeed/2
Gravity – all balls should be affected by gravity
o Use a small constant value for gravity that you add to
each ball’s ySpeed value each frame
Sound – sounds should occur when events such as generating or bouncing a ball occur
o Sketch..Import library..Sound
o import processing.sound.*;
o Then use the examples provided in File..Examples..Libraries..Sound..SoundFile
Images – all objects should show as images - eg ‘balls’ could be represented as ghosts
o Add an image field using the PImage data type to your bat and ball records
o Place images in a folder named ‘data’ inside the sketch folder
o Use loadImage(filename) to load an image, eg bat.image=loadImage(“bat.png”);
o Use the image() function to show an image
No bat ‘glitches’ – balls should never get stuck inside the bat
o When a ball is touching the bat, after reflecting its speed, you could use a WHILE
loop to move the ball until it is no longer touching the bat
Gems – add random gems into the game such as a ‘balls’ that replicate or a ‘boss’ character
o You could make some balls gems by setting a new field in its record or by having a
separate array of gems. Check whether you’ve bumped into a gem and do
something different such as more points, a different sound, creating more balls etc
Multiplayer – have more players, each player using a different ‘bat’ and set of control keys
o It’s probably a good idea to extend the bat or player record to include the keys
associated with movement for each player
Ball physics – have the balls bounce off eachother as well as the walls
Slider to adjust size of ‘balls’ array
Bullets – allow the player(s) to shoot
High scores file - store and load high scores in a text file
11 | P a g e