aboutsummaryrefslogtreecommitdiff
path: root/td
diff options
context:
space:
mode:
Diffstat (limited to 'td')
-rw-r--r--td/Assets/Prefabs/Enemies/Enemy.prefabbin7824 -> 7968 bytes
-rw-r--r--td/Assets/Prefabs/Towers/Guy One.prefabbin11536 -> 12040 bytes
-rw-r--r--td/Assets/Prefabs/projectiles.meta9
-rw-r--r--td/Assets/Scenes/Level 1.unitybin111964 -> 108444 bytes
-rw-r--r--td/Assets/Scripts/Enemy.cs8
-rw-r--r--td/Assets/Scripts/EnemySpawner.cs6
-rw-r--r--td/Assets/Scripts/gameStats.cs12
-rw-r--r--td/Assets/Scripts/player.cs22
-rw-r--r--td/Assets/Scripts/tower.cs13
9 files changed, 51 insertions, 19 deletions
diff --git a/td/Assets/Prefabs/Enemies/Enemy.prefab b/td/Assets/Prefabs/Enemies/Enemy.prefab
index fc3e820..88dcbcb 100644
--- a/td/Assets/Prefabs/Enemies/Enemy.prefab
+++ b/td/Assets/Prefabs/Enemies/Enemy.prefab
Binary files differ
diff --git a/td/Assets/Prefabs/Towers/Guy One.prefab b/td/Assets/Prefabs/Towers/Guy One.prefab
index de1c753..d0c904b 100644
--- a/td/Assets/Prefabs/Towers/Guy One.prefab
+++ b/td/Assets/Prefabs/Towers/Guy One.prefab
Binary files differ
diff --git a/td/Assets/Prefabs/projectiles.meta b/td/Assets/Prefabs/projectiles.meta
deleted file mode 100644
index b66e7d3..0000000
--- a/td/Assets/Prefabs/projectiles.meta
+++ /dev/null
@@ -1,9 +0,0 @@
-fileFormatVersion: 2
-guid: 1fd8e4afa918142cf86708ca153cfa3c
-folderAsset: yes
-timeCreated: 1507240769
-licenseType: Free
-DefaultImporter:
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/td/Assets/Scenes/Level 1.unity b/td/Assets/Scenes/Level 1.unity
index fbf4717..528d41c 100644
--- a/td/Assets/Scenes/Level 1.unity
+++ b/td/Assets/Scenes/Level 1.unity
Binary files differ
diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs
index eec02c9..4542902 100644
--- a/td/Assets/Scripts/Enemy.cs
+++ b/td/Assets/Scripts/Enemy.cs
@@ -6,9 +6,13 @@ public class Enemy : MonoBehaviour {
/* This is a general class that contains an enemy,
* Currently it follows the pathway, and dies when reacing the end */
+ [Header("Attributes")]
public float speed; // Speed multiplier
- public float initialHp; // HealthPoints
+ public int initialHp; // HealthPoints
+ public int damage;
public List<Vector3> waypoints; // Pathway waypoints, should be set by the spawner
+ [Header("Scripting vars")]
+ public player player; // Reference to the player object, should be set when instantiating
Vector3 waypointPos; // Current waypoint position
int waypointNum = -1; // Using minus one so that first addition returns 0, first element in array
@@ -24,7 +28,9 @@ public class Enemy : MonoBehaviour {
// Selfdestruct if object reached the end
if (waypointNum + 1 >= waypoints.Count) {
+ player.decreaseHealth (damage);
Destroy (gameObject);
+ return;
}
}
diff --git a/td/Assets/Scripts/EnemySpawner.cs b/td/Assets/Scripts/EnemySpawner.cs
index 74dc243..ee0d3d6 100644
--- a/td/Assets/Scripts/EnemySpawner.cs
+++ b/td/Assets/Scripts/EnemySpawner.cs
@@ -9,7 +9,10 @@ public class EnemySpawner : MonoBehaviour {
public Enemy enemyPrefab;
public Transform pathWay;
- Transform parentObject;
+ [Header("Scripting vars")]
+ public player player; // Reference to the player object, should be set when instantiating
+
+ private Transform parentObject;
List<Vector3> waypoints = new List<Vector3>();
int next = 1;
@@ -38,6 +41,7 @@ public class EnemySpawner : MonoBehaviour {
script.waypoints = waypoints;
script.speed = Random.Range (0.3f, 1.2f);
+ script.player = player;
transform.position = new Vector3 (0.93f, 0.483f, 0f);
}
diff --git a/td/Assets/Scripts/gameStats.cs b/td/Assets/Scripts/gameStats.cs
index af13f99..daeb3cf 100644
--- a/td/Assets/Scripts/gameStats.cs
+++ b/td/Assets/Scripts/gameStats.cs
@@ -9,13 +9,16 @@ public class gameStats : MonoBehaviour {
GameObject canvas;
Text txtMoney;
Text txtScore;
+ Text txtHp;
int displayedScore;
int displayedMoney;
+ int displayedHealth;
void Start() {
canvas = transform.GetChild (0).gameObject;
txtMoney = canvas.transform.Find ("playerMoney").gameObject.GetComponent <Text>();
txtScore = canvas.transform.Find ("playerScore").gameObject.GetComponent <Text>();
+ txtHp = canvas.transform.Find ("playerHealth").gameObject.GetComponent <Text>();
}
void Update () {
@@ -30,6 +33,11 @@ public class gameStats : MonoBehaviour {
updateScore (displayedScore);
}
+ if (Player.health () != displayedHealth) {
+ displayedHealth = Player.health ();
+ updateHealth (displayedHealth);
+ }
+
}
void updateScore(int newScore) {
@@ -40,4 +48,8 @@ public class gameStats : MonoBehaviour {
txtMoney.text = ("Money: " + newMoney.ToString () + "$");
}
+ void updateHealth(int newHp) {
+ txtHp.text = ("HP: " + newHp.ToString ());
+ }
+
}
diff --git a/td/Assets/Scripts/player.cs b/td/Assets/Scripts/player.cs
index b972477..4b23054 100644
--- a/td/Assets/Scripts/player.cs
+++ b/td/Assets/Scripts/player.cs
@@ -4,17 +4,17 @@ using UnityEngine;
public class player : MonoBehaviour {
+ public int initialHealth;
public int startingMoney;
- GameObject[] towers;
-
- int playerMoney;
- int playerScore;
-
- bool placingTower;
+ private GameObject[] towers;
+ private int playerMoney;
+ private int playerScore;
+ private int playerHealth;
void Awake() {
playerMoney = startingMoney;
+ playerHealth = initialHealth;
}
#region stats
@@ -22,7 +22,7 @@ public class player : MonoBehaviour {
return playerScore;
}
- public void score(int points) {
+ public void scoreAdd(int points) {
playerScore += points;
}
@@ -37,6 +37,14 @@ public class player : MonoBehaviour {
public void moneySubtract(int sum) {
playerMoney -= sum;
}
+
+ public int health() {
+ return playerHealth;
+ }
+
+ public void decreaseHealth(int hp) {
+ playerHealth -= hp;
+ }
#endregion
public void spawnTower(GameObject towerType) {
diff --git a/td/Assets/Scripts/tower.cs b/td/Assets/Scripts/tower.cs
index 0c812b2..bc8241c 100644
--- a/td/Assets/Scripts/tower.cs
+++ b/td/Assets/Scripts/tower.cs
@@ -10,6 +10,8 @@ public class tower : MonoBehaviour {
public float turnSpeed; // How fast the turret should rotate. Set in designer (tower prefab)
[Range(0, 10)]
public float towerRange; // How large the range of the tower is. this is the diameter. Set in designer (tower prefab)
+ public GameObject projectilePrefab;
+ public Transform firePoint;
[Header("Materials")]
public Material materialDanger; // The material used when tower can't be placed, set in the designer (tower prefab)
public Material materialSuccess; // The material used when the tower can be placed, or is selected, set in the designer (tower prefab)
@@ -83,6 +85,7 @@ public class tower : MonoBehaviour {
if (fireCountdown <= 0f) {
// FAIAAAAA
+ shoot();
fireCountdown = 1f / fireRate;
}
@@ -91,6 +94,15 @@ public class tower : MonoBehaviour {
}
+ void shoot() {
+ GameObject projectileGo = (GameObject) Instantiate (projectilePrefab, firePoint.position, firePoint.rotation);
+ projectile Projectile = projectileGo.GetComponent <projectile>();
+ if (Projectile != null) {
+ Projectile.player = player;
+ Projectile.seek (target);
+ }
+ }
+
void updateTarget() {
/* Method that updates the currentTarget.
* The target will be set to the nearest in range */
@@ -107,7 +119,6 @@ public class tower : MonoBehaviour {
}
if (nearestEnemy != null && shortestDistance <= towerRange) {
- Debug.Log ("Target aquired");
target = nearestEnemy.transform;
} else {
target = null;