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

Showing posts with label research. Show all posts
Showing posts with label research. Show all posts

Wednesday, 30 July 2008

Congratulations screen

Something exciting/worthwhile needs to happen as part of the visuals for the congratulations screen in order for the player to want to complete the game. Following on from my idea to include the Cliff Richard tune “Congratulations” I have decided to create a dancing Cliff Richard for this screen.

In order to create the effect of a dancing Cliff Richard I began by trying to draw Cliff Richard using Microsoft Paintbrush. I was working on the idea of having two similar images and switching between the two, to create a dancing effect. To create an image of Cliff Richard I was referring to a video of his performance durin
g the Eurovision Song Contest on YouTube.com. I then realised I would be able to take a few print screens of the video of Cliff Richard dancing and use these instead. From the print screens I found two similar images and cropped them to leave two images which when switched between gave the effect of Cliff Richard dancing.

I then began my research into how to load the two images to be displayed as part of the Congratulations screen and then switch between the two.

In the drawing file of my code I draw the Cliff Richard images to the screen, with an if statement relating to the toggle switch in the main Breakouy_v3.c file. The toggle allows the two images to be switched between, creating the effect of Cliff Richard dancing. In the drawing file I also had to flip the images of Cliff Richard vertically, as they were loading upside down before I added the cvFlip line of code.






















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

Monday, 16 June 2008

High score board

To understand how to create the High Score Board I needed to research this topic and how score boards are created for computer games. The scores need to be saved in a separate text file. The file is loaded into the structure of the memory at the beginning of the game.

I have structured the text files as follows:
Name (3 characters) Tab Score

To write the headings, “High Score Board”, “Name” and “Score” to the screen I used the sprintf code. I’ve also used the sprintf code in printing the text from the separate file to the screen.

To read the information from the separate file I have used the fscanf code. I began by pointing the computer to the relevant file and have created an integer variable to deal with the scores and a character variable to deal with the names. The code used then opens the relevant file and reads it: fileHandle – fopen(“highscores.txt”, “r”);

I then read the string, tab across, integer and create a new line. This points to the name and score strings. A copy of the name and score are then created. This process is repeated three times to then be used in displaying the names and scores of the three highest scorers.

Wednesday, 11 June 2008

Developing ball movement

The movement of the ball is based on the mathematical principles of trigonometry and Pythagoras theorem, so these principles were researched.
h = overall velocity of the ball (the hypotenuse)
x = x component of the ball velocity
y = y component of the ball velocity
0 = theta, angle of the path of the ball, set to a randomly generated number between 35o and 55o

x = sin 0 * h
y = cos 0 * h

Trigonometry:
Trigonometry can be used to calculate angles. In right-angled triangles, where there is a hypotenuse, the term SOHCAHTOA can be used:
  • SOH = sine = opposite/hypotenuse
  • CAH = cosine = adjacent/hypotenuse
  • TOA = tan = opposite/adjacent

Pythagoras theorem:
In a right-angled triangle, the hypotenuse is equal to the sum of the other two sides. Often written as: a
2+b2=c2

Random number generation:
For the ball to leave the paddle at the start of each game using a different angle, a random number between two set boundary numbers should be generated and control the ball’s initial movement. The boundary numbers are 35o and 55o as these were considered suitable angles between which to project the ball from the paddle.
To create a random number between these boundaries the srand code is implemented to initialise the random number generator, using processor clicks, as these values are different every time the program runs. The boundary angles are then set and the angle must be between these values, it is then multiplied by 2pi/360, and converted to radians. The ball velocity in x and y are then calculated and the remainder of the random number is divided by 2, giving an answer of 0 or 1, allowing the x component to be reversed, changing to direction the ball takes as it leaves the paddle.

Coding a timer

In order to create a countdown I needed to code a timer, again I needed to carry out some research to find the best way to do this. To work out that a second in time has passed the processor clicks need to be counted. If the number of processor clicks is greater than the number of clicks per second, then a second in time has passed.

The timer may also be used if I add a time counter to the game. This is not necessary and may make the scoring system more intricate. I may add a time counter to the game if I manage to get the rest of the essential coding done within the expected time limits.

To create the timer I have included the header file time.h and used the clock code in my game code.

Font experimentation

As the game needs to include text I have carried out some research into the font options available using OpenCV and then carried out some experiments with these.

Text items include:
  • Initialisation
  • Score
  • Countdown
  • Game over
  • High score board

This is an example of the initialisation screen and the font used throughout the game.

Monday, 2 June 2008

Gantt Chart

Planning

I've been busy planning my ideas for the project. I've been creating initial design ideas for the game board/screen and have been trying to work out where the objects will be placed on the screen, how they will interact with one another and specifiying some names for key variables.

The project is heavily based on mathematics, to understand the collision detection and spatial position of objects on the screen. I have been researching and working in my logbook at this planning stage so that I have firm ideas in place before trying to code the game.