Skip to content

Commit

Permalink
added menu scene, transition between rounds
Browse files Browse the repository at this point in the history
  • Loading branch information
qcmx16 committed Nov 5, 2018
1 parent 4e7c322 commit 34762fa
Show file tree
Hide file tree
Showing 9 changed files with 570 additions and 92 deletions.
119 changes: 119 additions & 0 deletions Blockade/Assets/BackgroundScript.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class BackgroundScript : MonoBehaviour {

public GameObject gridBlock;


public Sprite green;
public Sprite black;

public Vector3 direction;
public Vector3 direction2;
public static Vector3 current;
public static Vector3 current2;

public float timer = 0f;

static GameObject[,] grid = new GameObject[100, 100];


// Use this for initialization
void Start()
{
for (int i = -50; i < 50; i++)
{
for (int j = -50; j < 50; j++)
{
grid[i + 50, j + 50] = Instantiate(gridBlock, new Vector3((i + 0.5f), (j + 0.5f)), Quaternion.identity);
}
}

for (int i = 0; i < 100; i++)
{
grid[0, i].GetComponent<SpriteRenderer>().sprite = green;
grid[i, 0].GetComponent<SpriteRenderer>().sprite = green;
grid[99, i].GetComponent<SpriteRenderer>().sprite = green;
grid[i, 99].GetComponent<SpriteRenderer>().sprite = green;
}


current = new Vector3(25f, 75f);
current2 = new Vector3(75f, 25f);
direction = new Vector3(0, -1);
direction2 = new Vector3(0, 1);

}

// Update is called once per frame
void Update()
{
timer += Time.deltaTime;
//Debug.Log(current);
//Debug.Log(current2);
if (timer >= 0.3f)
{
timer = 0;
current += direction;
current2 += direction2;
grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite = green;
grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite = green;

}

int r = Random.Range(0, 3);
int r2 = Random.Range(0, 3);

if (r == 0)
{
direction = new Vector3(0, 1f);
}
if (r == 1)
{
direction = new Vector3(-1f, 0);
}
if (r == 2)
{
direction = new Vector3(0, -1f);
}
if (r == 3)
{
direction = new Vector3(1f, 0);
}

if (r2 == 0)
{
direction2 = new Vector3(0, 1f);
}
if (r2 == 1)
{
direction2 = new Vector3(-1f, 0);
}
if (r2 == 2)
{
direction2 = new Vector3(0, -1f);
}
if (r2 == 3)
{
direction2 = new Vector3(1f, 0);
}


//Debug.Log(current.x);

//grid[(int) current.x, (int) current.y].GetComponent<SpriteRenderer>().sprite = green;

if (Input.GetKeyDown("1"))
{
SceneManager.LoadScene("BlockadeScene", LoadSceneMode.Single);
}


}



}
11 changes: 11 additions & 0 deletions Blockade/Assets/BackgroundScript.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

