IOCT Masters in Creative Technogies
Major Project
An augmented reality game based on "Breakout"

Showing posts with label sound. Show all posts
Showing posts with label sound. Show all posts

Tuesday, 22 July 2008

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.

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":

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:
  • ball hits brick
  • ball hits border
  • ball hits paddle
Completion:








Used when a level is completed

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:
  • 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:
  • Ball and border collision
  • Ball and paddle collision
  • Ball and brick collision
  • Brick explosion
Other times during the game when sound effects or music could be used:
  • Losing a “life”
  • Completing a level
  • Congratulation state
  • During the countdown
  • Introduction to the game

Friday, 4 July 2008

Brick collision from below to the left

Collision on the side of a brick only occurs when the ball is travelling sideways and the brick next to it no longer exists. I need to create an if statement, which says if the ball is travelling to the left, but do not check if the brick being hit is the left-most brick (as there is no brick to the left of it to be hit), then check the side collision.

x1 = prevballx – (bricks1[i-1].posx + bricks1[i-1].halfwidth) – gameball.radius – 4;
t = (float)*1 / (float)gameball.velx;
y1 = (int) (t*(float)gameball.vely);
tempballposx = prevballx + x1;
tempballposy = prevbally + y1;


//Check that the collision is between the top and bottom of the brick
if (bricks1[i-1].posy + bricks1[i-1].halfheight + 7 >= tempballposy && bricks1[i-1].numberhits < level)
{
bricks1[i-1].numberhits ++; //Add one to hit count
if (bricks1[i-1].numberhits == level); //Set up to check if brick hits equals level number then a sound effect could be added later
}
score = score+10; //Add 10 to the score each time a brick is deleted
gameball.velx = - gameball.velx; //Reverse the direction of the ball
gameball.posx = tempballposx + (int) ((1.0-t)*(float)gameball.velx); //Calculate the final ball position
gameball.posy = - tempballposy + (int) ((1.0-t)*(float)gameball.vely); //Calculate the final ball position
checklevelcomplete(); //Check if the level has been completed

Wednesday, 2 July 2008

Meeting with Project Supervisor

Meeting with Project Supervisor, Mohammad Ibrahim
Friday 19th June
2.15pm

I demonstrated a version of my work and talked Mohammad through the code. I answered questions relating to the working process and the code itself. We discussed possible directions for the project, such as potentially adding sound. I had not previously considered incorporating sound into the game, as I was not sure exactly how tight time constraints would be (having never programmed a game before), however, Mohammad believes that I am working and progressing well and may have time to add additional aspects to the game.