Sunday, March 9, 2014

game description

//Learning Objective:
// -File and Assets managment
// -Basic game scripting
// -GUI element
// -Input
// -Events
// -Scene Loading


//Game Concept:
// Space shooter where player must avoid astroids from detryoing their ship
//  as they try to score as many point as they can by shooting the astroid in a given amount of time

//Control:
// Arrow keys to move (4 directions: up, down, left, right)
// spacebar to shoot
// e to creates a temporary shield

// Assets:
// - Player
// - Astroid
// - Bullet
// - Shield
//  - Blocker
//  - Explosion

Asset list


Credit Screen

// Credit Screen

// Inspector Variables

//

function OnGUI ()
{
// Make a group @ center of screen
GUI.BeginGroup(Rect (Screen.width/2-100,Screen.height/2-100,200,200));

// make box to see the group on screen
GUI.Box(Rect(0,0,200,200),"Credit");

//Credit
GUI.Label(Rect(10,40,210,50),     "By :  Kulprawee Prayoonsuk");
GUI.Label(Rect(10,70,200,80),     "Tutorial by WalkerBoyStudio ");
GUI.Label(Rect(10,100,200,110),   "Special Thank to  Alex Caswell");
GUI.Label(Rect(10,130,200,140),   "Mentor : Mr. Dan Cornell");
// Add BUttons here
if (GUI.Button(Rect(60,165,80,30),"Back"))
{
Application.LoadLevel("ScreenMainMenu");
}


// End group
GUI.EndGroup();
}

Lose Screen Script

// Lose Screen Script

// Inspector *Script attach to main camera
var loseQuote : String = "You Lose";

//
function OnGUI ()
{
// Make a group @ center of screen
GUI.BeginGroup(Rect (Screen.width/2-100,Screen.height/2-100,200,200));

// make box to see the group on screen
GUI.Box(Rect(0,0,200,100),loseQuote);

//Scores
GUI.Label(Rect(10,30,100,50),"Score:"+PlayerPrefs.GetInt("SCORE"));

//Back to main button
if(GUI.Button(Rect(60,60,80,30), "Main Menu"))
{
Application.LoadLevel("ScreenMainMenu");
}


// End group
GUI.EndGroup();
}

Win Screen Script

// Win Screen Script

// Inspector *Script attach to main camera
var winQuote : String = "You WIN!";

//
function OnGUI ()
{
// Make a group @ center of screen
GUI.BeginGroup(Rect (Screen.width/2-100,Screen.height/2-100,200,200));

// make box to see the group on screen
GUI.Box(Rect(0,0,200,100),winQuote);

//Scores
GUI.Label(Rect(10,30,100,50),"Score:"+PlayerPrefs.GetInt("SCORE"));
//Back to main button
if(GUI.Button(Rect(60,60,80,30), "Main Menu"))
{
Application.LoadLevel("ScreenMainMenu");
}


// End group
GUI.EndGroup();
}

Load Screen Script

// Load Screen Script

// Inspector Variables
var waitTime : float = 3.0;

//
function Update ()
{
if(Input.GetKeyDown("space"))
{
Application.LoadLevel("Level1");
}
else
{
Waittime();
}
}

function OnGUI ()
{
// Make a group @ center of screen
GUI.BeginGroup(Rect (Screen.width/2-100,Screen.height/2-100,200,200));

// make box to see the group on screen
GUI.Box(Rect(0,0,200,200),"Instructions");

//Instructions for player
GUI.Label(Rect(10,30,140,40),"Arrow Keys to Move");
GUI.Label(Rect(10,60,160,70),"Spacebar to Shoot");
GUI.Label(Rect(10,90,180,100),"E to create a temporary shield");
GUI.Label(Rect(10,120,200,100),"Esc to Quit the Game");

GUI.EndGroup();
}

function Waittime()
{
yield WaitForSeconds(waitTime);
Application.LoadLevel("Level1");
}

Main Menu Script

// Main Menu Script

// Inspector Variables

function OnGUI ()
{
// Make a group @ center of screen
GUI.BeginGroup(Rect (Screen.width/2-50,Screen.height/2-50,100,175));

//Make a box to see group on screen
GUI.Box(Rect(0,0,100,175),"Main Menu");

//Add buttons for game navigation
if (GUI.Button(Rect(10,30,80,30),"Start Game"))
{
Application.LoadLevel("ScreenLoad");
}
if (GUI.Button(Rect(10,65,80,30),"Credits"))
{
Application.LoadLevel("ScreenCredit");
}
if (GUI.Button(Rect(10,100,80,30),"Exit"))
{
Application.Quit();
}
if (GUI.Button(Rect(10,135,85,30),"Project Blog"))
{
Application.OpenURL("http://celosiaproject.blogspot.com/");
}

GUI.EndGroup();
}

Scene Manager Script

// Scene Manager Script

// Inspector Variables
var gameTime :float = 60;
static var score : int = 0;
static var lives : int = 3;
var labelRight : float = 100;

// Private Variables
function Start()
{
InvokeRepeating("CountDown",1.0,1.0);
}
//Game Loop
function Update ()
{
if(lives <0)
{
Application.LoadLevel("ScreenLose");
// reset player's life
lives = 3;
//display score in lose screen
PlayerPrefs.SetInt("SCORE",score);
}

if(gameTime <= 0)
{
Application.LoadLevel("ScreenWin");
lives = 3;
PlayerPrefs.SetInt("SCORE",score);
}

// Print Score
print("Score:"+score);
}

