CubeInvaders
From DIT Experimental Gaming Group
Contents |
Team Members: Mark Dunne
Team Mentor: Bryan Duggan
Concept
The concept behind Cube Invaders was to combine the Rubik’s Cube with the classic Space Invaders arcade game. The theory behind the gameplay is to rotate the cube to change its color, when the color of the cube matches the color of the invading space creator the player wants to shoot; the ship’s missiles will be able to destroy the space creator. The player must progress through the game rotating the cube, destroying all the invaders, once all the invaders are dead the next level will be activated. There are only one to six levels, and like the classic version of the game, the player must gain a high score to beat the game. The game freezes as the cube is rotating, this allows the player time to rotate the cube to the right color they need to kill the invading space creators.
Design
The project was developed in two parts. The game logic was created in a XNA game project called ‘CubeInvaders’. The second part of the project, contained the cube rendering stuff and was the main entry (‘Run()’) point of the game. It was built and kept in a separate project initially. The two projects were then merged together before completion.
After the completion of each level, the invasion force appears one row closer to the player. This makes it harder for the player to clear the screen as they will have less time to do it than the previous screen allowed. Each level’s invasion force contains the level number in it, for level one there is a red one in the center of the invasion force, for level two there is a orange two, so on and so forth for all six levels. Code Sample Below;
/// <summary>
/// Type of invader in each row for level one.
/// </summary>
private static int[] InvaderTypesLevel1 = {
13, 14, 15, 16, 17, 12, 14, 15, 16, 17, 13,
11, 7, 8, 9, 6, 6, 7, 8, 9, 10, 11,
10, 11, 7, 8, 9, 6, 11, 7, 8, 9, 10,
3, 4, 5, 1, 2, 0, 4, 5, 1, 2, 3,
2, 3, 4, 5, 0, 0, 0, 4, 5, 1, 2
};
public static int[] invaderTypesLevel1
{
get { return InvaderTypesLevel1; }
set { InvaderTypesLevel1 = value; }
}
There are arrows to the top, bottom, left and right sides of the cube. These arrows dynamically change color to reflect the color the cube will change to if the player rotates the cube in one of the given directions. This is a massive help to the player as they can plan an attack strategy in advance, knowing where to move next.
There is an integer array in the Cube.cs class that holds the FaceID for each face of the cube, when the cube is rotated, the array is updated accordingly and in turn the FaceID variable is also updated. This FaceID variable is passed to the Screen.cs class which in turn updates the color of the cube. The FaceID is also passed to the Invader.cs class, where it is used in the Collision method. These statements only allow the invaders of a certain colour to be collideable with the player’s missiles. This is what makes for the game play to work so well. Code sample below;
private void Collision(CollisionRectangle overlap, CollideableSprite item)
{
if (item is ShipMissile && faceID == 1)
{
if (type == 0 || type == 6 || type == 12)
{
explosion1.Start(Position - PositionOffset[type]);
Reset();
invaders.InvaderHit(this);
Score();
Sound.PlayCue(InvadersSounds.GetCueName(SpaceInvaderSounds.InvaderExplosion));
}
}
}
The main adaption to the code went into the Invader.cs, InvasionForce.cs, PlayScreen.cs and TitleScreen.cs. In these classes, the game logic was altered to introduce the six different colors to the 3 types of space invaders in the invasion force. This was vital to the gameplay. All the assets for the game had to be created from either editing existing assets in the adapted Space Invasion project or creating new ones. The audio has remained the same.
The Render to Texture
To get the game mapped to each side of the cube we used render-to-texture. In the original development plan, we had thought about and discussed using viewports which could be mapped onto each side of the cube. However after further research it was discovered that this approach was incorrect due to limitations with viewports in general. The correct approach for this type of task was to render-to-texture. During the render-texture update, a colour was also passed as the background. This was a very interesting task and a task that we learned a great deal of information.
Colouring the faces of the Cube
To get the correct orientation of the cube to match the correct colour we created an integer array to store the current state. We set each index of the array to be a different side of the cube (Up, Down, Back, Forward, Left, Right). In the initialisation, this array contained the numbers 1-6, representing 6 different colours. When moving the cube we then moved around the indices of the array to different positions so that the numbers representing the colours were altered to the correct index. We then simply took the contents of the first element in the array which represented the front face of the cube and matched the number that represented the colour.
Controls (Xbox360 Controller Only)
Left Thumb Stick: Moves the ship in a left or right direction across the bottom.
A Button/Right Trigger: Fires the ships missiles.
D Pad: Moves the cube in Up, Down, Left or Right directions.
Start Button: Pause the game or Start the game.
Back Button: Exit the game.
