Commit 2dc8aebd by Tim Reiter

implemented restart function after gameover.

parent 6f8584ed
...@@ -9,9 +9,14 @@ public class GameMaster : MonoBehaviour ...@@ -9,9 +9,14 @@ public class GameMaster : MonoBehaviour
public PlayerControl[] playerPrefabs; public PlayerControl[] playerPrefabs;
public GameObject gameOverPanel; public GameObject gameOverPanel;
public Text rankingText; public Text rankingText;
private GameStateTracker gameStateTracker;
private GameObject deleteAllChildrenAtRestart;
void Start() void Start()
{ {
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart");
gameStateTracker = GetComponent<GameStateTracker>();
levelLoader = new DeserializedLevelsLoader(); levelLoader = new DeserializedLevelsLoader();
levelLoader.load(); levelLoader.load();
} }
...@@ -28,10 +33,15 @@ public class GameMaster : MonoBehaviour ...@@ -28,10 +33,15 @@ public class GameMaster : MonoBehaviour
private void deleteAllPlayers() private void deleteAllPlayers()
{ {
foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player")) foreach (Transform child in deleteAllChildrenAtRestart.transform)
Object.Destroy(player, 0f); {
} if (child != deleteAllChildrenAtRestart.gameObject)
{
Destroy(child.gameObject,0f);
}
}
}
private void spawnPlayers(int count) private void spawnPlayers(int count)
{ {
Debug.Log("spawning " + count + " players"); Debug.Log("spawning " + count + " players");
...@@ -51,6 +61,8 @@ public class GameMaster : MonoBehaviour ...@@ -51,6 +61,8 @@ public class GameMaster : MonoBehaviour
playerPrefabs[i % playerPrefabs.Length], playerPrefabs[i % playerPrefabs.Length],
startPositions[i].transform.position, startPositions[i].transform.position,
Quaternion.identity); Quaternion.identity);
player.transform.parent = deleteAllChildrenAtRestart.transform;
player.init(i + 1); player.init(i + 1);
} }
} }
...@@ -89,4 +101,24 @@ public class GameMaster : MonoBehaviour ...@@ -89,4 +101,24 @@ public class GameMaster : MonoBehaviour
rankingText.text += "\n4th: " + ranking[3]; rankingText.text += "\n4th: " + ranking[3];
} }
} }
void Update()
{
if (gameOverPanel.activeSelf)
{
if (Input.GetKeyDown(KeyCode.Space))
{
gameStateTracker.reset();
loadLevel(gameStateTracker.getNumberOfPlayers()); //loads a new level randomly
rankingText.text = "";
gameOverPanel.SetActive(false);
}
else if (Input.GetKeyDown(KeyCode.Return))
{
}
}
}
} }
...@@ -19,6 +19,11 @@ public class GameStateTracker : MonoBehaviour ...@@ -19,6 +19,11 @@ public class GameStateTracker : MonoBehaviour
private GameMaster gameMaster; private GameMaster gameMaster;
public int getNumberOfPlayers()
{
return numberOfPlayers;
}
void Awake() void Awake()
{ {
ranking = new List<string>(); ranking = new List<string>();
...@@ -30,9 +35,11 @@ public class GameStateTracker : MonoBehaviour ...@@ -30,9 +35,11 @@ public class GameStateTracker : MonoBehaviour
gameMaster = GetComponent<GameMaster>(); gameMaster = GetComponent<GameMaster>();
} }
//clears the ranking and sets the time scale back to normal.
public void reset() public void reset()
{ {
ranking.Clear(); ranking.Clear();
Time.timeScale = 1.0f;
} }
public void setNumberOfPlayers(int players) public void setNumberOfPlayers(int players)
......
...@@ -6,7 +6,7 @@ using GamepadInput; ...@@ -6,7 +6,7 @@ using GamepadInput;
public class PlayerControl : MonoBehaviour public class PlayerControl : MonoBehaviour
{ {
private Rigidbody2D body2D; private Rigidbody2D body2D;
private Transform deleteAllChildrenAtRestart;
public Transform groundCheck; public Transform groundCheck;
public LayerMask mask; public LayerMask mask;
...@@ -57,6 +57,7 @@ public class PlayerControl : MonoBehaviour ...@@ -57,6 +57,7 @@ public class PlayerControl : MonoBehaviour
void Start() void Start()
{ {
body2D = GetComponent<Rigidbody2D>(); body2D = GetComponent<Rigidbody2D>();
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
} }
public void init(int playerNumber) public void init(int playerNumber)
...@@ -265,6 +266,7 @@ public class PlayerControl : MonoBehaviour ...@@ -265,6 +266,7 @@ public class PlayerControl : MonoBehaviour
{ {
case POWERUP_HEALINGBULLET: case POWERUP_HEALINGBULLET:
GameObject bullet = Instantiate(healingBulletPrefab, pos, transform.rotation) as GameObject; GameObject bullet = Instantiate(healingBulletPrefab, pos, transform.rotation) as GameObject;
bullet.transform.parent = deleteAllChildrenAtRestart.parent;
bullet.GetComponent<Bullet>().shoot(new Vector2(dir, 0)); bullet.GetComponent<Bullet>().shoot(new Vector2(dir, 0));
break; break;
default: default:
......
...@@ -26,7 +26,7 @@ public class PlayerHealth : MonoBehaviour ...@@ -26,7 +26,7 @@ public class PlayerHealth : MonoBehaviour
} }
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>(); healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
healthbar.size = 1.0f;
if (name.EndsWith("(Clone)")) if (name.EndsWith("(Clone)"))
{ {
name = name.Split(new char[] { '(' })[0]; name = name.Split(new char[] { '(' })[0];
......
...@@ -14,12 +14,14 @@ public class Rocket : MonoBehaviour ...@@ -14,12 +14,14 @@ public class Rocket : MonoBehaviour
public Transform target; public Transform target;
public Animator explosionAnimator; public Animator explosionAnimator;
private GameObject explosion; private GameObject explosion;
private Transform objectsToDeleteAtRestart;
#endregion #endregion
// Use this for initialization // Use this for initialization
void Start() void Start()
{ {
body = GetComponent<Rigidbody2D>(); body = GetComponent<Rigidbody2D>();
objectsToDeleteAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
} }
// Update is called once per frame // Update is called once per frame
...@@ -46,6 +48,7 @@ public class Rocket : MonoBehaviour ...@@ -46,6 +48,7 @@ public class Rocket : MonoBehaviour
//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;
explosion.transform.parent = objectsToDeleteAtRestart;
gameObject.GetComponent<SpriteRenderer>().enabled = false; gameObject.GetComponent<SpriteRenderer>().enabled = false;
gameObject.GetComponent<Collider2D>().enabled = false; gameObject.GetComponent<Collider2D>().enabled = false;
......
...@@ -15,10 +15,17 @@ public class Trap : MonoBehaviour ...@@ -15,10 +15,17 @@ public class Trap : MonoBehaviour
public GameObject destroyedEffectPrefab; public GameObject destroyedEffectPrefab;
private Animator destroyedEffect; private Animator destroyedEffect;
private Transform deleteAllChildrenAtRestart;
void Start() void Start()
{ {
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
hitEffect = (GameObject.Instantiate(hitEffectPrefab, transform.position, transform.rotation) as GameObject).GetComponent<Animator>(); hitEffect = (GameObject.Instantiate(hitEffectPrefab, transform.position, transform.rotation) as GameObject).GetComponent<Animator>();
hitEffect.transform.parent = deleteAllChildrenAtRestart.transform;
destroyedEffect = (GameObject.Instantiate(destroyedEffectPrefab, transform.position, transform.rotation) as GameObject).GetComponent<Animator>(); destroyedEffect = (GameObject.Instantiate(destroyedEffectPrefab, transform.position, transform.rotation) as GameObject).GetComponent<Animator>();
destroyedEffect.transform.parent = deleteAllChildrenAtRestart.transform;
} }
void OnTriggerEnter2D(Collider2D other) void OnTriggerEnter2D(Collider2D other)
......
...@@ -7,7 +7,12 @@ public class Turret : MonoBehaviour ...@@ -7,7 +7,12 @@ public class Turret : MonoBehaviour
public GameObject rocketPrefab; public GameObject rocketPrefab;
private Transform target; private Transform target;
private Rocket currentRocket; private Rocket currentRocket;
private Transform deleteAllChildrenAtRestart;
void Start()
{
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
}
// Update is called once per frame // Update is called once per frame
void Update() void Update()
...@@ -28,6 +33,7 @@ public class Turret : MonoBehaviour ...@@ -28,6 +33,7 @@ public class Turret : MonoBehaviour
if (currentRocket) return; // do not shoot another rocket when there is one already flying. if (currentRocket) return; // do not shoot another rocket when there is one already flying.
currentRocket = (GameObject.Instantiate(rocketPrefab, transform.position + 1.5f * (transform.rotation * Vector2.up), transform.rotation) as GameObject).GetComponent<Rocket>(); currentRocket = (GameObject.Instantiate(rocketPrefab, transform.position + 1.5f * (transform.rotation * Vector2.up), transform.rotation) as GameObject).GetComponent<Rocket>();
currentRocket.transform.parent = deleteAllChildrenAtRestart.transform;
currentRocket.setTarget(target); currentRocket.setTarget(target);
} }
} }
fileFormatVersion: 2
guid: 423a9169f3cb35946bcbaed7519e4da7
timeCreated: 1433592992
licenseType: Free
TextureImporter:
fileIDToRecycleName: {}
serializedVersion: 2
mipmaps:
mipMapMode: 0
enableMipMap: 1
linearTexture: 0
correctGamma: 0
fadeOut: 0
borderMipMap: 0
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: .25
normalMapFilter: 0
isReadable: 0
grayScaleToAlpha: 0
generateCubemap: 0
cubemapConvolution: 0
cubemapConvolutionSteps: 8
cubemapConvolutionExponent: 1.5
seamlessCubemap: 0
textureFormat: -1
maxTextureSize: 2048
textureSettings:
filterMode: -1
aniso: -1
mipBias: -1
wrapMode: 1
nPOTScale: 0
lightmap: 0
rGBM: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: .5, y: .5}
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spritePixelsToUnits: 100
alphaIsTransparency: 1
textureType: 8
buildTargetSettings: []
spriteSheet:
sprites: []
spritePackingTag:
userData:
assetBundleName:
assetBundleVariant:
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