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. 

Sunday, February 23, 2014

Main Screen Complete

Main Menu is more or less done there just detail like word lining that doesn't really matter with functionality of the game so I'm not going to bother with it too much.

also complete the credit screen


There minor detail that is not quite in place like spacing etc, but that is not very important so I'm not going to focus on that too much

Tuesday, February 18, 2014

GUI element

GUI stand for graphical user interface
which is an on screen information or something user can interact with common example is the start mean

in this cause we making a simple text GUI to display the information like Time, Live and scores





Without GUI


With GUI




Now you can conveniently see the info without having to stare at the console.

we also work on the timer and lives so that the number subtract every time you get hit and the timer countdown



Scores Managing system

Now that we have the basic component going we need to find a way to keep track of scores and time.
Since all the asset we made up until now can get destroy at some point (astroid get destroy when hit by bullet, Player get destroy when hit by astroid) etc. we need to make a new "object" to store the scores information  separately.

So I make an empty game object (which is pretty much an invisible object) and create new script for it and it will be our scores manager.
Scene manager Script

This code is pretty much telling the console to print the scores +1 every times bullet hit the astriod

 Then add this script to the bullet to tie them together.


Here is the result the console will tell us the scores every time we hit an enemy  

Code problem resolve!

Well so the past two day I been stuck on a part of code where player lives should decrease every time it hit an asteroid it haven't been working correctly after consulting my mentor still can't figure it out so I seek help from online community forum. That didn't work either so I just rewrite that part of the script this morning and now it just magically work O-O I have not idea what I did but guess it work now and I will be unloading my current script on to google drive or something so if software crash I would not lose them... agian.

Sunday, February 16, 2014

Half way there

Halfway there minor problem with code it should be fine but my computer keep crashing I wonder why and it very frustrating

Sunday, February 2, 2014

Major issues

A few day ago I got a new computer with different OS (Window 8) and Today when I'm goign to work on my project. I was unable to open it. It said something along the line of "device unsupported" so I don't know what to do right now I may have to restart the whole thing again which if they happen I may not get it done before dead line. Although I should have the back up file at school....

Really stressing right now and still try to see if there any solution to this problem.

I want to cry T - T 2 month of work gone just like that..... oh technology....

Monday, January 20, 2014

After Final

Finally final is over. which mean more time for this project yay, but the due date is approaching fast so now that I can, I will put in more time for this project. I'm half way through the project and it shouldn't be too difficult from here on out.

 I was going to do some work today (since no school) but it was my cousin birthday I we were out all day and after we came back it was already late so all I did today was uninstall unity and downloaded the new version because after taking the file to school, which use newer version of unity it can no longer be open with older version so that done took about an hour because have network error during download so glad that over.Perhaps will get some work done tomorrow.

Specification problems - pondering -

I feel like specification is the hardest thing about this project. Everything I set just doesn't seem to fit with what my supervisor suggested. to be honest I guess I don't really understand the purpose of the specification yet. I understand that it suppose to help you be on track and all, but for example

let say my specification was" work on project 2 hours a week" and let say you was unable to complete it like once because something came up. this just make you fail the specification even if your project continue at the expected pace?

Maybe I could change it to "work on project 2 hour a week IF fail to do so add the remaining time to next week"

but then it could stack up......

this is frustrating... I wonder what everyone else wrote for their specification :P

*Note to self*

- ask people advice for specification
- keep track of time I work on the project each day

Saturday, January 4, 2014

Space Shooter Day 8

today I learn about the tag function in Unity which make object organization and scripting a little bit easier

How ever I am having problem with getting the new part of the script to work. What I wrote is a script that will write a "string" which is a set of words when bullet hit an asteroid. However it seem that the script is correct because I was able to test in game mode just fine but the string is not printing like it suppose to
so my hypothesis is :
1. the bullet is not hitting the asteroid
or
2. Some in game function, setting is not set correctly

I been tackling this problem for a while now but it doesn't seem to be working so I'll continue next time if problem is unresolved i might skip it because this is minor detail and is not really needed for this game to be complete.

this code use a new function instead of function update it change to function OnTriggerEnter  (other : Collier)
which is a function use with object with rigid body to created interaction. In this case below is saying if the bullet (this is a bullet's script) hit an object with a tag name "astroid" then the object with the tag will reappear on the top at random x-axis. 

I couldn't find anything wrong with the script but it doesn't seem to be working so i'm looking into that.