Commit 8d61ac10 by Alisa Jung

Autoformat everything: Einrückung mit 2 Leerzeichen, keine Tabs.

parent d87c20d0
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
public class Bullet : MonoBehaviour { public class Bullet : MonoBehaviour
{
public int healingPoints = 10; public int healingPoints = 10;
public bool destroyTrap = false; public bool destroyTrap = false;
...@@ -14,7 +15,7 @@ public class Bullet : MonoBehaviour { ...@@ -14,7 +15,7 @@ public class Bullet : MonoBehaviour {
/// <param name="direction"></param> /// <param name="direction"></param>
public void shoot(Vector2 direction) public void shoot(Vector2 direction)
{ {
GetComponent<Rigidbody2D>().velocity = (float)speed*direction.normalized; GetComponent<Rigidbody2D>().velocity = (float)speed * direction.normalized;
} }
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
......
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
public class FireScript : MonoBehaviour { public class FireScript : MonoBehaviour
{
PlayerHealth parentHealth; PlayerHealth parentHealth;
...@@ -18,7 +19,8 @@ public class FireScript : MonoBehaviour { ...@@ -18,7 +19,8 @@ public class FireScript : MonoBehaviour {
} }
// Update is called once per frame // Update is called once per frame
void Update () { void Update()
{
if (parentHealth) if (parentHealth)
{ {
parentHealth.changeHealthBy(-constantDamagepoints * Time.deltaTime); parentHealth.changeHealthBy(-constantDamagepoints * Time.deltaTime);
......
...@@ -3,7 +3,8 @@ using System.Collections; ...@@ -3,7 +3,8 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine.UI; using UnityEngine.UI;
public class GameMaster : MonoBehaviour { public class GameMaster : MonoBehaviour
{
DeserializedLevelsLoader levelLoader; DeserializedLevelsLoader levelLoader;
public PlayerControl[] playerPrefabs; public PlayerControl[] playerPrefabs;
...@@ -11,7 +12,8 @@ public class GameMaster : MonoBehaviour { ...@@ -11,7 +12,8 @@ public class GameMaster : MonoBehaviour {
public Text rankingText; public Text rankingText;
// Use this for initialization // Use this for initialization
void Start () { void Start()
{
levelLoader = new DeserializedLevelsLoader(); levelLoader = new DeserializedLevelsLoader();
levelLoader.load(); levelLoader.load();
} }
...@@ -48,7 +50,7 @@ public class GameMaster : MonoBehaviour { ...@@ -48,7 +50,7 @@ public class GameMaster : MonoBehaviour {
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
PlayerControl player = (PlayerControl) Object.Instantiate( PlayerControl player = (PlayerControl)Object.Instantiate(
playerPrefabs[i % playerPrefabs.Length], playerPrefabs[i % playerPrefabs.Length],
startPositions[i].transform.position, startPositions[i].transform.position,
Quaternion.identity); Quaternion.identity);
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
public class GameStateTracker : MonoBehaviour { public class GameStateTracker : MonoBehaviour
{
private int numberOfPlayers; private int numberOfPlayers;
...@@ -24,7 +25,8 @@ public class GameStateTracker : MonoBehaviour { ...@@ -24,7 +25,8 @@ public class GameStateTracker : MonoBehaviour {
} }
// Use this for initialization // Use this for initialization
void Start () { void Start()
{
gameMaster = GetComponent<GameMaster>(); gameMaster = GetComponent<GameMaster>();
} }
......
...@@ -6,11 +6,12 @@ using System.IO; ...@@ -6,11 +6,12 @@ using System.IO;
using System.Xml; using System.Xml;
using System.Linq; using System.Linq;
public class DeserializedLevelsCrossChecker { public class DeserializedLevelsCrossChecker
{
//Hallo Tim und Philipp. Die Datei kuckt nur ob irgendwas mit den Prefabs komisch ist. //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 // 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 // create a list of /Resources/Prefabs for resources and Levels.Xml
List<string> resPrefabList = new List<string>(); List<string> resPrefabList = new List<string>();
...@@ -34,15 +35,15 @@ public class DeserializedLevelsCrossChecker { ...@@ -34,15 +35,15 @@ public class DeserializedLevelsCrossChecker {
// Add each prefab's file name to prefabList and truncate the .prefab extension from the end // Add each prefab's file name to prefabList and truncate the .prefab extension from the end
foreach (FileInfo fileInfo in fileInfos) 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 // Cross checks
foreach (string prefab in xmlPrefabList.Except(resPrefabList).ToList()) 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()) 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");
} }
} }
...@@ -34,7 +34,7 @@ public class DeserializedLevelsLoader ...@@ -34,7 +34,7 @@ public class DeserializedLevelsLoader
// Cache prefabs in prefabDict // Cache prefabs in prefabDict
Dictionary<string,GameObject> prefabPool; Dictionary<string, GameObject> prefabPool;
// Cache all items with locations // Cache all items with locations
List<ItemStruct> sceneItemsList; List<ItemStruct> sceneItemsList;
...@@ -43,12 +43,12 @@ public class DeserializedLevelsLoader ...@@ -43,12 +43,12 @@ public class DeserializedLevelsLoader
public const string xmlItemsGOName = "XmlItems"; public const string xmlItemsGOName = "XmlItems";
public void load () public void load()
{ {
deserializedLevels = XmlIO.LoadXml<DeserializedLevels>("Levels"); deserializedLevels = XmlIO.LoadXml<DeserializedLevels>("Levels");
} }
public int getLevelCount () public int getLevelCount()
{ {
if (deserializedLevels == null) if (deserializedLevels == null)
throw new System.InvalidOperationException(); throw new System.InvalidOperationException();
...@@ -56,7 +56,7 @@ public class DeserializedLevelsLoader ...@@ -56,7 +56,7 @@ public class DeserializedLevelsLoader
return deserializedLevels.levels.Length; return deserializedLevels.levels.Length;
} }
public void loadLevel (int levelIndex = 0) public void loadLevel(int levelIndex = 0)
{ {
if (deserializedLevels == null) if (deserializedLevels == null)
throw new System.InvalidOperationException(); throw new System.InvalidOperationException();
...@@ -68,8 +68,8 @@ public class DeserializedLevelsLoader ...@@ -68,8 +68,8 @@ public class DeserializedLevelsLoader
sceneItemsList = new List<ItemStruct>(); sceneItemsList = new List<ItemStruct>();
// if the XmlItems gameobject folder remained in the Hierarcy, then delete it // if the XmlItems gameobject folder remained in the Hierarcy, then delete it
while (GameObject.Find (xmlItemsGOName) != null) while (GameObject.Find(xmlItemsGOName) != null)
MonoBehaviour.DestroyImmediate(GameObject.Find (xmlItemsGOName)); MonoBehaviour.DestroyImmediate(GameObject.Find(xmlItemsGOName));
parentOfXmlItems = new GameObject(xmlItemsGOName).transform; parentOfXmlItems = new GameObject(xmlItemsGOName).transform;
...@@ -167,12 +167,12 @@ public class DeserializedLevelsLoader ...@@ -167,12 +167,12 @@ public class DeserializedLevelsLoader
// 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 // if no value then return zero or one, otherwise convert to float
float toFloatZeroIfNull (string value) { return value == null ? 0 : 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); } float toFloatOneIfNull(string value) { return value == null ? 1 : float.Parse(value); }
void setPos2D(GameObject g, Vector2 pos) void setPos2D(GameObject g, Vector2 pos)
{ {
g.transform.position = new Vector2 ( g.transform.position = new Vector2(
pos.x, pos.x,
pos.y pos.y
); );
......
...@@ -6,19 +6,19 @@ public class DeserializedLevelsSaver ...@@ -6,19 +6,19 @@ public class DeserializedLevelsSaver
{ {
public const string xmlItemsToExportGOName = "XmlItemsToExport"; public const string xmlItemsToExportGOName = "XmlItemsToExport";
public void saveExportItems () public void saveExportItems()
{ {
// Create XmlItemsToExport if does not exist yet // Create XmlItemsToExport if does not exist yet
if (GameObject.Find (xmlItemsToExportGOName) == null) if (GameObject.Find(xmlItemsToExportGOName) == null)
new GameObject(xmlItemsToExportGOName); new GameObject(xmlItemsToExportGOName);
GameObject xmlItemsToExportGO = GameObject.Find (xmlItemsToExportGOName); GameObject xmlItemsToExportGO = GameObject.Find(xmlItemsToExportGOName);
var xmlItemsToExportGOchildren = xmlItemsToExportGO.GetComponentsInChildren<Transform>(); var xmlItemsToExportGOchildren = xmlItemsToExportGO.GetComponentsInChildren<Transform>();
// Check if any children exist // Check if any children exist
if (xmlItemsToExportGOchildren.Length == 0) if (xmlItemsToExportGOchildren.Length == 0)
Debug.LogError ("Add the prefabs to " + xmlItemsToExportGOName); Debug.LogError("Add the prefabs to " + xmlItemsToExportGOName);
DeserializedLevels.Level levelXml = new DeserializedLevels.Level(); DeserializedLevels.Level levelXml = new DeserializedLevels.Level();
...@@ -87,12 +87,12 @@ public class DeserializedLevelsSaver ...@@ -87,12 +87,12 @@ public class DeserializedLevelsSaver
XmlIO.SaveXml<DeserializedLevels>(levelsXmlToExport, "./Assets/Resources/" + xmlItemsToExportGOName + ".xml"); XmlIO.SaveXml<DeserializedLevels>(levelsXmlToExport, "./Assets/Resources/" + xmlItemsToExportGOName + ".xml");
} }
string toStringNullIfZero (float num) { return num == 0 ? 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(); } 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 ...@@ -5,9 +5,9 @@ using UnityEngine; // necessary for TextAsset
public static class XmlIO 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)); var s = new XmlSerializer(typeof(T));
s.Serialize(stream, deserializedXml); s.Serialize(stream, deserializedXml);
...@@ -16,9 +16,9 @@ public static class XmlIO ...@@ -16,9 +16,9 @@ public static class XmlIO
public static T LoadXml<T>(string textAssetName) where T : class 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)); var s = new XmlSerializer(typeof(T));
T deserializedXml = s.Deserialize(stream) as T; T deserializedXml = s.Deserialize(stream) as T;
......
...@@ -76,7 +76,7 @@ public class Menu : MonoBehaviour ...@@ -76,7 +76,7 @@ public class Menu : MonoBehaviour
int playerNumber = addPlayer(); int playerNumber = addPlayer();
if (playerNumber > 0) if (playerNumber > 0)
{ {
inputMappings[playerNumber-1].set(controlType.WASD); inputMappings[playerNumber - 1].set(controlType.WASD);
WASDAdded = true; WASDAdded = true;
} }
} }
...@@ -96,7 +96,7 @@ public class Menu : MonoBehaviour ...@@ -96,7 +96,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0) if (playerNumber > 0)
{ {
ArrowAdded = true; ArrowAdded = true;
inputMappings[playerNumber-1].set(controlType.ARROWS); inputMappings[playerNumber - 1].set(controlType.ARROWS);
} }
} }
...@@ -116,7 +116,7 @@ public class Menu : MonoBehaviour ...@@ -116,7 +116,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0) if (playerNumber > 0)
{ {
GP1Added = true; GP1Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD1); inputMappings[playerNumber - 1].set(controlType.GAMEPAD1);
} }
} }
...@@ -136,7 +136,7 @@ public class Menu : MonoBehaviour ...@@ -136,7 +136,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0) if (playerNumber > 0)
{ {
GP2Added = true; GP2Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD2); inputMappings[playerNumber - 1].set(controlType.GAMEPAD2);
} }
} }
...@@ -156,7 +156,7 @@ public class Menu : MonoBehaviour ...@@ -156,7 +156,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0) if (playerNumber > 0)
{ {
GP3Added = true; GP3Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD3); inputMappings[playerNumber - 1].set(controlType.GAMEPAD3);
} }
} }
} }
...@@ -175,7 +175,7 @@ public class Menu : MonoBehaviour ...@@ -175,7 +175,7 @@ public class Menu : MonoBehaviour
if (playerNumber > 0) if (playerNumber > 0)
{ {
GP4Added = true; GP4Added = true;
inputMappings[playerNumber-1].set(controlType.GAMEPAD4); inputMappings[playerNumber - 1].set(controlType.GAMEPAD4);
} }
} }
} }
......
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
using System.Collections; using System.Collections;
using UnityEngine.UI; using UnityEngine.UI;
public class PlayerHealth : MonoBehaviour { public class PlayerHealth : MonoBehaviour
{
public float maxHealth = 100; public float maxHealth = 100;
...@@ -33,12 +34,13 @@ public class PlayerHealth : MonoBehaviour { ...@@ -33,12 +34,13 @@ public class PlayerHealth : MonoBehaviour {
} }
// Update is called once per frame // Update is called once per frame
void Update () { void Update()
{
if (alive && currentHealth <= 0) if (alive && currentHealth <= 0)
{ {
Debug.Log("Player " + name + " dead."); Debug.Log("Player " + name + " dead.");
alive = false; alive = false;
((GameStateTracker) Object.FindObjectOfType(typeof(GameStateTracker))).playerDied(name); ((GameStateTracker)Object.FindObjectOfType(typeof(GameStateTracker))).playerDied(name);
healthbar.gameObject.SetActive(false); //hide healthbar healthbar.gameObject.SetActive(false); //hide healthbar
Destroy(gameObject); Destroy(gameObject);
} }
...@@ -71,7 +73,8 @@ public class PlayerHealth : MonoBehaviour { ...@@ -71,7 +73,8 @@ public class PlayerHealth : MonoBehaviour {
updateHealthbar(); updateHealthbar();
} }
public void setShield(bool s) { public void setShield(bool s)
{
Debug.Log("Shield " + s + " accepted"); Debug.Log("Shield " + s + " accepted");
hasShield = s; hasShield = s;
} }
......
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
using GamepadInput; 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 }; private enum Keys : int { Left = 0, Right, Up, Down, Jump, Dash, Shoot };
......
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
public class PowerUpScript : MonoBehaviour { public class PowerUpScript : MonoBehaviour
{
/// <summary> /// <summary>
/// sollte übereinstimmen mit PlayerControl.POWERUP_XXX /// sollte übereinstimmen mit PlayerControl.POWERUP_XXX
......
...@@ -17,12 +17,14 @@ public class Rocket : MonoBehaviour ...@@ -17,12 +17,14 @@ public class Rocket : MonoBehaviour
#endregion #endregion
// Use this for initialization // Use this for initialization
void Start () { void Start()
{
body = GetComponent<Rigidbody2D>(); body = GetComponent<Rigidbody2D>();
} }
// Update is called once per frame // Update is called once per frame
void Update () { void Update()
{
if (!target) return; if (!target) return;
//update direction: //update direction:
...@@ -43,7 +45,7 @@ public class Rocket : MonoBehaviour ...@@ -43,7 +45,7 @@ public class Rocket : MonoBehaviour
otherBody.AddForce(body.velocity.normalized * pushForce); otherBody.AddForce(body.velocity.normalized * pushForce);
//explosion effect: //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<SpriteRenderer>().enabled = false;
gameObject.GetComponent<Collider2D>().enabled = false; gameObject.GetComponent<Collider2D>().enabled = false;
......
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
public class ShieldScript : MonoBehaviour { public class ShieldScript : MonoBehaviour
{
PlayerHealth parentHealth; PlayerHealth parentHealth;
......
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
public class Turret : MonoBehaviour { public class Turret : MonoBehaviour
{
public GameObject rocketPrefab; public GameObject rocketPrefab;
private Transform target; private Transform target;
...@@ -9,7 +10,8 @@ public class Turret : MonoBehaviour { ...@@ -9,7 +10,8 @@ public class Turret : MonoBehaviour {
// Update is called once per frame // Update is called once per frame
void Update () { void Update()
{
if (!target) return; if (!target) return;
Vector3 direction = target.position - transform.position; Vector3 direction = target.position - transform.position;
......
using UnityEngine; using UnityEngine;
using System.Collections; using System.Collections;
public class TurretButton : MonoBehaviour { public class TurretButton : MonoBehaviour
{
public Turret cannon; // die entsprechende turret-cannon. public Turret cannon; // die entsprechende turret-cannon.
void OnCollisionEnter2D(Collision2D coll) void OnCollisionEnter2D(Collision2D coll)
{ {
//soll nur von oben ausloesen: //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.setTarget(coll.gameObject.transform);
cannon.shoot(); 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