function AddScore() // everytime this function is call add +1 to the score
{
score+=1;
}

function SubtractLife()
{
lives -=1;
}

function CountDown()
{
if (--gameTime ==0)
{
CancelInvoke("CountDown");
}

}
// GUI label
function OnGUI ()
{
GUI.Label(Rect(10,10,100,20),"Score:"+score); //(left,top,width,height)
GUI.Label(Rect(10,25,100,35),"Live:"+ lives);
GUI.Label(Rect(Screen.width - labelRight,10,100,20), "Counter:"+ gameTime);
}

Shield Script

// Shield Script

//Inspector variables
var shieldStrength: int = 3;

//Private variables

function OnTriggerEnter (other : Collider)
{
if (other.tag =="astroid")
{
shieldStrength -= 1;
}
}

function Update ()
{
if(shieldStrength <= 0)
{
Destroy(gameObject);
}
}

Bullet script

//bullet script

//Inspector variables
var bulletSpeed : float = 15.0;   // Speed of bullet
var bulletLimit : float = 10.0;   // where will bullet dissapear
var explosion   : Transform;
var sceneManager: GameObject;   // load manager script for scoring

//Private Variable

// Game loop
function Update ()
{
 transform.Translate(0,bulletSpeed*Time.deltaTime,0);

 // check if object is off screen
 if (transform.position.y>= bulletLimit)
  {
  Destroy (gameObject);
  }
}
function OnTriggerEnter (other :Collider)
{
// check for asteriod
if (other.gameObject.tag =="astroid")
   
{

//reset enermy position
other.transform.position.y = 10.0;
    other.transform.position.x = Random.Range(-10,10);
   
    // explosion on impact
    if (explosion)
    {
    Instantiate (explosion,transform.position,transform.rotation);
    }
    // Tell score manager that enery is destroy and to add a point
sceneManager.transform.GetComponent("ScriptSceneManager").AddScore();


// get rid of the bullet after it hit a target
Destroy (gameObject);

}
}

Astroid script

//Astroid script

 //Inspector variables
 var astroidSpeed : float = 15.0;
 var explosion    : Transform;
 var sceneManager : GameObject;

 //Private Variable

 // Game loop
 function Update ()
{
   transform.Translate(Vector3.down*astroidSpeed*Time.deltaTime); // vector3.down = move object down on y axis
 
  // make astriod re appear at the top when it hit the bottom
  if(transform.position.y <= -10)
  {
    // reset enermy position
    ResetEnermy();
  }
}

function OnTriggerEnter (other : Collider)
{
if(other.gameObject.tag == "Player")
{

 other.GetComponent("ScriptPlayer").lives -=1;  // get component to get component of other source

 // Tell score manager that we lost a life
sceneManager.transform.GetComponent("ScriptSceneManager").SubtractLife();
   if (explosion)
 {
  Instantiate(explosion,transform.position,transform.rotation); //explosion will be created at astriod location
 }
 // Reset enermy position
ResetEnermy();
}
if(other.gameObject.tag == "shield")
{
if(explosion)
{
Instantiate(explosion,transform.position,transform.rotation);
}
ResetEnermy();
}
}

function ResetEnermy()
{
//Reset Enermy position
transform.position.y = 15;
    transform.position.x = Random.Range(-10,10);
}

Player Script

//Player script

//Inspector variables
var lives                     : int = 3;                       // Player life
var playerSpeedHorizontal     : float = 10.0;             // Player speed on x axis
var playerSpeedVertical       : float = 10.0;             // Player speed on y axis
var horizontalMin             : float = -10;              // limit left
var horizontalMax             : float = 10;               // limit right
var VerticalMin               : float = -10;              // limit down
var VerticalMax               : float = 10;               // limit up
var bullet                    : Transform;
var socket                    : Transform;
var numberofShields  :int = 4;                   // number of shield
var shieldMesh                : Transform;                    
var shieldKeyInput            :KeyCode;                  

//Private variables
private var shieldOn  :boolean = false;

// loop / repeat
function Update ()
{
 //Input Variables
 var transV : float = Input.GetAxis("Vertical")*playerSpeedVertical*Time.deltaTime;        //store varible for verticle movement
 var transH : float = Input.GetAxis("Horizontal") *playerSpeedHorizontal*Time.deltaTime;   // store variable for horizontal movement

//move player base on input
transform.Translate(transH,transV,0);   // x = left and right & y = up and down

//player position limit

transform.position.x=Mathf.Clamp(transform.position.x,horizontalMin,horizontalMax);       // limit to the left and right

transform.position.y=Mathf.Clamp(transform.position.y,VerticalMin,VerticalMax);           // limit for up and down

//Bullet
if(Input.GetKeyDown("space"))
 {
Instantiate(bullet,socket.position,socket.rotation);
 }

  // Create shield
 if(Input.GetKeyDown(shieldKeyInput))
 {
  if (!shieldOn) // no more shield can be created if the current one still exist
  {
var clone = Instantiate(shieldMesh,transform.position,transform.rotation);
clone.transform.parent = gameObject.transform;    // parent the object to selected object
shieldOn = true;
}
 }
}

Saturday, March 8, 2014

Function complete

So my game is now fully functional the only thing missing is the artistic aspect which is not what I'm focusing on so it doesn't matter,




Here what the game look like ( unfortunately there no way I could upload a moving picture but this is pretty much what it look like.