Browse Source

Added color, player tags, player tag script from Lachlan USB

master
Joshua Reason 9 years ago
parent
commit
27c5aceffc
33 changed files with 557 additions and 1 deletions
  1. BIN
      playable/Assets/Objects/P1.fbx
  2. BIN
      playable/Assets/Objects/P2.fbx
  3. BIN
      playable/Assets/Objects/P3.fbx
  4. BIN
      playable/Assets/Objects/P4.fbx
  5. BIN
      playable/Assets/Scenes/Level1.unity
  6. BIN
      playable/Assets/Scenes/Level2.unity
  7. BIN
      playable/Assets/Scenes/Level3 - Prototype.unity
  8. +4
    -0
      playable/Assets/Scenes/Level3 - Prototype.unity.meta
  9. BIN
      playable/Assets/Scenes/Menu_Scene.unity
  10. +5
    -0
      playable/Assets/Scripts/SpaceScripts.meta
  11. +65
    -0
      playable/Assets/Scripts/SpaceScripts/Gravitypull.cs
  12. +8
    -0
      playable/Assets/Scripts/SpaceScripts/Gravitypull.cs.meta
  13. +375
    -0
      playable/Assets/Scripts/SpaceScripts/spacePlayerController.cs
  14. +8
    -0
      playable/Assets/Scripts/SpaceScripts/spacePlayerController.cs.meta
  15. +2
    -0
      playable/Assets/Scripts/levelController.cs
  16. +14
    -0
      playable/Assets/Scripts/menuContrller.cs
  17. +2
    -1
      playable/Assets/Scripts/playerController.cs
  18. +34
    -0
      playable/Assets/Scripts/playerId.cs
  19. BIN
      playable/Assets/Shaders/Materials/blue.mat
  20. +4
    -0
      playable/Assets/Shaders/Materials/blue.mat.meta
  21. BIN
      playable/Assets/Shaders/Materials/green.mat
  22. +4
    -0
      playable/Assets/Shaders/Materials/green.mat.meta
  23. BIN
      playable/Assets/Shaders/Materials/pink.mat
  24. +4
    -0
      playable/Assets/Shaders/Materials/pink.mat.meta
  25. BIN
      playable/Assets/Shaders/Materials/yellow.mat
  26. +4
    -0
      playable/Assets/Shaders/Materials/yellow.mat.meta
  27. BIN
      playable/Assets/Shaders/blue.JPG
  28. BIN
      playable/Assets/Shaders/green.JPG
  29. BIN
      playable/Assets/Shaders/pink.JPG
  30. BIN
      playable/Assets/Shaders/yellow.JPG
  31. +24
    -0
      playable/Assets/sceneController.cs
  32. BIN
      playable/ProjectSettings/EditorBuildSettings.asset
  33. BIN
      playable/ProjectSettings/TagManager.asset

BIN
playable/Assets/Objects/P1.fbx View File


BIN
playable/Assets/Objects/P2.fbx View File


BIN
playable/Assets/Objects/P3.fbx View File


BIN
playable/Assets/Objects/P4.fbx View File


BIN
playable/Assets/Scenes/Level1.unity View File


BIN
playable/Assets/Scenes/Level2.unity View File


BIN
playable/Assets/Scenes/Level3 - Prototype.unity View File


+ 4
- 0
playable/Assets/Scenes/Level3 - Prototype.unity.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: 89904b1de13769a49a5159638a424160
DefaultImporter:
userData:

BIN
playable/Assets/Scenes/Menu_Scene.unity View File


+ 5
- 0
playable/Assets/Scripts/SpaceScripts.meta View File

@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 954ad14dfc3d1a647bd6ff7cad410071
folderAsset: yes
DefaultImporter:
userData:

+ 65
- 0
playable/Assets/Scripts/SpaceScripts/Gravitypull.cs View File

