blob: 608d09cdebbecf9374c94d983a0db8a4a47218aa (
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
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 _playerPaycheck;
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 Paycheck() {
return _playerPaycheck;
}
public void PaycheckAdd(int sum) {
_playerPaycheck += sum;
}
public void Payday() {
_playerMoney += _playerPaycheck;
_playerPaycheck = 0;
}
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;
}
}
|