Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Mostly) Finished GameSetup Script #21

Merged
merged 1 commit into from
Nov 6, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 79 additions & 13 deletions Assets/Scripts/GameSetup.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,90 @@
//Developer: Joseph Allen
//Developer: Noah Zemlin
//Script: GameSetup
//Version: 0.1
//Purpose: This script randomly sets up all GameObjects on the grid given by PlaySurfaceScanner
//Version: 1.0
//Purpose: This script spawns the game objects onto the map as well as checking for win conditions

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameSetup : MonoBehaviour {
private float[][] gridPositions;

void Start () {

}

void Update () {

}
public class GameSetup : MonoBehaviour
{

void InitializeGrid() {
private Dictionary<Goal, bool> goals;
private bool mapMade = false;

private bool won = false;

public LaserEmitter laserPrefab;
public LaserRefractor beaconPrefab;
public Goal goalPrefab;

public GameSetup()
{
goals = new Dictionary<Goal, bool>();
}

public void SetVictory(Goal g, bool victory)
{
if (goals.ContainsKey(g))
goals[g] = victory;
}

//Spawns all the game objecst
//This may need to be set to public if some other script is going to setup the world
private void SetupWorld()
{
if (laserPrefab != null && beaconPrefab != null && goalPrefab != null)
{
//spawn the map
mapMade = true;

//example spawn stuff (will come from json in future)
Vector3 pos1 = PlaySurfaceScanner.GetWorldPosition(1, 1, 1);
Vector3 pos2 = PlaySurfaceScanner.GetWorldPosition(1, 3, 1);
Vector3 pos3 = PlaySurfaceScanner.GetWorldPosition(1, 1, 3);

Instantiate(laserPrefab, pos1, Quaternion.Euler(0, 0, 0));
Instantiate(beaconPrefab, pos2, Quaternion.Euler(0, 0, 0));
Goal goal = Instantiate<Goal>(goalPrefab, pos3, Quaternion.Euler(0, 0, 0));
goals.Add(goal, false);

}
else
{
Debug.LogError("The GameSetup prefabs must be set!");
}
}

private void Update()
{
//if the map exists, assume game is in play
if (mapMade)
{
won = true;

//find any unsatisfied win conditions
foreach (bool goalVictory in goals.Values)
{
if (!goalVictory)
{
won = false;
break;
}
}

if (won)
{
Debug.Log("You won! Wow! Amazing! Nice shot!");
}
}
//if the PSS is done, then we can make the map using it's grid
else if (PlaySurfaceScanner.checkInitializationComplete())
{
//we can make the map
SetupWorld();
}
}

}