Category: Project

Today you will start designing your own version of the Breakout game based on the example we built together in class.

Game Design Document:

You will turn in a Game Design Document for your game. You need to include the following information:  Due Friday Dec 6 for 2 formative grades

  • What is the name of your game – Be creative!
  • What is the setting and theme for your game (space, wild west, past, future etc…)
  • What is the story of your game?  Why are we breaking blocks?
  • Draw out the GUI for your menu/welcome screen
  • Draw out the GUI for your instructions screen
  • Draw out the layout for all your levels (show the placement for all blocks and GUI)
  • For each level describe how this level advances the story, what power-ups will be used, what types of bricks will be used, background music, sound effects, particle systems, and any special features, events, or special effects.

Working/Published Game Due Friday December 13:  Semester Final Exam Grade

  • Minimum Requirements (80% Max Score)
    • Menu Screen (start, restart, quit)
    • Instructions Screen
    • 2 Levels
    • 3 different power-ups
    • 2 different types of bricks
    • Game clearly reflects the story and theme
  • To score a max of 90%
    • 3 Levels
    • 5 power-ups
    • 3 different bricks
    • Game clearly reflects the story and theme
  • To score a max of 100% add at least one of the following
    • Keep track of high scores ( check out playerprefs)
    • Add a 4th level
    • Add a 6th power-up
    • Add a 4th brick type
    • If you have other ideas or features talk to me about them for approval.

You will be playing each others completed games on your Semester Final Exam day – summative grade based on peer feedback.

Theme and story are very important for this project.  Be creative!  Show me what you can do!

Now we are going to create the paddle and make it controllable with the keyboard.

Make a new cube and name it Paddle.  Change the scale X to 6 to make it 6 units wide.  Make sure that it is located at 0 on the Z axis and drag it down towards the bottom of the screen (around -18 y).

Now we need to make the paddle move left and right when we push the left and right arrow keys or the a and d keys.

Using Input.GetAxis

To make the paddle move we are going to make use of Unity’s input manager.  Go to Edit on the top menu bar and select Project Settings then Input.  In the Inspector you will see the Input Manager.  Open the Axis area and you will see several prebuilt controls.  The one we want is Horizontal.  This one is already set up to work with the keys we want to use.  To access this from our script we need to use the Input.GetAxis command in our update function.

Input.GetAxis(“Horizontal”) will return a float between -1 and 1 depending on which keys are being pressed.

If we plug this into our transform.Translate command we can control the direction of movement.

transform.Translate(Input.GetAxis(“Horizontal”), 0,  0);

This will move the paddle to the left and right based on the keys pressed.  Now we need to convert this to time based movement and put in a speed variable.

transform.Translate(Input.GetAxis(“Horizontal”) * speed * Time.deltaTime, 0,  0);

Now we just block the paddle at the screen edges by setting the x position to the boundary when trying to push past it.

Now that the scene is setup, we can add the ball.  The ball needs to bounce off the edges of the screen on the left, right, and top.  If it goes off the bottom then a life will be lost.  When we add the paddle, the ball will also bounce off of that.

To make the ball we will create a sphere.  Go to Hiarchy – click create – sphere.  Position the sphere at 0,0,0 and rename the sphere as Ball.

Next we need a script file to control the ball.  Make a new javascript and name it Ball.  Attach the Ball script to the ball object and open it in the script editor.

Now we will make the ball move using transform.Translate.

Transform.Translate

This command will move an object by directly changing its x,y,z coordinates.

In the ball script file in the update function type in the command:

transform.Translate(0,1,0);

The numbers in the parenthesis make what is called a Vector3.  A Vector3 is a variable type that holds an x,y,z.  So in the command above we told the computer to move that ball 0 on the x, 1 on the y, and 0 on the z axis.  This will cause the ball to move up on the y axis by 1 every frame.

Frame Based Movement Vs Time Based Movement

Currently we are moving the ball one every frame.  This can cause some issues as frame rate is not consistent.  It is much better to move objects an amount over one second of time.  To do this we just need to add the time factor to our command.  Change the code to this:

transform.Translate(0, 1 * Time.deltaTime, 0);

This takes our movement and takes it times deltaTime.  DeltaTime is the amount of time that has passed since the last frame was drawn.  This changes the movement so that the ball moves up at one unit per second.

