Commit 2dc8aebd by Tim Reiter

implemented restart function after gameover.

parent 6f8584ed
......@@ -9,9 +9,14 @@ public class GameMaster : MonoBehaviour
public PlayerControl[] playerPrefabs;
public GameObject gameOverPanel;
public Text rankingText;
private GameStateTracker gameStateTracker;
private GameObject deleteAllChildrenAtRestart;
void Start()
{
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart");
gameStateTracker = GetComponent<GameStateTracker>();
levelLoader = new DeserializedLevelsLoader();
levelLoader.load();
}
......@@ -28,10 +33,15 @@ public class GameMaster : MonoBehaviour
private void deleteAllPlayers()
{
foreach (GameObject player in GameObject.FindGameObjectsWithTag("Player"))
Object.Destroy(player, 0f);
}
foreach (Transform child in deleteAllChildrenAtRestart.transform)
{
if (child != deleteAllChildrenAtRestart.gameObject)
{
Destroy(child.gameObject,0f);
}
}
}
private void spawnPlayers(int count)
{
Debug.Log("spawning " + count + " players");
......@@ -51,6 +61,8 @@ public class GameMaster : MonoBehaviour
playerPrefabs[i % playerPrefabs.Length],
startPositions[i].transform.position,
Quaternion.identity);
player.transform.parent = deleteAllChildrenAtRestart.transform;
player.init(i + 1);
}
}
......@@ -89,4 +101,24 @@ public class GameMaster : MonoBehaviour
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
private GameMaster gameMaster;
public int getNumberOfPlayers()
{
return numberOfPlayers;
}
void Awake()
{
ranking = new List<string>();
......@@ -30,9 +35,11 @@ public class GameStateTracker : MonoBehaviour
gameMaster = GetComponent<GameMaster>();
}
//clears the ranking and sets the time scale back to normal.
public void reset()
{
ranking.Clear();
Time.timeScale = 1.0f;
}
public void setNumberOfPlayers(int players)
......
......@@ -6,7 +6,7 @@ using GamepadInput;
public class PlayerControl : MonoBehaviour
{
private Rigidbody2D body2D;
private Transform deleteAllChildrenAtRestart;
public Transform groundCheck;
public LayerMask mask;
......@@ -57,6 +57,7 @@ public class PlayerControl : MonoBehaviour
void Start()
{
body2D = GetComponent<Rigidbody2D>();
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
}
public void init(int playerNumber)
......@@ -265,6 +266,7 @@ public class PlayerControl : MonoBehaviour
{
case POWERUP_HEALINGBULLET:
GameObject bullet = Instantiate(healingBulletPrefab, pos, transform.rotation) as GameObject;
bullet.transform.parent = deleteAllChildrenAtRestart.parent;
bullet.GetComponent<Bullet>().shoot(new Vector2(dir, 0));
break;
default:
......
......@@ -26,7 +26,7 @@ public class PlayerHealth : MonoBehaviour
}
healthbar = GameObject.Find(healthbarName).GetComponent<Scrollbar>();
healthbar.size = 1.0f;
if (name.EndsWith("(Clone)"))
{
name = name.Split(new char[] { '(' })[0];
......
......@@ -14,12 +14,14 @@ public class Rocket : MonoBehaviour
public Transform target;
public Animator explosionAnimator;
private GameObject explosion;
private Transform objectsToDeleteAtRestart;
#endregion
// Use this for initialization
void Start()
{
body = GetComponent<Rigidbody2D>();
objectsToDeleteAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
}
// Update is called once per frame
......@@ -46,6 +48,7 @@ public class Rocket : MonoBehaviour
//explosion effect:
explosion = GameObject.Instantiate(explosionAnimator.gameObject, transform.position, transform.rotation) as GameObject;
explosion.transform.parent = objectsToDeleteAtRestart;
gameObject.GetComponent<SpriteRenderer>().enabled = false;
gameObject.GetComponent<Collider2D>().enabled = false;
......
......@@ -15,10 +15,17 @@ public class Trap : MonoBehaviour
public GameObject destroyedEffectPrefab;
private Animator destroyedEffect;
private Transform deleteAllChildrenAtRestart;
void Start()
{
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
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.transform.parent = deleteAllChildrenAtRestart.transform;
}
void OnTriggerEnter2D(Collider2D other)
......
......@@ -7,7 +7,12 @@ public class Turret : MonoBehaviour
public GameObject rocketPrefab;
private Transform target;
private Rocket currentRocket;
private Transform deleteAllChildrenAtRestart;
void Start()
{
deleteAllChildrenAtRestart = GameObject.Find("ObjectsToDeleteAtRestart").transform;
}
// Update is called once per frame
void Update()
......@@ -28,6 +33,7 @@ public class Turret : MonoBehaviour
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.transform.parent = deleteAllChildrenAtRestart.transform;
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