The larger gym ball will be used for the game, as planned, as I believe it offers the player a more interesting gaming experience than playing with the AIBO ball. Playing with the larger ball requires the player to stand further from the screen on which the game is displayed and in turn offers the opportunity to include more players at one time as the ball can be moved anywhere within the cameras viewing range.
IOCT Masters in Creative Technogies
Major Project
An augmented reality game based on "Breakout"
Thursday, 24 July 2008
Gym ball
The larger gym ball will be used for the game, as planned, as I believe it offers the player a more interesting gaming experience than playing with the AIBO ball. Playing with the larger ball requires the player to stand further from the screen on which the game is displayed and in turn offers the opportunity to include more players at one time as the ball can be moved anywhere within the cameras viewing range.
Labels:
AIBO ball,
code,
development,
game,
gym ball,
hue,
players,
saturation
Tuesday, 22 July 2008
Separating the code
Having all of the code for the game in one file was making working on the file difficult, especially when trying to find certain sections of the code. I have created a header file, which is then called by each of the other .c files, allowing them to compile.
The header file includes:

The code has been separated into suitable sections, with the .c files including:
The header file includes:
- Libraries and includes
- Define constants
- Structures
- Global variables
- Game items
- Image
- Function prototypes

The code has been separated into suitable sections, with the .c files including:
- Breakout_v3.c
- Breakout_v3.h
- Collision_Detection.c
- Drawing.c
- High_Score.c
- Levels.c
- Sound.c
Brick cracks
In levels two and three the bricks are not deleted on their first contact with the ball. To show the player which bricks have been hit, I have coded a crack design. The cracks appear in level two once a brick has been hit once. In level three two cracks appear on the brick after the first collision and then another crack appears after the second collision.
To design the cracks I tried a variety of designs on a printscreen of the bricks, using Microsoft Paintbrush. Once I had chosen the brick crack preferred design, I then calculated the pixels which were part of the crack and coded this using the cvLine command. The cracks are created by coding a series of small lines.
The code is divided into three sections, one for each crack. In level two cracks one, two and three appear on the first collision. In level three cracks one and two appear after the first collision and crack three appears after the second collision.


To design the cracks I tried a variety of designs on a printscreen of the bricks, using Microsoft Paintbrush. Once I had chosen the brick crack preferred design, I then calculated the pixels which were part of the crack and coded this using the cvLine command. The cracks are created by coding a series of small lines.
The code is divided into three sections, one for each crack. In level two cracks one, two and three appear on the first collision. In level three cracks one and two appear after the first collision and crack three appears after the second collision.

Coding the brick collision effects
To code the brick collision effects I have included checks in an if statement, to check once the brick has been hit if the hit number matches the level number. In the first level, if the brick has been hit once then the player will hear an explosion effect whilst the brick disappears. In the second level of the game, the first time a brick is hit (which is one number less than the level number) the player hears a collision noise and cracks appear on the brick. The second time a brick is hit (the same number of hits as the level number) the player hears an explosion noise and the brick disappears. In the third level, the first hit creates a collision noise and two cracks appear on the brick (this is two hits less than the level number), the second hit creates a collision noise and another crack appears (this is one hit less than the level number) and the third hit causes an explosion noise and the brick disappears (as the hit number equals the level number).
Brick collision effects
In order for the player to know when the ball collides with a brick I have decided to make this clear through the use of visual and audio techniques. This will give the player(s) an indication that a brick has been hit and that the computer has recognised this. Cracks have been coded to represent bricks which have been hit but have not yet been hit enough times to be deleted (the brick has not been hit the same number of times as the level number).
The range of audio and visual effects that occur when a brick is hit include:
Level 1: Brick hit first time = Explosion noise, brick disappears
Level 2: Brick hit first time = Collision noise, cracks appear on the brick
Level 2: Brick hit second time = Explosion noise, brick disappears
Level 3: Brick hit first time = Collision noise, cracks appear on the brick
Level 3: Brick hit second time = Collision noise, another crack appears on the brick
Level 3: Brick hit third time = Explosion noise, brick disappears
This requires the code used for the brick disappearing, first set of cracks and second set of cracks and also the explosion and collision sound effects.
The range of audio and visual effects that occur when a brick is hit include:
Level 1: Brick hit first time = Explosion noise, brick disappears
Level 2: Brick hit first time = Collision noise, cracks appear on the brick
Level 2: Brick hit second time = Explosion noise, brick disappears
Level 3: Brick hit first time = Collision noise, cracks appear on the brick
Level 3: Brick hit second time = Collision noise, another crack appears on the brick
Level 3: Brick hit third time = Explosion noise, brick disappears
This requires the code used for the brick disappearing, first set of cracks and second set of cracks and also the explosion and collision sound effects.
Tuesday, 8 July 2008
Music
Having added sound effects to the game and understood how the MIDI signals can be used, I have also decided to include some musical elements. I feel the introduction to the game and the congratulations screen would benefit from having music playing alongside the visual image.
For the congratulations screen, I feel it appropriate to use Cliff Richard's "Congratulations". In order to code this, I researched and found a piano score on the Internet to find which notes are used in the chorus, the length of the notes and where the rests are in each bar. I then used a conversion list to convert the pitch musical notes into code and was able to write a piece of code to play the chorus of "Congratulations".
Here is the code I wrote for "Congratulations":
For the congratulations screen, I feel it appropriate to use Cliff Richard's "Congratulations". In order to code this, I researched and found a piano score on the Internet to find which notes are used in the chorus, the length of the notes and where the rests are in each bar. I then used a conversion list to convert the pitch musical notes into code and was able to write a piece of code to play the chorus of "Congratulations".
Here is the code I wrote for "Congratulations":

Sound effects
Bloop:
Used during the countdown, synchronised with the countdown
Explosion:
Used when a brick explodes
Waaaa:

Used when a "life" is lost
Boing:
Used when the ball collides with an object on the game screen, including:
Used when a level is completed

Used during the countdown, synchronised with the countdown
Explosion:

Used when a brick explodes
Waaaa:

Used when a "life" is lost
Boing:

Used when the ball collides with an object on the game screen, including:
- ball hits brick
- ball hits border
- ball hits paddle

Used when a level is completed
Labels:
"life",
border,
bricks,
code,
collision detection,
countdown,
game screen,
object interaction,
paddle,
sound
Sound code
I have researched the ways to add sound effects using c code and OpenCV. The best way appears to be to use a Musical Instrument Digital Interface (MIDI) voice. MIDI works by transmitting digital data about the pitch, intensity and length of notes, for example.
In the code I set up sound as an integer variable to include:
Volume ranges from 0 – 127, or off to loudest
Voice ranges from 0 – 127, each number representing a different voice or instrument effect
This took some time for experimentation and research to find the noises I wanted to include in the game.
A sample of the code looks like this:

In the code I set up sound as an integer variable to include:
- Frequency (as a floating point number)
- Duration (as an integer variable)
- Volume (as an integer variable)
- Voice (as an integer variable)
- Tempo (as a floating point number)
Volume ranges from 0 – 127, or off to loudest
Voice ranges from 0 – 127, each number representing a different voice or instrument effect
This took some time for experimentation and research to find the noises I wanted to include in the game.
A sample of the code looks like this:

Sound
I have carried out some research into the use of sound in game and have decided to add sound to the game, to make playing the game a more interesting experience, as it involves more of the senses.
Times in the game that may benefit from sound:
Times in the game that may benefit from sound:
- Ball and border collision
- Ball and paddle collision
- Ball and brick collision
- Brick explosion
- Losing a “life”
- Completing a level
- Congratulation state
- During the countdown
- Introduction to the game
Friday, 4 July 2008
Brick collision each row
The calculations shown in this blog are for the first row of bricks. The calculations are the same for each row, changing the number in the code, for example, bricks1 is used for the first row, bricks 2 for the second row and so on.
Subscribe to:
Posts (Atom)