aboutsummaryrefslogtreecommitdiff
path: root/td/Assets/Scripts/player.cs
blob: a8106d3abc548a5848706f8a2d9daaa24d12a4b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour {

	public int InitialHealth;
    public int StartingMoney;
	public MainGui MainGui;
	
	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);
    }

	#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);
		}
	}

}