Commit 3c8982aa by Tim Reiter

players are now loaded from xml (+ fixed a bug when the player picked up the portable fire)

parent 83bf8ea8
......@@ -4,8 +4,12 @@
<Developer StartLevel="0" />
<Level>
<Item prefab="Trap" x="-2.2" y="-0.1" rot="90" />
<Item prefab="ground" x="9.3" y="-0.7" scalex="200" />
<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" />
</Level>
<Level>
<Item prefab="PlayerStartPosition" x="5.11" y="-0.92" />
......
fileFormatVersion: 2
guid: 8d9c84360d70c1b44af690dc244612a0
timeCreated: 1433461451
guid: 329ca4a74de8c8a438a191940544e5e1
timeCreated: 1433500438
licenseType: Free
NativeFormatImporter:
userData:
......
fileFormatVersion: 2
guid: 6c6daf85837b9f542bcb18f819b9d8a8
timeCreated: 1433500442
licenseType: Free
NativeFormatImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: e0d90fce50c24884c8d83b9d365a5fe3
timeCreated: 1433446163
guid: 3ad7c167097946b408dbef72e2814b8f
timeCreated: 1433501024
licenseType: Free
NativeFormatImporter:
userData:
......
<?xml version="1.0" encoding="Windows-1252"?>
<Levels xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Level>
<Item prefab="Trap" x="-2.2" y="-0.1" rot="90" />
<Item prefab="ground" x="9.3" y="-0.7" scalex="200" />
<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" />
</Level>
</Levels>
\ No newline at end of file
......@@ -7,20 +7,23 @@ public class FireScript : MonoBehaviour {
public float constantDamagepoints = 0.1f;
public float burningTime = 10;
// Use this for initialization
void Start () {
Invoke("stopBurning", burningTime);
}
// Update is called once per frame
void Update () {
if (parentHealth != null)
public float burningTime = 10f;
private Vector3 startScale; //fixes a bug: scale of fire was 0 when attached to the player.
void Start()
{
startScale = transform.localScale;
}
// Update is called once per frame
void Update () {
if (parentHealth)
{
parentHealth.changeHealthBy(-constantDamagepoints);
parentHealth.changeHealthBy(-constantDamagepoints * Time.deltaTime);
}
}
}
void OnTriggerEnter2D(Collider2D other)
{
......@@ -29,6 +32,8 @@ public class FireScript : MonoBehaviour {
parentHealth = other.GetComponent<PlayerHealth>();
transform.position = other.transform.position; //hier schon position setzen
transform.parent = other.transform;
transform.localScale = startScale;
Invoke("stopBurning", burningTime);
}
}
......
using UnityEngine;
using System.Collections;
public class GameMaster : MonoBehaviour {
DeserializedLevelsLoader levelLoader;
// Use this for initialization
void Start () {
levelLoader = new DeserializedLevelsLoader();
levelLoader.loadLevel();
}
// Update is called once per frame
void Update () {
}
}
fileFormatVersion: 2
guid: 01cdeb3258bc3446ba8846c11515fc68
guid: 50166dd06214cc844822e30d279ffe94
timeCreated: 1433499967
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -22,15 +22,15 @@ public class GameStateTracker : MonoBehaviour {
ranking = new List<string>();
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void setNumberOfPlayers(int players)
{
......
......@@ -6,13 +6,13 @@ using UnityEngine;
public class DeserializedLevelsLoader
{
// Levels deserialized
private DeserializedLevels deserializedLevels;
// Levels deserialized
private DeserializedLevels deserializedLevels;
private int currentLevelIndex = 0;
private int currentSegmentIndex = 0;
private const string prefabsFolder = "Prefabs/";
private const string prefabsFolder = "Prefabs/";
struct ItemStruct
{
......@@ -24,32 +24,32 @@ public class DeserializedLevelsLoader
public float scaley;
}
// Cache prefabs in prefabDict
Dictionary<string,GameObject> prefabPool;
// Cache prefabs in prefabDict
Dictionary<string,GameObject> prefabPool;
// Cache all items with locations
List<ItemStruct> sceneItemsList;
// Cache all items with locations
List<ItemStruct> sceneItemsList;
Transform parentOfXmlItems;
public const string xmlItemsGOName = "XmlItems";
Transform parentOfXmlItems;
public const string xmlItemsGOName = "XmlItems";
public void loadLevel (int levelIndex = 0)
{
prefabPool = new Dictionary<string, GameObject>();
sceneItemsList = new List<ItemStruct>();
public void loadLevel (int levelIndex = 0)
{
prefabPool = new Dictionary<string, GameObject>();
sceneItemsList = new List<ItemStruct>();
// if the XmlItems gameobject folder remained in the Hierarcy, then delete it
while (GameObject.Find (xmlItemsGOName) != null)
MonoBehaviour.DestroyImmediate(GameObject.Find (xmlItemsGOName));
parentOfXmlItems = new GameObject(xmlItemsGOName).transform;
// if the XmlItems gameobject folder remained in the Hierarcy, then delete it
while (GameObject.Find (xmlItemsGOName) != null)
MonoBehaviour.DestroyImmediate(GameObject.Find (xmlItemsGOName));
parentOfXmlItems = new GameObject(xmlItemsGOName).transform;
deserializedLevels = XmlIO.LoadXml<DeserializedLevels>("Levels");
deserializedLevels = XmlIO.LoadXml<DeserializedLevels>("Levels");
// if startlevel is in the XML i.e. <Developer StartLevel="3" /> then get level from there
// otherwise start with level 1
currentLevelIndex = (levelIndex > deserializedLevels.levels.Length - 1) ? 0 : levelIndex;
// if startlevel is in the XML i.e. <Developer StartLevel="3" /> then get level from there
// otherwise start with level 1
currentLevelIndex = (levelIndex > deserializedLevels.levels.Length - 1) ? 0 : levelIndex;
DeserializedLevels.Level currentLevel = deserializedLevels.levels[currentLevelIndex];
......@@ -108,30 +108,30 @@ public class DeserializedLevelsLoader
// set parent
newGameObject.transform.parent = parentOfXmlItems;
}
}
}
// DONE, these are only helper functions below
// DONE, these are only helper functions below
// if no value then return zero or one, otherwise convert to float
float toFloatZeroIfNull (string value) { return value == null ? 0 : float.Parse(value); }
float toFloatOneIfNull (string value) { return value == null ? 1 : float.Parse(value); }
// if no value then return zero or one, otherwise convert to float
float toFloatZeroIfNull (string value) { return value == null ? 0 : float.Parse(value); }
float toFloatOneIfNull (string value) { return value == null ? 1 : float.Parse(value); }
void setPos2D(GameObject g, Vector2 pos)
{
g.transform.position = new Vector2 (
pos.x,
pos.y
);
}
void setPos2D(GameObject g, Vector2 pos)
{
g.transform.position = new Vector2 (
pos.x,
pos.y
);
}
void setRot2D(GameObject g, float rot)
{
void setRot2D(GameObject g, float rot)
{
//Debug.Log("Set rotation of " + g.name + " to " + rot);
Quaternion rotation = Quaternion.identity;
rotation.eulerAngles = new Vector3(0, 0, rot);
g.transform.localRotation = rotation;
}
Quaternion rotation = Quaternion.identity;
rotation.eulerAngles = new Vector3(0, 0, rot);
g.transform.localRotation = rotation;
}
void setScale2D(GameObject g, float scaleX, float scaleY)
{
......
using UnityEngine;
using System.Collections;
public class PlayScript : MonoBehaviour {
DeserializedLevelsLoader d;
void Start ()
{
d = new DeserializedLevelsLoader();
d.loadLevel();
}
}
......@@ -8,21 +8,29 @@ public class PlayerHealth : MonoBehaviour {
public float currentHealth = 100;
private bool alive = true;
public Scrollbar healthbar;
private Scrollbar healthbar;
private PlayerControl playerControl;
private GameStateTracker gameStateTracker;
private bool hasShield = false;
void Start()
{
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();
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
}
// Update is called once per frame
void Update () {
// Update is called once per frame
void Update () {
if (alive && currentHealth <= 0)
{
Debug.Log("Player " + name + " dead.");
alive = false;
GameObject.Find("GameStateTracker").GetComponent<GameStateTracker>().playerDied(name);
gameStateTracker.playerDied(name);
Destroy(gameObject);
}
}
}
public float getCurrentHealth()
{
......
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