@ -0,0 +1,65 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Gravitypull : MonoBehaviour {
//public GameObject gravityWell;
//public float wellMass;
public int gravConstPow;
public
GameObject[] planets;
//public double gravConstant = 6.673f * Mathf.Pow(10,11);
// Use this for initialization
void Start () {
planets = GameObject.FindGameObjectsWithTag ("ground");
}
// Update is called once per frame
void Update () {
}
void FixedUpdate() {
foreach (GameObject planet in planets) {
rigidbody2D.AddForce( calcGrav (planet));
}
}
private Vector2 calcGrav(GameObject planet){
double gravConstant = 6.673f * Mathf.Pow(10,gravConstPow);
float gravityForce;
Vector3 distance = planet.transform.position - transform.position;
float r12 = distance.magnitude;
distance /= r12;
//Debug.Log ("distance: " + distance);
gravityForce = (rigidbody2D.mass * planet.rigidbody2D.mass * (float)gravConstant) / (r12 * r12);
//Debug.Log ("player mass: " + rigidbody.mass);
//Debug.Log ("well mass: " + wellMass);
//Debug.Log ("grav Const: " + (float)gravConstant);
//Debug.Log ("r12: " + r12);
//Debug.Log ("gravityForce: " + gravityForce);
Vector2 distance2D = new Vector2 (distance.x, distance.y);
Debug.Log ("force added: " + (distance2D * gravityForce));
return (distance2D * gravityForce);
}
}

+ 8
- 0
playable/Assets/Scripts/SpaceScripts/Gravitypull.cs.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6da08785e13ca0b4d94ee474b4cff7f3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 375
- 0
playable/Assets/Scripts/SpaceScripts/spacePlayerController.cs View File

@ -0,0 +1,375 @@
using UnityEngine;
using System.Collections;
using System.Collections.Generic; //input for lists
using UnityEngine.UI;
public class spacePlayerController : MonoBehaviour {
public string HorizontalBtn; //holds string for horizontal input
public string VerticalBtn; //holds string for Vertical input
public string StrongAttackBtn;
public string DashAttackBtn;
public Animator animator; //Holds animator for Pinata
public GameObject heart; //Health sprites
public GameObject newConfetti; //confetti when hit
public GameObject newCandy;
public stickController stick; //controller for stick
public GUIText scoreDisplay;
public GUIText gameOverDisplay;
public GameObject dashDisplay;
public GameObject playerFrac;
public GameObject Planet;
public float runSpeed; //run speed
public float jumpHeight; //jump height
public float health; //holds health
public int confettiOnHit; //amount of confetti created on hit
public Vector2 healthPos;
public float invulTime;
public float attackWait;
public bool isHit;
public float dashDistance;
public float dashTime;
public float dashWait;
public float minY;public bool heartBlack = false;
public bool heartColor = true;
public bool dead = false;
public float heartTimer = 0.0f;
private float displayedHealth = 3; //currently displayed health
private bool updateHealth = true; //if the health bar needs updating
private float curDirection = -1; //direction player is pointing
private bool canJump = true; // if player can jump
private bool canSpin = true; // if player can spin
private List<GameObject> hearts = new List<GameObject> (); //list which holds health sprites;
private bool isSpinning = false; //checks if player is spin attacking
private float lastHit;
private float lastAttack;
private int score;
private bool isDashing =false;
private bool canDash = true;
private float lastDash = 0.0f;
private bool stopDash = false;
public float deathTimer = 3.0f;
bool droppedCandy = false;
private bool exploded = false;
void Start(){
if (transform.rotation.y == 180)
curDirection = -1;
else
curDirection = 1;
}
// Update is called once per frame
void Update () {
displayHealth ();
death ();
applyPlayerDirection (Input.GetAxisRaw (HorizontalBtn));
damage ();
//if (transform.position.y < minY)
// health = 0;
if (score >= 10) {
gameOverDisplay.enabled = true;
gameOverDisplay.text = ""+ gameObject.name + " Wins";
Time.timeScale = 0;
}
dashDisplay.GetComponent<Scrollbar> ().size = (Time.time - lastDash) / dashWait;
Vector3 direction = transform.position - Planet.transform.position;
float tempRotZ = Vector3.Angle (Vector3.up, direction);
Vector3 tempRot = transform.rotation.eulerAngles;
if ((direction.x > 0 && transform.rotation.eulerAngles.y <10)|| (direction.x < 0 && transform.rotation.eulerAngles.y >170))
tempRot.z = 360 - tempRotZ;
else
tempRot.z = tempRotZ;
transform.rotation = Quaternion.Euler (tempRot);
}
void FixedUpdate() {
/*
* Movement inputs
*/
Vector2 velocity = transform.InverseTransformDirection(rigidbody2D.velocity);
if (transform.rotation.eulerAngles.y <10)
velocity.x = Input.GetAxis (HorizontalBtn) * runSpeed; //Horizontal input
else
velocity.x = Input.GetAxis (HorizontalBtn) * -runSpeed; //Horizontal input
if ((Input.GetAxisRaw (VerticalBtn) == 1) && (canJump)) //Vertical input
{
velocity.y = jumpHeight;
canJump = false;
}//end if
if (Input.GetAxisRaw (StrongAttackBtn)==1) {
if (!isSpinning && canSpin && Time.time - lastAttack > attackWait){
velocity.y = jumpHeight;
lastAttack = Time.time;
StartCoroutine (spinAttack (Vector3.down * 360, 0.2f));
}
}
if (Input.GetAxisRaw (DashAttackBtn) == 1) {
//Debug.Log ("dashbutton pressed");
if(!isDashing && canDash && Time.time - lastDash > dashWait){
lastDash = Time.time;
StartCoroutine (dashAttack (dashDistance,dashTime));
}
}
rigidbody2D.velocity = transform.TransformDirection(velocity); //apply inputs
animator.SetFloat("Velocity",velocity.magnitude);//inputs for animator
animator.SetBool ("Fall", !canJump);
}//end fixed update
private void displayHealth(){
if (displayedHealth != health) //check if health needs updating
updateHealth = true;
if (updateHealth){
foreach (GameObject desHeart in hearts) //Destroy all heart sprites
GameObject.Destroy (desHeart);
hearts.Clear(); //sets list to zero
for (int i=1; i<= health; i++) { //creates new heart sprite for each health
GameObject heartCanister = Instantiate (heart) as GameObject; //creat heart sprite
Vector3 heartPos = new Vector3 ();
//set position
if (healthPos.x == 1)
heartPos.x = (i * 0.033f);
else
heartPos.x = 1-(i * 0.033f);
if (healthPos.y == 1)
heartPos.y = 0.95f;
else
heartPos.y = 0.05f;
heartCanister.transform.position = heartPos;
hearts.Add(heartCanister); //adds heart to list
if (heartBlack == true && heartColor == false){
heartCanister.guiTexture.color = Color.black;
//else (heartCanister.guiTexture.color = Color.red);
}
}//end for
displayedHealth = health;
updateHealth = false;
}//end if
}//end displayHealth
//respawns player if they die
private void death()
{
if (health <= 0|| dead ==true) {
dead = true;
if (dead == true){
heartColor = false;
heartBlack = true;
heartTimer += Time.deltaTime;
if (heartTimer >=1.5f){
health = 1;
}
if (heartTimer >=2.5f){
health = 2;
}
if (!exploded){
exploded = true;
Vector3 fracRotation = transform.rotation.eulerAngles;
fracRotation.y +=90;
GameObject explosion = Instantiate (playerFrac, transform.position+(Vector3.up*-3), Quaternion.Euler(fracRotation)) as GameObject;
}
}
if (deathTimer > 0) {
deathTimer -= Time.deltaTime;
if (!droppedCandy) {
Instantiate (newCandy, transform.position + Vector3.up, transform.rotation);
Debug.Log ("Exploded position: " + transform.position);
droppedCandy = true;
}
transform.position = new Vector3 (10, -50, 0);
if (deathTimer <= 0) {
Vector3 spawnPos = new Vector3 (Random.Range (-20.0f, 20.0f), 15.0f, 0); //picks random position
health = 3; //resets life
transform.position = spawnPos; //changes position
rigidbody2D.velocity = Vector2.zero;
deathTimer = deathTimer + 3.02f;
heartTimer = heartTimer - 3.00f;
droppedCandy = false;
heartBlack = false;
dead = false;
heartColor = true;
exploded = false;
}
}//end if
/*else if (hearts <= 0) {
dead = true;
}*/
}//end death
}
private void applyPlayerDirection(float moveHorizontal)
{
if ((curDirection != moveHorizontal) && (moveHorizontal != 0) && !isSpinning) //if player movement direction vs displayed direction
{
transform.Rotate(0,180,0); //rotates player
curDirection = moveHorizontal; //updates direction
}
}
private void damage (){
if (isHit) {
gameObject.GetComponentInChildren<PolygonCollider2D> ().enabled = false;
isHit = false;
lastHit = Time.time;
}
if (lastHit+invulTime < Time.time)
gameObject.GetComponentInChildren<PolygonCollider2D> ().enabled = true;
}
//spin
IEnumerator spinAttack(Vector3 byAngles, float inTime) {
isSpinning = true;
canSpin = false;
stick.isAttacking = true;
Debug.Log ("" + gameObject.name + "spinning");
Quaternion startAngle = transform.rotation;
Quaternion endAngle = Quaternion.Euler(transform.eulerAngles + byAngles);
float direction = transform.eulerAngles.y;
for(float i = 0; i < 1; i += Time.deltaTime/inTime) {
transform.rotation = Quaternion.Euler(0,direction,Mathf.Lerp(transform.eulerAngles.z,transform.eulerAngles.z + 360,i));
yield return null;
}
transform.eulerAngles = new Vector3 (0,direction,0);
//Debug.Log ("" + gameObject.name + "End spin");
isSpinning = false;
stick.isAttacking = false;
}
//dash
IEnumerator dashAttack (float dashDistance,float dashTime) {
float endPosition;
int dashDirection;
isDashing = true;
canDash = false;
stick.isAttacking = true;
Debug.Log ("" + gameObject.name + "Dashing");
rigidbody2D.gravityScale = 0;
Vector3 startPosition = transform.position;
//Debug.Log ("rotation Y: " + transform.eulerAngles.y);
if (transform.eulerAngles.y >= 150)
dashDirection = -1;
else
dashDirection = 1;
endPosition = startPosition.x + (dashDirection * dashDistance);
//Debug.Log ("Dash start: " + startPosition.x);
//Debug.Log ("Dash Direction: " + (dashDirection ));
//Debug.Log ("Dash end: " + endPosition);
for (float i = 0; i < 1; i += Time.deltaTime/dashTime) {
transform.position = new Vector3(dashDirection * Mathf.Lerp((dashDirection)*startPosition.x, (dashDirection)* endPosition, i), startPosition.y, startPosition.z);
if ((transform.position.x < -30.5f && dashDirection == -1) || (transform.position.x > 26.5 && dashDirection == 1))
stopDash = true;
if (stopDash)
break;
yield return null;
}
stopDash = false;
isDashing = false;
canDash = true;
stick.isAttacking = false;
//Debug.Log ("" + gameObject.name + " finished Dashing");
rigidbody2D.gravityScale = 4;
}
void OnCollisionEnter2D(Collision2D col){
if (col.collider.tag == "ground") {
canJump = true;
canSpin = true;
}
else if (col.collider.tag == "Player") {
canJump = true;
canSpin = true;
}
if (col.collider.tag == "wall") {
stopDash = true;
}
if (col.collider.tag == "failBox") {
health = 0;
}
}
void OnTriggerEnter2D(Collider2D trig)
{
Debug.Log (trig.gameObject.tag);
if (trig.gameObject.tag == "candy")
{
Destroy (trig.gameObject, 0.0f);
score++;
scoreDisplay.text = "score: " + score.ToString ();
}
}
}