171 changes: 117 additions & 54 deletions Blockade/Assets/Blockade.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Blockade : MonoBehaviour {

Expand All @@ -11,8 +12,8 @@ public class Blockade : MonoBehaviour {
public TextMesh s1;
public TextMesh s2;

public static Sprite green;
public static Sprite black;
public Sprite green;
public Sprite black;

public Vector3 direction;
public Vector3 direction2;
Expand All @@ -22,8 +23,11 @@ public class Blockade : MonoBehaviour {
public int score1;
public int score2;

public int winner;
public bool transition;

public float timer = 0f;
public float transitionTimer = 0f;

static GameObject[,] grid = new GameObject[100, 100];

Expand Down Expand Up @@ -55,74 +59,130 @@ void Start () {
score1 = 0;
score2 = 0;

bkgd.Play();
transition = false;
//bkgd.Play();
}

// Update is called once per frame
void Update () {
timer += Time.deltaTime;
//Debug.Log(current);
//Debug.Log(current2);
if (timer >= 0.3f)
if(transition)
{
timer = 0;
current += direction;
if (grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite == green)
timer += Time.deltaTime;
transitionTimer += Time.deltaTime;
if (winner == 1 && timer >= 0.2f)
{
score2++;
gameOver(1);
Debug.Log("s1");
if ((grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite == green))
{
grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite = black;
}
else
{
grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite = green;
}
timer = 0;
}
current2 += direction2;
if (grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite == green)
else if (winner == 2 && timer >= 0.2f)
{
score1++;
gameOver(2);
Debug.Log("s2");
if ((grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite == green))
{
grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite = black;
}
else
{
grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite = green;
}
timer = 0;
}

if(transitionTimer >= 5f)
{
s2.gameObject.SetActive(false);
s1.gameObject.SetActive(false);
transitionTimer = 0f;
timer = 0;
transition = false;
gameOver(winner);
}
grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite = green;
grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite = green;

}
else
{
timer += Time.deltaTime;
//Debug.Log(current);
//Debug.Log(current2);
if (timer >= 0.3f)
{
timer = 0;
current += direction;
if (grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite == green)
{
s2.gameObject.SetActive(true);
s1.gameObject.SetActive(true);
score1++;
s1.text = score1.ToString();
transition = true;
winner = 1;
}
current2 += direction2;
if (grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite == green)
{
s2.gameObject.SetActive(true);
s1.gameObject.SetActive(true);
score2++;
s2.text = score2.ToString();
transition = true;
winner = 2;
}
grid[(int)current.x, (int)current.y].GetComponent<SpriteRenderer>().sprite = green;
grid[(int)current2.x, (int)current2.y].GetComponent<SpriteRenderer>().sprite = green;
}

//Debug.Log(current.x);
//Debug.Log(current.x);

//grid[(int) current.x, (int) current.y].GetComponent<SpriteRenderer>().sprite = green;
//grid[(int) current.x, (int) current.y].GetComponent<SpriteRenderer>().sprite = green;

if(Input.GetKeyDown("w"))
{
direction = new Vector3(0, 1f);
}
if (Input.GetKeyDown("a"))
{
direction = new Vector3(-1f, 0);
}
if (Input.GetKeyDown("s"))
{
direction = new Vector3(0, -1f);
}
if (Input.GetKeyDown("d"))
{
direction = new Vector3(1f, 0);
}
if (Input.GetKeyDown("w"))
{
direction = new Vector3(0, 1f);
}
if (Input.GetKeyDown("a"))
{
direction = new Vector3(-1f, 0);
}
if (Input.GetKeyDown("s"))
{
direction = new Vector3(0, -1f);
}
if (Input.GetKeyDown("d"))
{
direction = new Vector3(1f, 0);
}

if (Input.GetKeyDown("up"))
{
direction2 = new Vector3(0, 1f);
}
if (Input.GetKeyDown("left"))
{
direction2 = new Vector3(-1f, 0);
}
if (Input.GetKeyDown("down"))
{
direction2 = new Vector3(0, -1f);
}
if (Input.GetKeyDown("right"))
{
direction2 = new Vector3(1f, 0);
if (Input.GetKeyDown("up"))
{
direction2 = new Vector3(0, 1f);
}
if (Input.GetKeyDown("left"))
{
direction2 = new Vector3(-1f, 0);
}
if (Input.GetKeyDown("down"))
{
direction2 = new Vector3(0, -1f);
}
if (Input.GetKeyDown("right"))
{
direction2 = new Vector3(1f, 0);
}
}


if (Input.GetKeyDown("r"))
{
gameOver(3);
SceneManager.LoadScene("BlockadeMenu", LoadSceneMode.Single);

}

}
Expand Down Expand Up @@ -160,9 +220,9 @@ void gameOver(int s)
}


IEnumerator gameoverTransition(int s);
IEnumerator gameoverTransition(int s)
{
for (int i = 0; i < 15; i++)
for (float i = 0; i < 1500f; i += 0.1f)
{
if(s == 1 && i % 3 == 0)
{
Expand All @@ -187,5 +247,8 @@ void gameOver(int s)
}
}
}

yield return null;

}
}

This file was deleted.

Loading

0 comments on commit 34762fa

Please sign in to comment.