Added a bunch of stuff

This commit is contained in:
2018-04-10 23:53:49 +10:00
parent efe1cd63f5
commit ba4b01653d
33 changed files with 2120 additions and 65 deletions
+43
View File
@@ -0,0 +1,43 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Background : MonoBehaviour {
SpriteRenderer spriteRenderer;
void Awake() {
spriteRenderer = GetComponent<SpriteRenderer> ();
StartFade (0.1f);
}
void StartFade(float period) {
if (period <= 0) {
throw new System.ArgumentOutOfRangeException("StartFade argument must be a positive floating point value");
}
StartCoroutine (FadeCoroutine (period));
}
IEnumerator FadeCoroutine(float period) {
float absolute = 1.0f;
float degree = -0.01f;
const float lowerLimit = 0.8f;
const float upperLimit = 1.0f;
while(true) {
//wait
yield return new WaitForSeconds (period);
//fade routine
absolute += degree;
//flip fade direction
if (absolute <= lowerLimit || absolute >= upperLimit) {
degree = -degree;
}
//fade
spriteRenderer.color = new Color (absolute, absolute, absolute);
}
}
}
+13
View File
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 72cfcd727b69cf543893b4d457e109e1
timeCreated: 1523360847
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+27
View File
@@ -1,11 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameController : MonoBehaviour {
public Text timerText;
public Text scoreText;
void Awake() {
PersistentData.timer = 60;
PersistentData.score = 0;
StartCoroutine (DecreaseTick ());
}
void Update() {
if (Input.GetButtonDown ("Quit")) {
Application.Quit ();
}
if (PersistentData.timer <= 0) {
SceneManager.LoadScene ("gameover");
}
//update the texts
timerText.text = "Time Remaining: " + PersistentData.timer;
scoreText.text = "Score: " + PersistentData.score;
}
IEnumerator DecreaseTick() {
while (PersistentData.timer > 0) {
yield return new WaitForSeconds (1);
PersistentData.timer -= 1;
}
}
}
+22
View File
@@ -0,0 +1,22 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class GameOverController : MonoBehaviour {
public Text scoreText;
void Update() {
if (Input.GetButtonDown ("Quit")) {
Application.Quit ();
}
if (Input.GetMouseButtonDown(0)) {
SceneManager.LoadScene ("gameplay");
}
//update the texts
scoreText.text = "Score: " + PersistentData.score;
}
}
+13
View File
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 50cbb78cd78265f4fb87277d95bcd4ee
timeCreated: 1523366783
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
+13
View File
@@ -3,9 +3,22 @@ using System.Collections.Generic;
using UnityEngine;
public class Monster : MonoBehaviour {
public int value;
void Awake() {
StartCoroutine (DestroySelfAfter (30f));
}
void OnMouseOver() {
if (Input.GetMouseButtonDown(0)) {
//TODO: play death sound
PersistentData.score += value;
Destroy (gameObject);
}
}
IEnumerator DestroySelfAfter(float seconds) {
yield return new WaitForSeconds (seconds);
Destroy (gameObject);
}
}
+5
View File
@@ -7,7 +7,11 @@ public class MonsterSpawner : MonoBehaviour {
public Vector2 motion;
public float delay;
AudioSource audioSource;
void Awake() {
audioSource = GetComponent<AudioSource> ();
StartCoroutine (SpawnMonster ());
}
@@ -17,6 +21,7 @@ public class MonsterSpawner : MonoBehaviour {
GameObject monster = Instantiate (monsterPrefab);
monster.transform.position = transform.position;
monster.GetComponent<Rigidbody2D> ().velocity = motion;
audioSource.Play ();
}
}
}
+4
View File
@@ -0,0 +1,4 @@
public static class PersistentData {
public static int timer;
public static int score;
}
+13
View File
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 62a6fdc5749705b45941916987edc9c7
timeCreated: 1523365472
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: