Commit 8d61ac10 by Alisa Jung

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

parent d87c20d0
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>();
}
......
......@@ -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");
}
}
......@@ -34,7 +34,7 @@ public class DeserializedLevelsLoader
// Cache prefabs in prefabDict
Dictionary<string,GameObject> prefabPool;
Dictionary<string, GameObject> prefabPool;
// Cache all items with locations
List<ItemStruct> sceneItemsList;
......@@ -43,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();
......@@ -56,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();
......@@ -68,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;
......@@ -167,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();
......@@ -87,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