Commit 7d9c2dd3 by Tim Reiter

Merge branch 'master' of ssh://git.breab.org:2222/gamejam-gpn15/dyingIsMainstream

Conflicts: Assets/Scripts/PlayerControl.cs Assets/game.unity
parents e860e653 cb5cf6e8
<?xml version="1.0" encoding="us-ascii"?>
<Levels>
<Developer StartLevel="0" />
<Level>
<Item prefab="Player Two" x="-3.05" y="2.06" />
<Item prefab="Player One" x="-0.23" y="2.06" />
<Item prefab="Trap" x="-5.02" y="-0.57" rot="90" />
<Item prefab="ground" x="1.51" y="-0.8" scalex="58.39" />
<Item prefab="Turret" x="4.47" y="0.71" />
<Item prefab="PortableFire" x="4.04" y="-0.22" scalex="0.2" scaley="0.2" />
<Item prefab="Start_Position" x="5" />
<Item prefab="Start_Position" x="-5" />
<Item prefab="Start_Position" />
<Item prefab="ground" y="-1.5" scalex="22.78" />
<Item prefab="ground" x="-7.5" y="-0.38" rot="90" scalex="30" />
<Item prefab="ground" x="7.5" y="-0.38" rot="90" scalex="30" />
<Item prefab="ground" x="4.69" y="-2.71" scalex="22.78" />
<Item prefab="ground" x="-4.7" y="-2.7" scalex="22.78" />
<Item prefab="ground" y="-4" scalex="60" />
</Level>
<Level>
<Item prefab="PlayerStartPosition" x="5.11" y="-0.92" />
<Item prefab="PortableFire" x="6.57" y="-1.3" />
<Item prefab="PortableFire" x="6.41" y="-2.37" />
<Item prefab="PortableFire" x="4.84" y="-1.68" />
</Level>
</Levels>
\ No newline at end of file
</Levels>
fileFormatVersion: 2
guid: d0e95f1c653856b409b235f9de3f6493
timeCreated: 1433514922
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -6,6 +6,7 @@ using UnityEngine.UI;
public class GameMaster : MonoBehaviour {
DeserializedLevelsLoader levelLoader;
public PlayerControl[] playerPrefabs;
public GameObject gameOverPanel;
public Text rankingText;
......@@ -14,9 +15,53 @@ public class GameMaster : MonoBehaviour {
levelLoader = new DeserializedLevelsLoader();
}
public void loadLevel()
public void loadLevel(int numberOfPlayers)
{
levelLoader.loadLevel();
deleteAllPlayers();
spawnPlayers(numberOfPlayers);
}
private void deleteAllPlayers()
{
foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player"))
Object.Destroy(player, 0f);
}
private void spawnPlayers(int count)
{
Debug.Log("spawning " + count + " players");
GameObject[] startPositions = GameObject.FindGameObjectsWithTag("Start_Position");
if (count > startPositions.Length)
{
count = startPositions.Length;
Debug.LogError("map is capped at " + count + " players");
}
shuffle(startPositions);
for (int i = 0; i < count; i++)
{
PlayerControl player = (PlayerControl) Object.Instantiate(
playerPrefabs[i % playerPrefabs.Length],
startPositions[i].transform.position,
Quaternion.identity);
player.init(i + 1);
}
}
private static void shuffle<T>(T[] array)
{
int i = array.Length;
while (i > 1)
{
int k = Random.Range(0, i--);
T t = array[k];
array[k] = array[i];
array[i] = t;
}
}
public void gameOver(List<string> ranking)
......
......@@ -7,6 +7,7 @@ using UnityEngine.UI;
public class Menu : MonoBehaviour
{
public GameStateTracker gameStateTracker;
public GameObject gameUI;
public GameMaster gameMaster;
public GameObject menuPanel;
public GameObject p1Image, p2Image, p3Image, p4Image;
......@@ -38,9 +39,10 @@ public class Menu : MonoBehaviour
{
if (numberOfRegisteredPlayers > 1 || (numberOfRegisteredPlayers > 0 && Debug.isDebugBuild))
{
gameUI.SetActive(true);
gameStateTracker.setNumberOfPlayers(numberOfRegisteredPlayers);
gameStateTracker.reset();
gameMaster.loadLevel();
gameMaster.loadLevel(numberOfRegisteredPlayers);
gameObject.SetActive(false);
return true;
}
......
......@@ -13,13 +13,10 @@ public class PlayerHealth : MonoBehaviour {
private GameStateTracker gameStateTracker;
private bool hasShield = false;
void Start()
public void init(int playerNumber)
{
gameStateTracker = GameObject.Find("GameMaster").GetComponent<GameStateTracker>(); //warning: geht kaputt wenn der name "Game Master" sich aendert.
playerControl = gameObject.GetComponent<PlayerControl>();
string healthbarName = "HealthBar" + playerControl.playerNumber.ToString();
string healthbarName = "HealthBar" + playerNumber;
Debug.Log(healthbarName);
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
if (name.EndsWith("(Clone)"))
......
No preview for this file type
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment