aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'td/Assets/Scripts')
-rw-r--r--td/Assets/Scripts/Enemy.cs31
-rw-r--r--td/Assets/Scripts/EnemySpawner.cs37
-rw-r--r--td/Assets/Scripts/Projectile.cs42
-rw-r--r--td/Assets/Scripts/Projectile.cs.meta12
-rw-r--r--td/Assets/Scripts/cameraHandler.cs66
-rw-r--r--td/Assets/Scripts/castle.cs23
-rw-r--r--td/Assets/Scripts/castle.cs.meta12
-rw-r--r--td/Assets/Scripts/developerMode.cs56
-rw-r--r--td/Assets/Scripts/enableChild.cs2
-rw-r--r--td/Assets/Scripts/gameStats.cs56
-rw-r--r--td/Assets/Scripts/mainGUI.cs122
-rw-r--r--td/Assets/Scripts/player.cs53
-rw-r--r--td/Assets/Scripts/tower.cs112
-rw-r--r--td/Assets/Scripts/waveSpawner.cs44
14 files changed, 376 insertions, 292 deletions
diff --git a/td/Assets/Scripts/Enemy.cs b/td/Assets/Scripts/Enemy.cs
index 4542902..3074003 100644
--- a/td/Assets/Scripts/Enemy.cs
+++ b/td/Assets/Scripts/Enemy.cs
@@ -1,5 +1,4 @@
-using System.Collections;
-using System.Collections.Generic;
+using System.Collections.Generic;
using UnityEngine;
public class Enemy : MonoBehaviour {
@@ -7,28 +6,28 @@ public class Enemy : MonoBehaviour {
* Currently it follows the pathway, and dies when reacing the end */
[Header("Attributes")]
- public float speed; // Speed multiplier
- public int initialHp; // HealthPoints
- public int damage;
- public List<Vector3> waypoints; // Pathway waypoints, should be set by the spawner
+ public float Speed; // Speed multiplier
+ 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
+ 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
+ private Vector3 _waypointPos; // Current waypoint position
+ private int _waypointNum = -1; // Using minus one so that first addition returns 0, first element in array
void Update () {
- if ( (transform.position == waypointPos && waypointNum + 1 < waypoints.Count) || waypointNum == -1) {
- waypointNum++;
- waypointPos = new Vector3 (waypoints [waypointNum].x, 0.483f, waypoints [waypointNum].z);
+ if ( (transform.position == _waypointPos && _waypointNum + 1 < Waypoints.Count) || _waypointNum == -1) {
+ _waypointNum++;
+ _waypointPos = new Vector3 (Waypoints [_waypointNum].x, 0.483f, Waypoints [_waypointNum].z);
}
- float transformStep = speed * Time.deltaTime;
- transform.position = Vector3.MoveTowards (transform.position, waypointPos, transformStep);
+ float transformStep = Speed * Time.deltaTime;
+ transform.position = Vector3.MoveTowards (transform.position, _waypointPos, transformStep);
// Selfdestruct if object reached the end
- if (waypointNum + 1 >= waypoints.Count) {
- player.decreaseHealth (damage);
+ 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 ee0d3d6..7ee8680 100644
--- a/td/Assets/Scripts/EnemySpawner.cs
+++ b/td/Assets/Scripts/EnemySpawner.cs
@@ -6,42 +6,41 @@ public class EnemySpawner : MonoBehaviour {
/* This is a class that spawns an enemy with a random interval
* it is not very good, but is what it needs to be for testing purposes */
// TODO Add wave system with increasing difficulty
-
- public Enemy enemyPrefab;
- public Transform pathWay;
+ public Enemy EnemyPrefab;
+ public Transform PathWay;
[Header("Scripting vars")]
- public player player; // Reference to the player object, should be set when instantiating
+ public Player Player; // Reference to the player object, should be set when instantiating
- private Transform parentObject;
+ private Transform _parentObject;
- List<Vector3> waypoints = new List<Vector3>();
- int next = 1;
- int n = 0;
+ List<Vector3> _waypoints = new List<Vector3>();
+ int _next = 1;
+ int _n = 0;
void Awake() {
- foreach (Transform child in pathWay) {
- waypoints.Add (child.position);
+ foreach (Transform child in PathWay) {
+ _waypoints.Add (child.position);
}
}
void Start() {
- parentObject = transform.Find ("enemies").gameObject.GetComponent <Transform> ();
+ _parentObject = transform.Find ("enemies").gameObject.GetComponent <Transform> ();
}
void Update () {
- n++;
+ _n++;
- if (n == next) {
- n = 0;
- next = (int)Random.Range (50, 400);
+ if (_n == _next) {
+ _n = 0;
+ _next = (int)Random.Range (50, 400);
- Enemy newEnemy = Instantiate (enemyPrefab, new Vector3(0, 0, 0), Quaternion.identity, parentObject);
+ Enemy newEnemy = Instantiate (EnemyPrefab, new Vector3(0, 0, 0), Quaternion.identity, _parentObject);
Enemy script = newEnemy.GetComponent <Enemy> ();
Transform transform = newEnemy.GetComponent <Transform>();
- script.waypoints = waypoints;
- script.speed = Random.Range (0.3f, 1.2f);
- script.player = player;
+ 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/Projectile.cs b/td/Assets/Scripts/Projectile.cs
new file mode 100644
index 0000000..0cdef16
--- /dev/null
+++ b/td/Assets/Scripts/Projectile.cs
@@ -0,0 +1,42 @@
+using UnityEngine;
+
+public class Projectile : MonoBehaviour {
+
+ public float Speed = 70f;
+ public int PointsPerHit;
+ [Header("Scripting vars")]
+ public Player Player; // Reference to the player object, should be set when instantiating
+ private Transform _target;
+
+ public void Seek(Transform target) {
+ _target = target;
+ }
+
+
+ void Update () {
+
+ if (_target == null) {
+ Destroy (gameObject);
+ return;
+ }
+
+ Vector3 direction = _target.position - transform.position;
+ float distanceThisFrame = Speed * Time.deltaTime;
+
+ if (direction.magnitude <= distanceThisFrame) {
+ HitTarget ();
+ return;
+ }
+
+ transform.Translate (direction.normalized * distanceThisFrame, Space.World);
+
+
+ }
+
+ void HitTarget() {
+ Player.ScoreAdd (PointsPerHit);
+ Destroy (_target.gameObject);
+ Destroy (gameObject);
+ }
+
+}
diff --git a/td/Assets/Scripts/Projectile.cs.meta b/td/Assets/Scripts/Projectile.cs.meta
new file mode 100644
index 0000000..a95b993
--- /dev/null
+++ b/td/Assets/Scripts/Projectile.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 4a1928566183240ea8566b659c4b3d5f
+timeCreated: 1507300755
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/td/Assets/Scripts/cameraHandler.cs b/td/Assets/Scripts/cameraHandler.cs
index c1c4cae..1655509 100644
--- a/td/Assets/Scripts/cameraHandler.cs
+++ b/td/Assets/Scripts/cameraHandler.cs
@@ -1,8 +1,6 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
+using UnityEngine;
-public class cameraHandler : MonoBehaviour {
+public class CameraHandler : MonoBehaviour {
// TODO Fiks panning, ser idiotisk ut nå så jeg har satt panSpeed til 0. (I editoren)
public float PanSpeed = 20f;
@@ -14,17 +12,17 @@ public class cameraHandler : MonoBehaviour {
public static readonly float[] BoundsZ = new float[]{-8f, 8f};
public static readonly float[] ZoomBounds = new float[]{1f, 5f};
- private Camera cam;
+ private Camera _cam;
- private bool panActive;
- private Vector3 lastPanPosition;
- private int panFingerId; // Touch mode only
+ private bool _panActive;
+ private Vector3 _lastPanPosition;
+ private int _panFingerId; // Touch mode only
- private bool zoomActive;
- private Vector2[] lastZoomPositions; // Touch mode only
+ private bool _zoomActive;
+ private Vector2[] _lastZoomPositions; // Touch mode only
void Awake() {
- cam = GetComponent<Camera>();
+ _cam = GetComponent<Camera>();
}
void Update() {
@@ -46,43 +44,43 @@ public class cameraHandler : MonoBehaviour {
switch(Input.touchCount) {
case 1: // Panning
- zoomActive = false;
+ _zoomActive = false;
// If the touch began, capture its position and its finger ID.
// Otherwise, if the finger ID of the touch doesn't match, skip it.
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Began) {
- lastPanPosition = touch.position;
- panFingerId = touch.fingerId;
- panActive = true;
- } else if (touch.fingerId == panFingerId && touch.phase == TouchPhase.Moved) {
+ _lastPanPosition = touch.position;
+ _panFingerId = touch.fingerId;
+ _panActive = true;
+ } else if (touch.fingerId == _panFingerId && touch.phase == TouchPhase.Moved) {
PanCamera(touch.position);
}
break;
case 2: // Zooming
- panActive = false;
+ _panActive = false;
Vector2[] newPositions = new Vector2[]{Input.GetTouch(0).position, Input.GetTouch(1).position};
- if (!zoomActive) {
- lastZoomPositions = newPositions;
- zoomActive = true;
+ if (!_zoomActive) {
+ _lastZoomPositions = newPositions;
+ _zoomActive = true;
} else {
// Zoom based on the distance between the new positions compared to the
// distance between the previous positions.
float newDistance = Vector2.Distance(newPositions[0], newPositions[1]);
- float oldDistance = Vector2.Distance(lastZoomPositions[0], lastZoomPositions[1]);
+ float oldDistance = Vector2.Distance(_lastZoomPositions[0], _lastZoomPositions[1]);
float offset = newDistance - oldDistance;
ZoomCamera(offset, ZoomSpeedTouch);
- lastZoomPositions = newPositions;
+ _lastZoomPositions = newPositions;
}
break;
default:
- panActive = false;
- zoomActive = false;
+ _panActive = false;
+ _zoomActive = false;
break;
}
}
@@ -92,41 +90,41 @@ public class cameraHandler : MonoBehaviour {
// On mouse up, disable panning.
// If there is no mouse being pressed, do nothing.
if (Input.GetMouseButtonDown(0)) {
- panActive = true;
- lastPanPosition = Input.mousePosition;
+ _panActive = true;
+ _lastPanPosition = Input.mousePosition;
} else if (Input.GetMouseButtonUp(0)) {
- panActive = false;
+ _panActive = false;
} else if (Input.GetMouseButton(0)) {
PanCamera(Input.mousePosition);
}
// Check for scrolling to zoom the camera
float scroll = Input.GetAxis("Mouse ScrollWheel");
- zoomActive = true;
+ _zoomActive = true;
ZoomCamera(scroll, ZoomSpeedMouse);
- zoomActive = false;
+ _zoomActive = false;
}
void ZoomCamera(float offset, float speed) {
- if (!zoomActive || offset == 0) {
+ if (!_zoomActive || offset == 0) {
return;
}
- cam.orthographicSize = Mathf.Clamp(cam.orthographicSize - (offset * speed), ZoomBounds[0], ZoomBounds[1]);
+ _cam.orthographicSize = Mathf.Clamp(_cam.orthographicSize - (offset * speed), ZoomBounds[0], ZoomBounds[1]);
}
void PanCamera(Vector3 newPanPosition) {
- if (!panActive) {
+ if (!_panActive) {
return;
}
// Translate the camera position based on the new input position
- Vector3 offset = cam.ScreenToViewportPoint(lastPanPosition - newPanPosition);
+ Vector3 offset = _cam.ScreenToViewportPoint(_lastPanPosition - newPanPosition);
Vector3 move = new Vector3(offset.x * PanSpeed, offset.y * PanSpeed, 0f);
transform.Translate(move, Space.World);
ClampToBounds();
- lastPanPosition = newPanPosition;
+ _lastPanPosition = newPanPosition;
}
void ClampToBounds() {
diff --git a/td/Assets/Scripts/castle.cs b/td/Assets/Scripts/castle.cs
new file mode 100644
index 0000000..5c8835c
--- /dev/null
+++ b/td/Assets/Scripts/castle.cs
@@ -0,0 +1,23 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+public class Castle : MonoBehaviour {
+
+ private void Update () {
+ //CheckThing();
+ }
+
+ private void CheckThing() {
+ GameObject[] enemies = GameObject.FindGameObjectsWithTag ("enemy");
+
+ foreach (var enemy in enemies) {
+ var distanceToEnemy = Vector3.Distance (transform.position, enemy.transform.position);
+ if (distanceToEnemy <= 0) {
+ Debug.Log("INTRUDER!");
+ }
+ }
+ }
+
+
+}
diff --git a/td/Assets/Scripts/castle.cs.meta b/td/Assets/Scripts/castle.cs.meta
new file mode 100644
index 0000000..246ac0b
--- /dev/null
+++ b/td/Assets/Scripts/castle.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: c6004dcebebd0498389086d43a3bd6fa
+timeCreated: 1507302323
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/td/Assets/Scripts/developerMode.cs b/td/Assets/Scripts/developerMode.cs
index 4f241cf..a71d4c7 100644
--- a/td/Assets/Scripts/developerMode.cs
+++ b/td/Assets/Scripts/developerMode.cs
@@ -3,49 +3,49 @@ using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
-public class developerMode : MonoBehaviour {
+public class DeveloperMode : MonoBehaviour {
- public string output = "";
- public string stack = "";
- public bool cheatsAllowed;
+ public string Output = "";
+ public string Stack = "";
+ public bool CheatsAllowed;
- GameObject pnlCanvas;
- GameObject pnlCheats;
- Button btnToggleCheats;
- Text lblConsoleLog;
+ GameObject _pnlCanvas;
+ GameObject _pnlCheats;
+ Button _btnToggleCheats;
+ Text _lblConsoleLog;
- bool developerModeActive;
- bool cheatMenuOpen;
+ bool _developerModeActive;
+ bool _cheatMenuOpen;
void Start () {
/* Panels */
- pnlCanvas = this.gameObject.transform.GetChild (0).gameObject;
- pnlCheats = pnlCanvas.transform.Find ("cheatMenu").gameObject;
+ _pnlCanvas = this.gameObject.transform.GetChild (0).gameObject;
+ _pnlCheats = _pnlCanvas.transform.Find ("cheatMenu").gameObject;
/* Buttons */
/* Button handlers */
/* Lablels */
- lblConsoleLog = pnlCanvas.transform.Find ("consoleLog").gameObject.GetComponent <Text>();
+ _lblConsoleLog = _pnlCanvas.transform.Find ("consoleLog").gameObject.GetComponent <Text>();
/* Do setup */
- lblConsoleLog.text = "";
+ _lblConsoleLog.text = "";
- if (cheatsAllowed) {
- btnToggleCheats = pnlCanvas.transform.Find ("toggleCheats").gameObject.GetComponent <Button> ();
- if (btnToggleCheats != null) { btnToggleCheats.onClick.AddListener (btnToggleCheatsHandler); }
- cheatMenuOpen = false;
+ if (CheatsAllowed) {
+ _btnToggleCheats = _pnlCanvas.transform.Find ("toggleCheats").gameObject.GetComponent <Button> ();
+ if (_btnToggleCheats != null) { _btnToggleCheats.onClick.AddListener (btnToggleCheatsHandler); }
+ _cheatMenuOpen = false;
} else {
- pnlCanvas.transform.Find ("toggleCheats").gameObject.SetActive (false);
+ _pnlCanvas.transform.Find ("toggleCheats").gameObject.SetActive (false);
}
- pnlCheats.SetActive (false);
+ _pnlCheats.SetActive (false);
}
void Update () {
if (PlayerPrefs.HasKey ("developerMode")) {
- if (PlayerPrefs.GetInt ("developerMode") == 1) { developerModeActive = true; }
- else { developerModeActive = false; }
+ if (PlayerPrefs.GetInt ("developerMode") == 1) { _developerModeActive = true; }
+ else { _developerModeActive = false; }
}
- if (developerModeActive) {
+ if (_developerModeActive) {
this.gameObject.transform.GetChild (0).gameObject.SetActive (true);
} else {
this.gameObject.transform.GetChild (0).gameObject.SetActive (false);
@@ -54,9 +54,9 @@ public class developerMode : MonoBehaviour {
void btnToggleCheatsHandler() {
/* Handler for btnToggleCheats */
- if (cheatsAllowed) {
- cheatMenuOpen = !cheatMenuOpen;
- pnlCheats.SetActive (cheatMenuOpen);
+ if (CheatsAllowed) {
+ _cheatMenuOpen = !_cheatMenuOpen;
+ _pnlCheats.SetActive (_cheatMenuOpen);
}
}
@@ -68,8 +68,8 @@ public class developerMode : MonoBehaviour {
Application.logMessageReceived -= HandleLog;
}
public void HandleLog(string logString, string stackTrace, LogType type) {
- string backLog = lblConsoleLog.text;
- lblConsoleLog.text = logString + "\n" + backLog;
+ string backLog = _lblConsoleLog.text;
+ _lblConsoleLog.text = logString + "\n" + backLog;
}
#endregion
diff --git a/td/Assets/Scripts/enableChild.cs b/td/Assets/Scripts/enableChild.cs
index 50c7844..cba9375 100644
--- a/td/Assets/Scripts/enableChild.cs
+++ b/td/Assets/Scripts/enableChild.cs
@@ -2,7 +2,7 @@
using System.Collections.Generic;
using UnityEngine;
-public class enableChild : MonoBehaviour {
+public class EnableChild : MonoBehaviour {
/* Denne klassen gjør ikke annet enn å aktivere det første childobjektet,
* nyttig om man vil skjule objekter når man designer,
* slik at man slipper å drive å skru objektene av og på mellom hver test manuelt */
diff --git a/td/Assets/Scripts/gameStats.cs b/td/Assets/Scripts/gameStats.cs
index daeb3cf..7c305fa 100644
--- a/td/Assets/Scripts/gameStats.cs
+++ b/td/Assets/Scripts/gameStats.cs
@@ -3,53 +3,53 @@ using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
-public class gameStats : MonoBehaviour {
+public class GameStats : MonoBehaviour {
- public player Player;
- GameObject canvas;
- Text txtMoney;
- Text txtScore;
- Text txtHp;
- int displayedScore;
- int displayedMoney;
- int displayedHealth;
+ public Player Player;
+ 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>();
+ _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 () {
- if (Player.money () != displayedMoney) {
- displayedMoney = Player.money ();
- updateMoney (displayedMoney);
+ if (Player.Money () != _displayedMoney) {
+ _displayedMoney = Player.Money ();
+ UpdateMoney (_displayedMoney);
}
- if (Player.score () != displayedScore) {
- displayedScore = Player.score ();
- updateScore (displayedScore);
+ if (Player.Score () != _displayedScore) {
+ _displayedScore = Player.Score ();
+ UpdateScore (_displayedScore);
}
- if (Player.health () != displayedHealth) {
- displayedHealth = Player.health ();
- updateHealth (displayedHealth);
+ if (Player.Health () != _displayedHealth) {
+ _displayedHealth = Player.Health ();
+ UpdateHealth (_displayedHealth);
}
}
- void updateScore(int newScore) {
- txtScore.text = ("Score: " + newScore.ToString ());
+ void UpdateScore(int newScore) {
+ _txtScore.text = ("Score: " + newScore.ToString ());
}
- void updateMoney(int newMoney) {
- txtMoney.text = ("Money: " + newMoney.ToString () + "$");
+ void UpdateMoney(int newMoney) {
+ _txtMoney.text = ("Money: " + newMoney.ToString () + "$");
}
- void updateHealth(int newHp) {
- txtHp.text = ("HP: " + newHp.ToString ());
+ void UpdateHealth(int newHp) {
+ _txtHp.text = ("HP: " + newHp.ToString ());
}
}
diff --git a/td/Assets/Scripts/mainGUI.cs b/td/Assets/Scripts/mainGUI.cs
index d9fb955..1c18a17 100644
--- a/td/Assets/Scripts/mainGUI.cs
+++ b/td/Assets/Scripts/mainGUI.cs
@@ -4,76 +4,76 @@ using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
-public class mainGUI : MonoBehaviour {
+public class MainGui : MonoBehaviour {
- GameObject pnlMenu;
- GameObject pnlSidebar;
- GameObject pnlSettings;
- RectTransform pnlSidebarTransform;
- Button btnToggleSidebar;
- Button btnPauseGame;
- Button btnResumeGame;
- Button btnExitGame;
- Button btnSettings;
- Button btnSettingsDiscard;
- Button btnSettingsSave;
+ GameObject _pnlMenu;
+ GameObject _pnlSidebar;
+ GameObject _pnlSettings;
+ RectTransform _pnlSidebarTransform;
+ Button _btnToggleSidebar;
+ Button _btnPauseGame;
+ Button _btnResumeGame;
+ Button _btnExitGame;
+ Button _btnSettings;
+ Button _btnSettingsDiscard;
+ Button _btnSettingsSave;
- bool sidebarExpanded;
- float[] sidebarStates = new float[2] {0f, -202.4f}; // The x position of the sidebar expanded or collapsed
+ bool _sidebarExpanded;
+ float[] _sidebarStates = new float[2] {0f, -202.4f}; // The x position of the sidebar expanded or collapsed
- bool menuActive;
+ bool _menuActive;
void Awake() {
/* Panels */
- pnlMenu = transform.Find ("menu").gameObject;
- pnlSidebar = transform.Find ("sidebarWrapper").gameObject;
- pnlSettings = transform.Find ("settings").gameObject;
- pnlSidebarTransform = pnlSidebar.GetComponent <RectTransform> ();
+ _pnlMenu = transform.Find ("menu").gameObject;
+ _pnlSidebar = transform.Find ("sidebarWrapper").gameObject;
+ _pnlSettings = transform.Find ("settings").gameObject;
+ _pnlSidebarTransform = _pnlSidebar.GetComponent <RectTransform> ();
/* Buttons */
- btnToggleSidebar = pnlSidebar.transform.Find("toggleSidebar").gameObject.GetComponent <Button> ();
- btnPauseGame = pnlSidebar.transform.Find ("pauseGame").gameObject.GetComponent <Button> ();
- btnResumeGame = pnlMenu.transform.Find ("resumeGame").gameObject.GetComponent <Button> ();
- btnExitGame = pnlMenu.transform.Find ("exitGame").gameObject.GetComponent <Button> ();
- btnSettings = pnlMenu.transform.Find ("settings").gameObject.GetComponent <Button> ();
- btnSettingsDiscard = pnlSettings.transform.Find ("discardChanges").gameObject.GetComponent <Button> ();
- btnSettingsSave = pnlSettings.transform.Find ("saveChanges").gameObject.GetComponent <Button> ();
- if (btnToggleSidebar != null) { btnToggleSidebar.onClick.AddListener (toggleSidebarHandler); }
- if (btnPauseGame != null) { btnPauseGame.onClick.AddListener (pauseGameHandler); }
- if (btnResumeGame != null) { btnResumeGame.onClick.AddListener (btnResumeGameHandler); }
- if (btnExitGame != null) { btnExitGame.onClick.AddListener (btnExitGameHandler); }
- if (btnSettings != null) { btnSettings.onClick.AddListener (btnSettingsHandler); }
- if (btnSettingsDiscard != null) { btnSettingsDiscard.onClick.AddListener (btnSettingsDiscardHandler); }
- if (btnSettingsSave != null) { btnSettingsSave.onClick.AddListener (btnSettingsSaveHandler); }
+ _btnToggleSidebar = _pnlSidebar.transform.Find("toggleSidebar").gameObject.GetComponent <Button> ();
+ _btnPauseGame = _pnlSidebar.transform.Find ("pauseGame").gameObject.GetComponent <Button> ();
+ _btnResumeGame = _pnlMenu.transform.Find ("resumeGame").gameObject.GetComponent <Button> ();
+ _btnExitGame = _pnlMenu.transform.Find ("exitGame").gameObject.GetComponent <Button> ();
+ _btnSettings = _pnlMenu.transform.Find ("settings").gameObject.GetComponent <Button> ();
+ _btnSettingsDiscard = _pnlSettings.transform.Find ("discardChanges").gameObject.GetComponent <Button> ();
+ _btnSettingsSave = _pnlSettings.transform.Find ("saveChanges").gameObject.GetComponent <Button> ();
+ if (_btnToggleSidebar != null) { _btnToggleSidebar.onClick.AddListener (toggleSidebarHandler); }
+ if (_btnPauseGame != null) { _btnPauseGame.onClick.AddListener (pauseGameHandler); }
+ if (_btnResumeGame != null) { _btnResumeGame.onClick.AddListener (btnResumeGameHandler); }
+ if (_btnExitGame != null) { _btnExitGame.onClick.AddListener (btnExitGameHandler); }
+ if (_btnSettings != null) { _btnSettings.onClick.AddListener (btnSettingsHandler); }
+ if (_btnSettingsDiscard != null) { _btnSettingsDiscard.onClick.AddListener (btnSettingsDiscardHandler); }
+ if (_btnSettingsSave != null) { _btnSettingsSave.onClick.AddListener (btnSettingsSaveHandler); }
/* Set up initial states */
- updateSidebarPosandBtn ();
- pnlMenu.SetActive (false);
- pnlSettings.SetActive (false);
+ UpdateSidebarPosandBtn ();
+ _pnlMenu.SetActive (false);
+ _pnlSettings.SetActive (false);
}
void toggleSidebarHandler() {
/* handler for btnToggleSidebar */
- sidebarExpanded = !sidebarExpanded;
- updateSidebarPosandBtn ();
+ _sidebarExpanded = !_sidebarExpanded;
+ UpdateSidebarPosandBtn ();
}
void pauseGameHandler() {
/* handler for btnPauseGame */
- menuActive = true;
- pnlMenu.SetActive (menuActive);
+ _menuActive = true;
+ _pnlMenu.SetActive (_menuActive);
Time.timeScale = 0.0F;
- btnToggleSidebar.interactable = false;
- btnPauseGame.interactable = false;
+ _btnToggleSidebar.interactable = false;
+ _btnPauseGame.interactable = false;
}
void btnResumeGameHandler() {
/* handler for btnResumeGame */
- menuActive = false;
- pnlMenu.SetActive (menuActive);
+ _menuActive = false;
+ _pnlMenu.SetActive (_menuActive);
Time.timeScale = 1.0F;
- btnToggleSidebar.interactable = true;
- btnPauseGame.interactable = true;
+ _btnToggleSidebar.interactable = true;
+ _btnPauseGame.interactable = true;
}
void btnExitGameHandler() {
@@ -83,40 +83,40 @@ public class mainGUI : MonoBehaviour {
void btnSettingsHandler() {
/* handler for btnSettings */
- pnlMenu.SetActive (false);
- pnlSettings.SetActive (true);
+ _pnlMenu.SetActive (false);
+ _pnlSettings.SetActive (true);
if (PlayerPrefs.HasKey ("developerMode")) {
- pnlSettings.transform.Find ("developerEnabled").gameObject.GetComponent <Toggle> ().isOn = intToBool(PlayerPrefs.GetInt ("developerMode"));
+ _pnlSettings.transform.Find ("developerEnabled").gameObject.GetComponent <Toggle> ().isOn = IntToBool(PlayerPrefs.GetInt ("developerMode"));
}
}
void btnSettingsSaveHandler() {
/* handler for btnSaveSettings */
- pnlMenu.SetActive (true);
- pnlSettings.SetActive (false);
+ _pnlMenu.SetActive (true);
+ _pnlSettings.SetActive (false);
- PlayerPrefs.SetInt ("developerMode", Convert.ToInt32(pnlSettings.transform.Find ("developerEnabled").gameObject.GetComponent <Toggle>().isOn));
+ PlayerPrefs.SetInt ("developerMode", Convert.ToInt32(_pnlSettings.transform.Find ("developerEnabled").gameObject.GetComponent <Toggle>().isOn));
}
void btnSettingsDiscardHandler() {
/* handler for btnSettingsDiscard */
- pnlMenu.SetActive (true);
- pnlSettings.SetActive (false);
+ _pnlMenu.SetActive (true);
+ _pnlSettings.SetActive (false);
}
- void updateSidebarPosandBtn() {
+ void UpdateSidebarPosandBtn() {
/* update state of sidebar based on the expanded var */
- if (sidebarExpanded) {
- pnlSidebarTransform.localPosition = new Vector3 (sidebarStates [1], 0f, 0f);
- btnToggleSidebar.transform.GetComponent <RectTransform> ().localScale = new Vector3 (-1, 1, 1);
+ if (_sidebarExpanded) {
+ _pnlSidebarTransform.localPosition = new Vector3 (_sidebarStates [1], 0f, 0f);
+ _btnToggleSidebar.transform.GetComponent <RectTransform> ().localScale = new Vector3 (-1, 1, 1);
} else {
- pnlSidebarTransform.localPosition = new Vector3 (sidebarStates [0], 0f, 0f);
- btnToggleSidebar.transform.GetComponent <RectTransform> ().localScale = new Vector3 (1, 1, 1);
+ _pnlSidebarTransform.localPosition = new Vector3 (_sidebarStates [0], 0f, 0f);
+ _btnToggleSidebar.transform.GetComponent <RectTransform> ().localScale = new Vector3 (1, 1, 1);
}
}
- bool intToBool(int input) {
+ bool IntToBool(int input) {
/* Converts int to boolean */
if (input >= 1) {
return true;
diff --git a/td/Assets/Scripts/player.cs b/td/Assets/Scripts/player.cs
index 4b23054..30ad07f 100644
--- a/td/Assets/Scripts/player.cs
+++ b/td/Assets/Scripts/player.cs
@@ -2,55 +2,56 @@
using System.Collections.Generic;
using UnityEngine;
-public class player : MonoBehaviour {
+public class Player : MonoBehaviour {
- public int initialHealth;
- public int startingMoney;
+ public int InitialHealth;
+ public int StartingMoney;
- private GameObject[] towers;
- private int playerMoney;
- private int playerScore;
- private int playerHealth;
+ private GameObject[] _towers;
+ private int _playerMoney;
+ private int _playerScore;
+ private int _playerHealth;
void Awake() {
- playerMoney = startingMoney;
- playerHealth = initialHealth;
+ /* This method initializes the player class */
+ _playerMoney = StartingMoney;
+ _playerHealth = InitialHealth;
}
#region stats
- public int score() {
- return playerScore;
+ public int Score() {
+ return _playerScore;
}
- public void scoreAdd(int points) {
- playerScore += points;
+ public void ScoreAdd(int points) {
+ _playerScore += points;
}
- public int money() {
- return playerMoney;
+ public int Money() {
+ return _playerMoney;
}
- public void moneyAdd(int sum) {
- playerMoney += sum;
+ public void MoneyAdd(int sum) {
+ _playerMoney += sum;
}
- public void moneySubtract(int sum) {
- playerMoney -= sum;
+ public void MoneySubtract(int sum) {
+ _playerMoney -= sum;
}
- public int health() {
- return playerHealth;
+ public int Health() {
+ return _playerHealth;
}
- public void decreaseHealth(int hp) {
- playerHealth -= hp;
+ public void DecreaseHealth(int hp) {
+ _playerHealth -= hp;
}
#endregion
- public void spawnTower(GameObject towerType) {
+ public void SpawnTower(GameObject towerType) {
GameObject tower = Instantiate (towerType, new Vector3 (0, 0, 0), Quaternion.identity, transform.Find ("towers").transform);
- tower script = tower.GetComponent <tower>();
- script.player = this;
+ Tower script = tower.GetComponent <Tower>();
+ script.Player = this;
}
}
diff --git a/td/Assets/Scripts/tower.cs b/td/Assets/Scripts/tower.cs
index bc8241c..d99f937 100644
--- a/td/Assets/Scripts/tower.cs
+++ b/td/Assets/Scripts/tower.cs
@@ -1,69 +1,67 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
+using UnityEngine;
-public class tower : MonoBehaviour {
+public class Tower : MonoBehaviour {
[Header("Attributes")]
- public int towerPrice; // The price of the tower, set this in the desiger (tower prefab)
- public float fireRate; // How long the turret should use to reload, Set in designer (tower prefab)
- public float turnSpeed; // How fast the turret should rotate. Set in designer (tower prefab)
+ public int TowerPrice; // The price of the tower, set this in the desiger (tower prefab)
+ public float FireRate; // How long the turret should use to reload, Set in designer (tower prefab)
+ 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;
+ 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)
+ 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)
[Header("Scripting vars")]
- public player player; // Reference to the player object, should be set when instantiating
+ public Player Player; // Reference to the player object, should be set when instantiating
- private GameObject placementIndicator; // The placement indicator
- private Renderer placementIndicatorRenderer; // The renderer of the placement indicator
- private Plane groundPlane; // Plane used for raycasting when placing tower
- private float groundYpoint = 0.525f; // What Y-position the Tower should be placed on, this should be constant in every use-case.
- private bool towerPlaced; // Bool used to descide what to do this frame
- private bool colliding; // Set if the tower collides with any GameObject, used when placing, to see where it can be placed
+ private GameObject _placementIndicator; // The placement indicator
+ private Renderer _placementIndicatorRenderer; // The renderer of the placement indicator
+ private Plane _groundPlane; // Plane used for raycasting when placing tower
+ private float _groundYpoint = 0.525f; // What Y-position the Tower should be placed on, this should be constant in every use-case.
+ private bool _towerPlaced; // Bool used to descide what to do this frame
+ private bool _colliding; // Set if the tower collides with any GameObject, used when placing, to see where it can be placed
- private Transform target;
- private float fireCountdown;
+ private Transform _target;
+ private float _fireCountdown;
void Start () {
- placementIndicator = transform.GetChild (0).gameObject;
- placementIndicatorRenderer = placementIndicator.GetComponent<Renderer> ();
- placementIndicator.transform.localScale = new Vector3 (towerRange*7, 0.00000001f, towerRange*7);
+ _placementIndicator = transform.GetChild (0).gameObject;
+ _placementIndicatorRenderer = _placementIndicator.GetComponent<Renderer> ();
+ _placementIndicator.transform.localScale = new Vector3 (TowerRange*7, 0.00000001f, TowerRange*7);
- groundPlane = new Plane (Vector3.up, new Vector3(0f, groundYpoint, 0f));
+ _groundPlane = new Plane (Vector3.up, new Vector3(0f, _groundYpoint, 0f));
}
void Update () {
#region placeTower
- if (!towerPlaced) {
+ if (!_towerPlaced) {
if (Input.touchCount == 1 || Input.GetMouseButton (0)) {
/* Activate indicator if not already */
- if (!placementIndicator.activeSelf) { placementIndicator.SetActive (true); }
+ if (!_placementIndicator.activeSelf) { _placementIndicator.SetActive (true); }
/* Change indicator-color based on placement */
- if (!colliding) { placementIndicatorRenderer.sharedMaterial = materialDanger; }
- else { placementIndicatorRenderer.sharedMaterial = materialSuccess; }
+ if (!_colliding) { _placementIndicatorRenderer.sharedMaterial = MaterialDanger; }
+ else { _placementIndicatorRenderer.sharedMaterial = MaterialSuccess; }
/* Calculate new position */
Ray touchRay = Camera.main.ScreenPointToRay (Input.mousePosition);
float rayDistance;
- if (groundPlane.Raycast (touchRay, out rayDistance)) {
+ if (_groundPlane.Raycast (touchRay, out rayDistance)) {
transform.position = touchRay.GetPoint (rayDistance);
}
} else {
/* User let go of the screen, decide if tower can be placed */
- if (!colliding) { Destroy (gameObject); } // Skal kollidere for å være på et godkjent område
+ if (!_colliding) { Destroy (gameObject); } // Skal kollidere for å være på et godkjent område
else {
- towerPlaced = true;
- player.moneySubtract (towerPrice);
- placementIndicator.SetActive (false);
- placementIndicatorRenderer.sharedMaterial = materialSuccess;
- InvokeRepeating ("updateTarget", 0f, 0.5f); // This starts the
+ _towerPlaced = true;
+ Player.MoneySubtract (TowerPrice);
+ _placementIndicator.SetActive (false);
+ _placementIndicatorRenderer.sharedMaterial = MaterialSuccess;
+ InvokeRepeating ("UpdateTarget", 0f, 0.5f); // This starts the
gameObject.GetComponent <BoxCollider>().enabled = false;
}
@@ -74,36 +72,36 @@ public class tower : MonoBehaviour {
#endregion
// Stop rest of update if no target is aquired
- if (target == null) {
+ if (_target == null) {
return;
}
// Target lockon
- Vector3 direction = target.position - transform.position;
+ Vector3 direction = _target.position - transform.position;
Quaternion lookRotation = Quaternion.LookRotation (direction);
- Vector3 rotation = Quaternion.Lerp (transform.rotation, lookRotation, Time.deltaTime * turnSpeed).eulerAngles;
+ Vector3 rotation = Quaternion.Lerp (transform.rotation, lookRotation, Time.deltaTime * TurnSpeed).eulerAngles;
transform.rotation = Quaternion.Euler (0f, rotation.y, 0f);
- if (fireCountdown <= 0f) {
+ if (_fireCountdown <= 0f) {
// FAIAAAAA
- shoot();
- fireCountdown = 1f / fireRate;
+ Shoot();
+ _fireCountdown = 1f / FireRate;
}
- fireCountdown -= Time.deltaTime;
+ _fireCountdown -= Time.deltaTime;
}
- 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 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() {
+ void UpdateTarget() {
/* Method that updates the currentTarget.
* The target will be set to the nearest in range */
GameObject[] enemies = GameObject.FindGameObjectsWithTag ("enemy");
@@ -118,29 +116,29 @@ public class tower : MonoBehaviour {
}
}
- if (nearestEnemy != null && shortestDistance <= towerRange) {
- target = nearestEnemy.transform;
+ if (nearestEnemy != null && shortestDistance <= TowerRange) {
+ _target = nearestEnemy.transform;
} else {
- target = null;
+ _target = null;
}
}
void OnTriggerEnter(Collider other) {
- colliding = true;
+ _colliding = true;
}
void OnTriggerStay(Collider other) {
- colliding = true;
+ _colliding = true;
}
void OnTriggerExit(Collider other) {
- colliding = false;
+ _colliding = false;
}
void OnDrawGizmosSelected() {
/* Show gizmos in designer */
Gizmos.color = Color.red;
- Gizmos.DrawWireSphere (transform.position, towerRange);
+ Gizmos.DrawWireSphere (transform.position, TowerRange);
}
}
diff --git a/td/Assets/Scripts/waveSpawner.cs b/td/Assets/Scripts/waveSpawner.cs
index c3fada3..f79fb90 100644
--- a/td/Assets/Scripts/waveSpawner.cs
+++ b/td/Assets/Scripts/waveSpawner.cs
@@ -3,21 +3,21 @@ using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
-public class waveSpawner : MonoBehaviour {
+public class WaveSpawner : MonoBehaviour {
public static int EnemiesAlive = 0;
- public Wave[] waves;
+ public Wave[] Waves;
- public Transform spawnPoint;
+ public Transform SpawnPoint;
- public float timeBetweenWaves = 5f;
- private float countdown = 2f;
+ public float TimeBetweenWaves = 5f;
+ private float _countdown = 2f;
- public Text waveCountdownText;
+ public Text WaveCountdownText;
- private int waveIndex = 0;
+ private int _waveIndex = 0;
void Update ()
{
@@ -26,51 +26,51 @@ public class waveSpawner : MonoBehaviour {
return;
}
- if (waveIndex == waves.Length)
+ if (_waveIndex == Waves.Length)
{
// WIN LEVEL!!!
this.enabled = false;
}
- if (countdown <= 0f)
+ if (_countdown <= 0f)
{
StartCoroutine(SpawnWave());
- countdown = timeBetweenWaves;
+ _countdown = TimeBetweenWaves;
return;
}
- countdown -= Time.deltaTime;
+ _countdown -= Time.deltaTime;
- countdown = Mathf.Clamp(countdown, 0f, Mathf.Infinity);
+ _countdown = Mathf.Clamp(_countdown, 0f, Mathf.Infinity);
//waveCountdownText.text = string.Format("{0:00.00}", countdown);
}
IEnumerator SpawnWave ()
{
- Wave wave = waves[waveIndex];
+ Wave wave = Waves[_waveIndex];
- EnemiesAlive = wave.count;
+ EnemiesAlive = wave.Count;
- for (int i = 0; i < wave.count; i++)
+ for (int i = 0; i < wave.Count; i++)
{
- SpawnEnemy(wave.enemy);
- yield return new WaitForSeconds(1f / wave.rate);
+ SpawnEnemy(wave.Enemy);
+ yield return new WaitForSeconds(1f / wave.Rate);
}
- waveIndex++;
+ _waveIndex++;
}
void SpawnEnemy (GameObject enemy)
{
- Instantiate(enemy, spawnPoint.position, spawnPoint.rotation);
+ Instantiate(enemy, SpawnPoint.position, SpawnPoint.rotation);
}
}
[System.Serializable]
public class Wave {
- public GameObject enemy;
- public int count;
- public float rate;
+ public GameObject Enemy;
+ public int Count;
+ public float Rate;
} \ No newline at end of file