-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from OUVirtualReality/noah_z
(Mostly) Finished GameSetup Script
- Loading branch information
Showing
1 changed file
with
79 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |