1. IS51016A: Audio Visual Computing
Coursework 2 Report
Giancarlo Santana Batista Fleuri (33316392)
1 - Summary
Galaxy Defender is a 3d shooting game created using Processing (2.1.1) and the Minim Library [1] and
my own ‘library’ for the camera (see session 3 or the code for more details). The main scenario is the
Milky Way, with all the planets moving around the sun, but the current version enables you to go
beyond and explore. The score is based on number of enemies destroyed. The interaction was made to
be easiest as possible, being also possible to play using only the mouse. The physics concepts used in
the development aims to deliver a cool immersion effect to the player.
2 - Features and User Interactions
As a gamer, I couldn't have chosen something better to develop. The physics required for this kind of
project (such as collision, gravity, acceleration, rotations and etc.), is another reason why I chose this.
Besides that, my main focus during the Audio Visual Computing course was these concepts. The
relation between the game and the course support is clear: The scenario was drawn based in the first
coursework, which required us to create a 2D solar system. Furthermore, all these physics concepts
were applied since the first labs. I went beyond and I decided to create a 3D version with coloured
spheres. Then I decided to make it more beautiful (I was not happy with our planet as a blue sphere)
and decided to implement one of the most difficult parts of the game which is to apply textures to 3D
spheres to create the planets. Finally, I was always interested in space games like the classic Asteroids,
my main inspiration.
2.1 – Main elements of the game
The main menu – With options like: Play, Instructions, Credits and Exit.
The player – The main spaceship (1st
person camera) with the goal to kill the maximum of
enemies possible without run out of health.
Enemies – Spaceships with different behaviours with the goal to kill the player.
Scenario – The Milky Way
Sounds – Sounds effects archived using the Minim library and include different sounds such
as the soundtrack, shots, explosions and a red alert.
Figure 2.1 – Game scene: Health bar, score, enemies, scenario and some action (shots and explosions).
2. 2.2 – Controls
Mouse:
o Moves the camera on X and Y axis.
o Left button: shoot
o Middle button: accelerate
o Right button: reverse gear
Keyboard:
o SPACE to accelerate and
o ESC to exit at any time
2.3 – Gameplay
The gameplay is quite intuitive. The goal is to survive and kill the maximum of enemies possible
without run out of health as explained in the section 2.1. The game flow would be: Open the
application →Select your menu option→ (if option = = Start) then play → Kill or be killed → Play
again. The player can dodge the shots combining camera movements and rotations.
Next version (already started with an Android version) improvements to turn the game play even more
exciting:
Flocking between the enemies
Improvement on the Artificial intelligence
Collision with the planets and effects when it get shot
Implementation of power-ups randomly placed, such as health and more powerful shots
Creation of bosses for each X points with extra rewards
Complex movements such as barrel roll
2.4 – Effects
There are some effects to improve the immersion during the gameplay, accomplished by physics or
Audio Visual Effects:
Explosion – When an enemy is killed, also plays a Minim sound when it happens
Stars – Comes towards the player's direction when accelerates
Camera Shaking – When the player gets shot
Fade effect – When the player leaves the galaxy
Sounds – Themed Soundtrack[2],
Figure 2.4.1 – Stars Effect, delivers an immersive effect and sense of direction.
3. 3 - Development
The development of the game was a great challenge for many reasons. A completely new programming
language combined with the ambition of a 3D game with a lot of audio-visual effects. Another
challenge is the structure of the code when I started to work with so many classes, adding galaxy (It
was programmed even before the rest) at the end of the implementation demanded more time and
research than create it. Finally, the more difficult feature to implement was the camera; there is no
camera library, since I used a 3D matrix made by my own to ‘create’ my own camera library. In this
section I’ll try to summarize and simplify the maximum as possible, the key points of the game,
explaining each class and its functions in the application, exemplifying with some snippets of code.
3.1 – Main methods, classes and its responsibilities
DrawSphere – This is probably the most complex class of the whole application. There are
some of the main functions and responsibilities of this class:
o Orbit lines - Draw the orbit lines using the ellipse() function at same distance as the
planets from the sun
o Moons – Draw a moon if it is settled in the function call:
if (moon == true)//if a planet has a moon arround it
{
pushMatrix();
noStroke();
rotateZ(frameCount * -PI/3 * 0.05);//Rotate the moon arround the planet
translate(0, 40, 0);//distance from the planet
fill(#aea7a7);//Gray color, no texture used to save image processing
sphere(5);//size of the moon
popMatrix();
}
o Shape - used to create the grid sphere:
for (int j = 0; j < yDetail; j++) {
beginShape(TRIANGLE_STRIP);//create a new TRIANGLE_STRIP shape, the sphere as a
general shape
texture(texmap);//used to draw the texture arround the grid of triangles
for (int i = 0; i <= xDetail; i++) {//create new triangles to create a sphere
of triangles
vertex(allPoints[i][j+1][0], allPoints[i][j+1][1], allPoints[i][j+1][2],
xGrid[i], yGrid[j+1]);
vertex(allPoints[i][j][0], allPoints[i][j][1], allPoints[i][j][2], xGrid[i],
yGrid[j]);
}
endShape(CLOSE);//ends the shape
}
setup();
draw(); Chara Fighter
Effect
Menu
Enemy
MenuItem
Player
DrawSphere
4. setup(); - The main responsibility here is the same as any setup method, setting of the screen
size, 3D mode and loading of all the images and sounds used in the other classes and
functions. The only part of this code that may be different from the other that someone is
used to is the call for another function inside it:
addEnemy(10);//add 10 enemies on the game
The implementation of this function can be viewed here:
void addEnemy(int n)//add a new enemy/spaceship
{
fighterList.add(player);//create the player
for (int i=0; i<n; i++) {//create new enemies in random areas around the player
fighterList.add(new Enemy(random(-2000, 2000), random(-2000, 2000), random(-3000,
-4000), 150, (random(1, 3))));
}
}
The reason why I had to do it is to avoid the recreation of the enemies on every call in the
draw method, which would crash the game. There are other ways to do that, but this way I can easily
set the amount of enemies on the start of the game. There are also a call to addenemy(); when the
player kills an enemy, so the game became more challenging:
if (fighter.damage(bullet.power)) {//If the player destroy a enemy
fighterList.remove(j--);//Remove from the list
score2 ++;//Score +1
addEnemy(1);//Add a new enemy
addExplosionEffect(fighter);//Explosion effect is applied
cameraShake += 3.0;//how strong is the shake
}
Draw(); - Where is practically where all the ‘magic’ happens. The same as any draw method
this one is called directly after setup(), and continuously executes the lines of code contained
inside its block until the program is stopped. The cool stuff and one of the key features here is
the menu, which gives the user the options to see the instructions and credits before play. The
selection of the button is made in this line. It opens the first screen, the menu:
if (MODE.equals("NIL")) {
menuBackground.resize(width, height);//resize the image to fit the screen
background(menuBackground);//define this image as background
menu.render();//render the menu
MODE=menu.whichItem();//selection of the Item from the menu
}
Chara - Implements all the Character attributes and main functions, such as:
o void roll - Rotate arround all the 3 axis, acording with the parameters received
o void accel – Moves the player to where it is looking at
o void revert - Moves the player agains to where it is looking at
o void lookAt - Set the field of vision of the player
o more - Explained in the code comments
Bullet – Extends Chara (Character) and has the responsibility to define the attributes of the
bullet, the laser shot:
o Shape – rectangle, created using the box() function
o Size – _radius, can be settled when the draw() method creates the bullet
o Color – green if it comes from the player and red from the enemies
o Which group (player or enemy)
o Power - _power, can be settled when the draw() method creates the bullet
5. Effect – Extends Chara (Character) and create the explosion effect, the main part of this class
is here:
void drawShape() {
damage(2);
matrix.scale(1.04);//scale the matrix in 4%
matrix.rotateX(0.1);//rotate it to create a cool effect
fill(255, 64, 32, map(health, 0, 100, 0, 128));//explosion effect, with a red
color
sphereDetail(7); //detail of the spheres of the explosion. If higher, more
rounded it will be
sphere(radius);//Draw the effect itself
}
References
[1] Minim library is available at: http://code.compartmental.net/tools/minim/
[2] Soundtrack by GameBalance available at: http://www.newgrounds.com/audio/listen/561358
[3] Audio effects by Freesound available at: https://www.freesound.org/
[4] Textured Sphere Example available at: http://processing.org/discourse/beta/num_1274893475.html
[5] Processing reference used during the whole development, available at:
http://processing.org/reference/
[5] Moving 3D camera used to have an idea about how to move a 3D camera without using any library.
Available at: http://www.openprocessing.org/sketch/12557
[6] NASA website, used to set the scale of distance, size and proportion of the solar system used:
http://www.nasa.gov/
[7] Solar system scale tool, available at: http://www.exploratorium.edu/ronh/solar_system/