Commit 8cf1be2d by Tim Reiter
parents 90a5e627 8d61ac10
......@@ -12,6 +12,31 @@
<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" />
<Item prefab="Turret" y="-0.59">
<children prefab="TurretBase" y="3.11" rot="180" />
<children prefab="Cannon" y="3.07" rot="180" scaley="4.02" />
<children prefab="TurretButton" x="0.1" y="-3.61" />
</Item>
<Item prefab="ground" x="-6.2" y="1.15" scalex="10" />
<Item prefab="ground" x="6.2" y="1.15" scalex="10" />
<Item prefab="PortableFire" x="-6.84" y="1.96" scalex="0.2" scaley="0.2">
<children prefab="flame_a_0005" x="-6.84" y="1.96" scalex="2" scaley="2" />
</Item>
<Item prefab="PortableFire" x="6.84" y="1.83" scalex="0.2" scaley="0.2">
<children prefab="flame_a_0005" x="6.84" y="1.83" scalex="2" scaley="2" />
</Item>
</Level>
<Level>
<Item prefab="Start_Position" x="5" />
<Item prefab="Start_Position" x="-5" />
<Item prefab="Start_Position" x="-2.5" />
<Item prefab="Start_Position" x="2.5" />
<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="Start_Position" x="5" />
......
fileFormatVersion: 2
guid: 35b793df4d97b407088a52900b7b2e30
timeCreated: 1433525392
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
public class Bullet : MonoBehaviour {
public class Bullet : MonoBehaviour
{
public int healingPoints = 10;
public bool destroyTrap = false;
......@@ -14,7 +15,7 @@ public class Bullet : MonoBehaviour {
/// <param name="direction"></param>
public void shoot(Vector2 direction)
{
GetComponent<Rigidbody2D>().velocity = (float)speed*direction.normalized;
GetComponent<Rigidbody2D>().velocity = (float)speed * direction.normalized;
}
void OnTriggerEnter2D(Collider2D other)
......
using UnityEngine;
using System.Collections;
public class FireScript : MonoBehaviour {
public class FireScript : MonoBehaviour
{
PlayerHealth parentHealth;
......@@ -18,7 +19,8 @@ public class FireScript : MonoBehaviour {
}
// Update is called once per frame
void Update () {
void Update()
{
if (parentHealth)
{
parentHealth.changeHealthBy(-constantDamagepoints * Time.deltaTime);
......
......@@ -3,7 +3,8 @@ using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class GameMaster : MonoBehaviour {
public class GameMaster : MonoBehaviour
{
DeserializedLevelsLoader levelLoader;
public PlayerControl[] playerPrefabs;
......@@ -11,7 +12,8 @@ public class GameMaster : MonoBehaviour {
public Text rankingText;
// Use this for initialization
void Start () {
void Start()
{
levelLoader = new DeserializedLevelsLoader();
levelLoader.load();
}
......@@ -48,7 +50,7 @@ public class GameMaster : MonoBehaviour {
for (int i = 0; i < count; i++)
{
PlayerControl player = (PlayerControl) Object.Instantiate(
PlayerControl player = (PlayerControl)Object.Instantiate(
playerPrefabs[i % playerPrefabs.Length],
startPositions[i].transform.position,
Quaternion.identity);
......
......@@ -2,7 +2,8 @@
using System.Collections;
using System.Collections.Generic;
public class GameStateTracker : MonoBehaviour {
public class GameStateTracker : MonoBehaviour
{
private int numberOfPlayers;
......@@ -24,7 +25,8 @@ public class GameStateTracker : MonoBehaviour {
}
// Use this for initialization
void Start () {
void Start()
{
gameMaster = GetComponent<GameMaster>();
}
......
......@@ -22,20 +22,14 @@ public class DeserializedLevels
public Item[] items;
}
public class PlayerStartPosition
{
[XmlAttribute("x")]
public string x;
[XmlAttribute("y")]
public string y;
}
public class Item
{
[XmlAttribute ("prefab")]
public string prefab;
[XmlElement("children")]
public Item[] children;
[XmlAttribute ("x")]
public string x;
......
......@@ -6,11 +6,12 @@ using System.IO;
using System.Xml;
using System.Linq;
public class DeserializedLevelsCrossChecker {
public class DeserializedLevelsCrossChecker
{
//Hallo Tim und Philipp. Die Datei kuckt nur ob irgendwas mit den Prefabs komisch ist.
// cross check /Resources/Prefabs and Levels.xml if there are any item prefabs that exist only in one but not the other
public void crossCheck ()
public void crossCheck()
{
// create a list of /Resources/Prefabs for resources and Levels.Xml
List<string> resPrefabList = new List<string>();
......@@ -34,15 +35,15 @@ public class DeserializedLevelsCrossChecker {
// Add each prefab's file name to prefabList and truncate the .prefab extension from the end
foreach (FileInfo fileInfo in fileInfos)
resPrefabList.Add (fileInfo.Name.Substring(0, fileInfo.Name.Length - ".prefab".Length));
resPrefabList.Add(fileInfo.Name.Substring(0, fileInfo.Name.Length - ".prefab".Length));
// Cross checks
foreach (string prefab in xmlPrefabList.Except(resPrefabList).ToList())
Debug.LogError (prefab + " is missing in the /Resorces/Prefabs folder but used in Levels.xml");
Debug.LogError(prefab + " is missing in the /Resorces/Prefabs folder but used in Levels.xml");
foreach (string prefab in resPrefabList.Except(xmlPrefabList).ToList())
Debug.Log (prefab + " exists in the /Resorces/Prefabs folder but not used in Levels.xml");
Debug.Log(prefab + " exists in the /Resorces/Prefabs folder but not used in Levels.xml");
Debug.Log ("Cross Check Done");
Debug.Log("Cross Check Done");
}
}
......@@ -19,10 +19,22 @@ public class DeserializedLevelsLoader
public float rot;
public float scalex;
public float scaley;
public ItemChildStruct[] children;
}
struct ItemChildStruct
{
public string name;
public float x;
public float y;
public float rot;
public float scalex;
public float scaley;
}
// Cache prefabs in prefabDict
Dictionary<string,GameObject> prefabPool;
Dictionary<string, GameObject> prefabPool;
// Cache all items with locations
List<ItemStruct> sceneItemsList;
......@@ -31,12 +43,12 @@ public class DeserializedLevelsLoader
public const string xmlItemsGOName = "XmlItems";
public void load ()
public void load()
{
deserializedLevels = XmlIO.LoadXml<DeserializedLevels>("Levels");
}
public int getLevelCount ()
public int getLevelCount()
{
if (deserializedLevels == null)
throw new System.InvalidOperationException();
......@@ -44,7 +56,7 @@ public class DeserializedLevelsLoader
return deserializedLevels.levels.Length;
}
public void loadLevel (int levelIndex = 0)
public void loadLevel(int levelIndex = 0)
{
if (deserializedLevels == null)
throw new System.InvalidOperationException();
......@@ -56,8 +68,8 @@ public class DeserializedLevelsLoader
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));
while (GameObject.Find(xmlItemsGOName) != null)
MonoBehaviour.DestroyImmediate(GameObject.Find(xmlItemsGOName));
parentOfXmlItems = new GameObject(xmlItemsGOName).transform;
......@@ -96,6 +108,22 @@ public class DeserializedLevelsLoader
item.scalex = toFloatOneIfNull(deserializedItem.scalex);
item.scaley = toFloatOneIfNull(deserializedItem.scaley);
DeserializedLevels.Item[] children;
if (deserializedItem.children == null) children = new DeserializedLevels.Item[0];
else children = deserializedItem.children;
item.children = new ItemChildStruct[children.Length];
int k = 0;
foreach (DeserializedLevels.Item child in children)
{
item.children[k].name = child.prefab;
item.children[k].x = toFloatZeroIfNull(child.x);
item.children[k].y = toFloatZeroIfNull(child.y);
item.children[k].rot = toFloatZeroIfNull(child.rot);
item.children[k].scalex = toFloatOneIfNull(child.scalex);
item.children[k].scaley = toFloatOneIfNull(child.scaley);
}
sceneItemsList.Add(item);
}
......@@ -114,6 +142,22 @@ public class DeserializedLevelsLoader
setScale2D(newGameObject, item.scalex, item.scaley);
foreach (Transform t in newGameObject.GetComponentsInChildren<Transform>())
{
if (!(t.parent == null) && (!t.parent.name.Equals("XmlItems")))
{
foreach (ItemChildStruct child in item.children) //Ja das ist wahrscheinlich Laufzeitmig nicht ideal, aber die Arrays haben eh nur eine Hand viele Elemente
{
if (t.name == child.name)
{
Debug.Log("Set child " + child.name);
setPos2D(t.gameObject, new Vector2(child.x, child.y));
setRot2D(t.gameObject, child.rot);
setScale2D(t.gameObject, child.scalex, child.scaley);
}
}
}
}
// set parent
newGameObject.transform.parent = parentOfXmlItems;
}
......@@ -123,12 +167,12 @@ public class DeserializedLevelsLoader
// 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); }
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 (
g.transform.position = new Vector2(
pos.x,
pos.y
);
......
......@@ -6,19 +6,19 @@ public class DeserializedLevelsSaver
{
public const string xmlItemsToExportGOName = "XmlItemsToExport";
public void saveExportItems ()
public void saveExportItems()
{
// Create XmlItemsToExport if does not exist yet
if (GameObject.Find (xmlItemsToExportGOName) == null)
if (GameObject.Find(xmlItemsToExportGOName) == null)
new GameObject(xmlItemsToExportGOName);
GameObject xmlItemsToExportGO = GameObject.Find (xmlItemsToExportGOName);
GameObject xmlItemsToExportGO = GameObject.Find(xmlItemsToExportGOName);
var xmlItemsToExportGOchildren = xmlItemsToExportGO.GetComponentsInChildren<Transform>();
// Check if any children exist
if (xmlItemsToExportGOchildren.Length == 0)
Debug.LogError ("Add the prefabs to " + xmlItemsToExportGOName);
Debug.LogError("Add the prefabs to " + xmlItemsToExportGOName);
DeserializedLevels.Level levelXml = new DeserializedLevels.Level();
......@@ -41,6 +41,8 @@ public class DeserializedLevelsSaver
levelXml.items[i] = new DeserializedLevels.Item();
string name = item.name;
name = name.Replace("(Clone)", "");
levelXml.items[i].prefab = item.name;
levelXml.items[i].x = toStringNullIfZero(item.transform.position.x);
levelXml.items[i].y = toStringNullIfZero(item.transform.position.y);
......@@ -48,7 +50,32 @@ public class DeserializedLevelsSaver
levelXml.items[i].scalex = toStringNullIfOne(item.localScale.x);
levelXml.items[i].scaley = toStringNullIfOne(item.localScale.y);
// increase i for the next cycle
DeserializedLevels.Item[] children = new DeserializedLevels.Item[item.childCount];
Debug.Log("Child count for " + item.name + ": " + item.childCount);
int k = 0;
foreach (Transform t in item.GetComponentsInChildren<Transform>())
{
if (!t.parent.name.Equals("XmlItemsToExport"))
{
//GetComponentsInChildren gibt auch die Komponente aus dem Parent (also dem Objekt selbst) zurck
DeserializedLevels.Item child = new DeserializedLevels.Item();
Debug.Log("Add child " + t.name);
child.prefab = t.name;
child.x = toStringNullIfZero(t.position.x);
child.y = toStringNullIfZero(t.position.y);
child.rot = toStringNullIfZero(t.rotation.eulerAngles.z);
child.scalex = toStringNullIfOne(t.localScale.x);
child.scaley = toStringNullIfOne(t.localScale.y);
children[k] = child;
k++;
}
}
levelXml.items[i].children = (item.childCount > 0) ? children : null;
i++;
}
......@@ -60,12 +87,12 @@ public class DeserializedLevelsSaver
XmlIO.SaveXml<DeserializedLevels>(levelsXmlToExport, "./Assets/Resources/" + xmlItemsToExportGOName + ".xml");
}
string toStringNullIfZero (float num) { return num == 0 ? null : mathRound(num,2).ToString(); }
string toStringNullIfOne (float num) { return num == 1 ? null : mathRound(num,2).ToString(); }
string toStringNullIfZero(float num) { return num == 0 ? null : mathRound(num, 2).ToString(); }
string toStringNullIfOne(float num) { return num == 1 ? null : mathRound(num, 2).ToString(); }
float mathRound (float round, int decimals)
float mathRound(float round, int decimals)
{
return Mathf.Round(round * Mathf.Pow(10,decimals)) / Mathf.Pow(10,decimals);
return Mathf.Round(round * Mathf.Pow(10, decimals)) / Mathf.Pow(10, decimals);
}
}
......@@ -5,9 +5,9 @@ using UnityEngine; // necessary for TextAsset
public static class XmlIO
{
public static void SaveXml<T> (this object deserializedXml, string path) where T : class
public static void SaveXml<T>(this object deserializedXml, string path) where T : class
{
using(var stream = new FileStream(path, FileMode.Create))
using (var stream = new FileStream(path, FileMode.Create))
{
var s = new XmlSerializer(typeof(T));
s.Serialize(stream, deserializedXml);
......@@ -16,9 +16,9 @@ public static class XmlIO
public static T LoadXml<T>(string textAssetName) where T : class
{
TextAsset xmlTextAsset = (TextAsset) Resources.Load (textAssetName, typeof(TextAsset));
TextAsset xmlTextAsset = (TextAsset)Resources.Load(textAssetName, typeof(TextAsset));
using(var stream = new StringReader(xmlTextAsset.text))
using (var stream = new StringReader(xmlTextAsset.text))
{
var s = new XmlSerializer(typeof(T));
T deserializedXml = s.Deserialize(stream) as T;
......
......@@ -76,7 +76,7 @@ public class Menu : MonoBehaviour
int playerNumber = addPlayer();
if (playerNumber > 0)
{
inputMappings[playerNumber-1].set(controlType.WASD);
inputMappings[playerNumber - 1].set(controlType.WASD);
WASDAdded = true;
}
}
......@@ -96,7 +96,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0)
{
ArrowAdded = true;
inputMappings[playerNumber-1].set(controlType.ARROWS);
inputMappings[playerNumber - 1].set(controlType.ARROWS);
}
}
......@@ -116,7 +116,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0)
{
GP1Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD1);
inputMappings[playerNumber - 1].set(controlType.GAMEPAD1);
}
}
......@@ -136,7 +136,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0)
{
GP2Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD2);
inputMappings[playerNumber - 1].set(controlType.GAMEPAD2);
}
}
......@@ -156,7 +156,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0)
{
GP3Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD3);
inputMappings[playerNumber - 1].set(controlType.GAMEPAD3);
}
}
}
......@@ -175,7 +175,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0)
{
GP4Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD4);
inputMappings[playerNumber - 1].set(controlType.GAMEPAD4);
}
}
}
......
......@@ -2,7 +2,8 @@
using System.Collections;
using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour {
public class PlayerHealth : MonoBehaviour
{
public float maxHealth = 100;
......@@ -33,12 +34,13 @@ public class PlayerHealth : MonoBehaviour {
}
// Update is called once per frame
void Update () {
void Update()
{
if (alive && currentHealth <= 0)
{
Debug.Log("Player " + name + " dead.");
alive = false;
((GameStateTracker) Object.FindObjectOfType(typeof(GameStateTracker))).playerDied(name);
((GameStateTracker)Object.FindObjectOfType(typeof(GameStateTracker))).playerDied(name);
healthbar.gameObject.SetActive(false); //hide healthbar
Destroy(gameObject);
}
......@@ -71,7 +73,8 @@ public class PlayerHealth : MonoBehaviour {
updateHealthbar();
}
public void setShield(bool s) {
public void setShield(bool s)
{
Debug.Log("Shield " + s + " accepted");
hasShield = s;
}
......
using UnityEngine;
using System.Collections;
using GamepadInput;
public enum controlType : int { WASD = 0, ARROWS = 1, GAMEPAD1 = 2, GAMEPAD2 = 3, GAMEPAD3=4, GAMEPAD4=5}
public enum controlType : int { WASD = 0, ARROWS = 1, GAMEPAD1 = 2, GAMEPAD2 = 3, GAMEPAD3 = 4, GAMEPAD4 = 5 }
public class PlayerInputMapping : MonoBehaviour {
public class PlayerInputMapping : MonoBehaviour
{
private enum Keys : int { Left = 0, Right, Up, Down, Jump, Dash, Shoot };
......
using UnityEngine;
using System.Collections;
public class PowerUpScript : MonoBehaviour {
public class PowerUpScript : MonoBehaviour
{
/// <summary>
/// sollte übereinstimmen mit PlayerControl.POWERUP_XXX
......
......@@ -17,12 +17,14 @@ public class Rocket : MonoBehaviour
#endregion
// Use this for initialization
void Start () {
void Start()
{
body = GetComponent<Rigidbody2D>();
}
// Update is called once per frame
void Update () {
void Update()
{
if (!target) return;
//update direction:
......@@ -43,7 +45,7 @@ public class Rocket : MonoBehaviour
otherBody.AddForce(body.velocity.normalized * pushForce);
//explosion effect:
explosion = GameObject.Instantiate(explosionAnimator.gameObject,transform.position,transform.rotation) as GameObject;
explosion = GameObject.Instantiate(explosionAnimator.gameObject, transform.position, transform.rotation) as GameObject;
gameObject.GetComponent<SpriteRenderer>().enabled = false;
gameObject.GetComponent<Collider2D>().enabled = false;
......
using UnityEngine;
using System.Collections;
public class ShieldScript : MonoBehaviour {
public class ShieldScript : MonoBehaviour
{
PlayerHealth parentHealth;
......
using UnityEngine;
using System.Collections;
public class Turret : MonoBehaviour {
public class Turret : MonoBehaviour
{
public GameObject rocketPrefab;
private Transform target;
......@@ -9,7 +10,8 @@ public class Turret : MonoBehaviour {
// Update is called once per frame
void Update () {
void Update()
{
if (!target) return;
Vector3 direction = target.position - transform.position;
......
using UnityEngine;
using System.Collections;
public class TurretButton : MonoBehaviour {
public class TurretButton : MonoBehaviour
{
public Turret cannon; // die entsprechende turret-cannon.
void OnCollisionEnter2D(Collision2D coll)
{
//soll nur von oben ausloesen:
if (coll.gameObject.tag == "Player" && coll.relativeVelocity.x<0.001f && coll.relativeVelocity.y>0.2f)
if (coll.gameObject.tag == "Player" && coll.relativeVelocity.x < 0.001f && coll.relativeVelocity.y > 0.2f)
{
cannon.setTarget(coll.gameObject.transform);
cannon.shoot();
......
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