+ 8
- 0
playable/Assets/Scripts/SpaceScripts/spacePlayerController.cs.meta View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9c07795f9df4e4948ba0e2f7e1618aa5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

+ 2
- 0
playable/Assets/Scripts/levelController.cs View File

@ -4,6 +4,8 @@ using System.Collections;
public class levelController : MonoBehaviour {
public int playerCount;
public int maxScore;
public int confetti;
public static levelController control;

+ 14
- 0
playable/Assets/Scripts/menuContrller.cs View File

@ -10,6 +10,8 @@ public class menuContrller : MonoBehaviour {
public GameObject btn_2player;
public GameObject btn_3player;
public GameObject btn_4player;
public GameObject txt_score;
public GameObject txt_confetti;
public levelController control;
// Use this for initialization
@ -61,4 +63,16 @@ public class menuContrller : MonoBehaviour {
}
public void scoreChange (float score){
txt_score.GetComponent<Text> ().text = "" + Mathf.RoundToInt(score);
control.maxScore = Mathf.RoundToInt (score);
}
public void confettiSlider (float confetti){
txt_confetti.GetComponent<Text> ().text = "" + Mathf.RoundToInt(confetti);
control.confetti = Mathf.RoundToInt (confetti);
}
}

+ 2
- 1
playable/Assets/Scripts/playerController.cs View File

@ -35,6 +35,7 @@ public class playerController : MonoBehaviour {
public bool heartColor = true;
public bool dead = false;
public float heartTimer = 0.0f;
public int maxScore = 10;
@ -78,7 +79,7 @@ public class playerController : MonoBehaviour {
//if (transform.position.y < minY)
// health = 0;
if (score >= 10) {
if (score >= maxScore) {
gameOverDisplay.enabled = true;
gameOverDisplay.text = ""+ gameObject.name + " Wins";
Time.timeScale = 0;

+ 34
- 0
playable/Assets/Scripts/playerId.cs View File

@ -0,0 +1,34 @@
using UnityEngine;
using System.Collections;
public class playerId : MonoBehaviour {
public bool idVanish = true;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
transform.eulerAngles = new Vector3 (transform.eulerAngles.x, 180, transform.eulerAngles.z);
if (Input.GetKeyDown (KeyCode.Backspace)) {
idVanish = true;
if (idVanish) {
transform.position = new Vector3 (transform.position.x, -100, transform.position.z);
idVanish = false;
Debug.Log ("player ID true");
}
}
if (Input.GetKeyDown (KeyCode.Backspace) && idVanish == false) {
transform.position = new Vector3 (transform.position.x, 100, transform.position.z);
idVanish = true;
}
}
}

BIN
playable/Assets/Shaders/Materials/blue.mat View File


+ 4
- 0
playable/Assets/Shaders/Materials/blue.mat.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: e656641419a3c314991212036e1accef
NativeFormatImporter:
userData:

BIN
playable/Assets/Shaders/Materials/green.mat View File


+ 4
- 0
playable/Assets/Shaders/Materials/green.mat.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: d4f5793b59b43604bbf2aa00e5300a95
NativeFormatImporter:
userData:

BIN
playable/Assets/Shaders/Materials/pink.mat View File


+ 4
- 0
playable/Assets/Shaders/Materials/pink.mat.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: fc80d43c16d868f4e932cb12d1a7e960
NativeFormatImporter:
userData:

BIN
playable/Assets/Shaders/Materials/yellow.mat View File


+ 4
- 0
playable/Assets/Shaders/Materials/yellow.mat.meta View File

@ -0,0 +1,4 @@
fileFormatVersion: 2
guid: bfdf8ba55ca8d294196d058459087c47
NativeFormatImporter:
userData:

BIN
playable/Assets/Shaders/blue.JPG View File

Before After
Width: 432  |  Height: 895  |  Size: 14 KiB

BIN
playable/Assets/Shaders/green.JPG View File

Before After
Width: 432  |  Height: 885  |  Size: 14 KiB

BIN
playable/Assets/Shaders/pink.JPG View File

Before After
Width: 428  |  Height: 884  |  Size: 14 KiB

BIN
playable/Assets/Shaders/yellow.JPG View File

Before After
Width: 426  |  Height: 820  |  Size: 13 KiB

+ 24
- 0
playable/Assets/sceneController.cs View File

@ -9,7 +9,21 @@ public class sceneController : MonoBehaviour {
public GameObject player4;
public levelController control;
private int playerCount;
private playerController playerScript1;
private playerController playerScript2;
private playerController playerScript3;
private playerController playerScript4;
// Use this for initialization
void Awake(){
playerScript1 = player1.GetComponent<playerController> ();
playerScript2 = player2.GetComponent<playerController> ();
playerScript3 = player3.GetComponent<playerController> ();
playerScript4 = player4.GetComponent<playerController> ();
}
void Start () {
control = GameObject.FindGameObjectWithTag ("GameController").GetComponent<levelController> ();
@ -28,6 +42,16 @@ public class sceneController : MonoBehaviour {
if (playerCount >= 4)
player4.SetActive (true);
playerScript1.maxScore = control.maxScore;
playerScript2.maxScore = control.maxScore;
playerScript3.maxScore = control.maxScore;
playerScript4.maxScore = control.maxScore;
playerScript1.confettiOnHit = control.confetti;
playerScript2.confettiOnHit = control.confetti;
playerScript3.confettiOnHit = control.confetti;
playerScript4.confettiOnHit = control.confetti;

BIN
playable/ProjectSettings/EditorBuildSettings.asset View File


BIN
playable/ProjectSettings/TagManager.asset View File


Loading…
Cancel
Save