To make the ball move faster we will change the one to a variable and set it to a bigger number as follows:

var speed:int = 10;

We will then change our command to:

transform.Translate(0, speed * Time.deltaTime, 0);

Now the ball will move up 10 over a second of time.

Moving on the x and y axis

To handle moving on both the x and y axis we are going to use a Vector3 variable to hold the direction we want he ball to move.

Make a variable as follows:

var direction:Vector3 = Vector3(-1,1,0);

This is a Vector3 variable that holds an x,y,z amount.  Now we will use this variable to control the direction the ball is moving on the x and y axis.

transform.Translate(direction * speed * Time.deltaTime);

Now we are moving the ball 10 units up and 10 units left every second.

You will notice that a negative value in the x will cause the ball to move left and a positive value will make it move right.

A negative value in the y will move the ball down and a positive up.

Making the Ball Bounce Off the Edges

Now that we know how to move the ball and change it’s direction, we can make the ball bounce off of the screen edges.

The first step is to figure out where the edges of the screen are on the left, right, top, and bottom.  To do this drag the ball to the edges of the screen in your scene view and look at the position numbers in the inspector.  Make variables to hold these boundary numbers.

Example: var topBoundary:float = 19.5;

Now in the update function we need to check to see if the ball is passing any of these boundaries.

if(transform.position.y >= topBoundary)

{

direction.y *= -1;

}

Here we checked if the ball’s y coordinate was greater than or equal to the top boundary.  If it was then we took the direction Vector3 variable’s y number and multiplied it by a -1.  This will cause the sign to change from a positive to a negative.  A negative y will cause the ball to move down.  This is how we change the direction of the balls movement.

Do this for the left and right boundaries as well.

If the ball get below the bottom boundary a life is lost and we need to reset it to start again.

In this post we will go over how to setup our project.

This is a 2D game so we need to setup our camera to  view our objects in a 2D way.  Here are the steps:

  1. Click on the camera and in the inspector click on projection and change it to Orthographic.
    • Orthographic changes the way the camera sees your objects.  Instead of looking at them in a perspective view it flattens them out so we see just the side facing us straight on.
  2. Now we have to define how much space we want the camera to see.  In the inspector change the position to x = 0, y = 0, z = -10.
    • This puts our camera right in the middle of our screen and pulls in back 10 units.  We are defining the 2D plane that we want the camera to look at.
  3. Change the size to 20 and the far to 15.
    • The size defines the dimension of the rectangle that we are looking at in the x,y plane.
    • Far tell the camera how many units to look into.  If an object is farther away from the camera then 15 units in will not be visible.

What we have done is define a 2D space on which our game will be played.  Make sure your camera settings match the screen shot below.

Camera Inspector

Our game is going to take place on the x,y plane located at 0 on the z axis.  It is very important to make sure that all of our game objects always stay at a z = 0 coordinate.

Now we are ready to start adding our Game Objects.  Make sure to save the scene with the name Level1.

After completing the Reverse Guessing Game you will start on this project.

This will be our 2D game project.  We will be remaking the classic game Breakout.  You can find out about this game’s history here Breakout History.

By the end of this project you will be able to:

  • Make objects move using Transform.translate
  • Setup a 2D Orthographic camera
  • Bound the edges of the screen
  • Setup and use triggers for collision detection
  • Have one game object get components from another one
  • Load and unload levels
  • Add materials and textures
  • Instantiate objects from prefabs
  • Make simple particle effects
  • Add music and sound effects

We will be breaking this project down into several small chunks – It will be up to you to keep up and come in for extra help as needed.

After you get the Number Guessing Game finished, you will start working on Level 1.5 Game.

Level 1.5 will be due no later than November 1st and will count as a summative grade.

In this game the player will think of a number and the computer will guess it.

Requirements:

  • The computer will give an initial guess and then the player will press a button to tell the computer if it guessed too low, too high, or correct.
  • The computer must be able to guess any number within 10 guesses.
  • When the game is over the player will have the option to quit or play again.

Here is a link to my example so you can see how it should work:  Computer Guess My Number Game

Start by flow charting the game and thinking through the math needed for the computer to make an intelligent guess.