diff options
author | Jakob Stendahl <JakobS1n@users.noreply.github.com> | 2017-10-14 23:17:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-14 23:17:09 +0200 |
commit | 8b2c937959c99ab2dfbc3eaf9dc5b9c18cf73371 (patch) | |
tree | b775b07054de58f83cd9df41bf43e61b3facfad1 /td/Assets/Scripts/player.cs | |
parent | 76cf99ade6530bdad81088295fb4cf73f5c5b118 (diff) | |
parent | abe835d1112e4804ce63b7d2fa85f8bd76e3c237 (diff) | |
download | TD-8b2c937959c99ab2dfbc3eaf9dc5b9c18cf73371.tar.gz TD-8b2c937959c99ab2dfbc3eaf9dc5b9c18cf73371.zip |
Merge pull request #4 from JakobS1n/GUI
Gui
Diffstat (limited to 'td/Assets/Scripts/player.cs')
-rw-r--r-- | td/Assets/Scripts/player.cs | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/td/Assets/Scripts/player.cs b/td/Assets/Scripts/player.cs new file mode 100644 index 0000000..cb55357 --- /dev/null +++ b/td/Assets/Scripts/player.cs @@ -0,0 +1,85 @@ +using UnityEngine; + +public class Player : MonoBehaviour { + + public int InitialHealth; + public int StartingMoney; + public MainGui MainGui; + + private int _gameState; + private GameObject[] _towers; + private int _playerMoney; + private int _playerScore; + private int _playerHealth; + + void Awake() { + /* This method initializes the player class */ + _playerMoney = StartingMoney; + _playerHealth = InitialHealth; + InvokeRepeating ("GameStateWatcher", 0f, 0.5f); + _gameState = 1; + } + + #region stats + public int Score() { + return _playerScore; + } + + public void ScoreAdd(int points) { + _playerScore += points; + } + + public int Money() { + return _playerMoney; + } + + public void MoneyAdd(int sum) { + _playerMoney += sum; + } + + public void MoneySubtract(int sum) { + _playerMoney -= sum; + } + + public int Health() { + return _playerHealth; + } + + public int HealthAsPercentage() + { + return Mathf.RoundToInt((InitialHealth * _playerHealth) / 100.0f); // Basic percentage calc... + } + + public void DecreaseHealth(int hp) { + _playerHealth -= hp; + } + #endregion + + 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; + } + + public void GameStateWatcher() { + if (_playerHealth <= 0) { + MainGui.GameOverScreen(_playerScore); + } + } + + public bool GameIsPaused() { + if (_gameState == 0) { return true; } + return false; + } + + public void PauseGame() { + Time.timeScale = 0.0F; + _gameState = 0; + } + + public void ResumeGame() { + Time.timeScale = 1.0F; + _gameState = 1; + } + +} |