-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBattleSystem.cs
More file actions
188 lines (160 loc) · 5.22 KB
/
BattleSystem.cs
File metadata and controls
188 lines (160 loc) · 5.22 KB
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public enum BattleState { START, PLAYERTURN, ENEMYTURN, WON, LOST }
public class BattleSystem : MonoBehaviour
{
public GameObject playerPrefab;
public GameObject WurmPrefab;
public GameObject ZigPrefab;
public GameObject PoochPrefab;
public Transform playerBattleStation;
public Transform enemyBattleStation;
Unit playerUnit;
Unit enemyUnit;
public BattleHudPlayer playerHUD;
public BattleHud enemyHUD;
public BattleState state;
public GrassCollision encounter;
public GameObject player;
public GameObject battleScene;
public Text DialogueText;
public GameObject attackTextButton;
public GameObject bagTextButton;
public GameObject runTextButton;
public GameObject pokemonTextButton;
public GameObject selector;
public string PKMN;
public bool foundPKMN;
public bool attackTime;
public bool attackMenu;
public int totalButtonsY = 2;
public int totalButtonsX = 2;
public float yOffset = 15f;
public float xOffset = 15f;
public int yIndex = 0;
public int xIndex = 0;
public bool hasHappenedAlready = false;
// Start is called before the first frame update
void Start()
{
state = BattleState.START;
foundPKMN = false;
attackTime = false;
attackMenu = false;
}
void Update()
{
GrassCollision grassCollision = player.GetComponent<GrassCollision>();
PKMN = grassCollision.whatPKMN;
if (battleScene.activeInHierarchy == true)
{
foundPKMN = true;
}
else
{
foundPKMN = false;
}
if (foundPKMN == true && attackTime == false)
{
DialogueText.text = "A wild " +PKMN+ " approaches...";
if (Input.GetButtonDown("Interact"))
{
attackTime = true;
attackMenu = true;
}
}
else if (foundPKMN == true && attackTime == true)
{
attacking();
}
if (PKMN.Length != 0 && hasHappenedAlready == false)
{
battle();
hasHappenedAlready = true;
}
if(PKMN.Length != 0)
{
MenuMoving();
}
}
void battle()
{
GameObject playerGo = Instantiate(playerPrefab, playerBattleStation);
playerUnit = playerGo.GetComponent<Unit>();
if (PKMN == "Wurmple")
{
GameObject enemyGo = Instantiate(WurmPrefab, enemyBattleStation);
enemyUnit = enemyGo.GetComponent<Unit>();
}
else if (PKMN == "Poochyena")
{
GameObject enemyGo = Instantiate(PoochPrefab, enemyBattleStation);
enemyUnit = enemyGo.GetComponent<Unit>();
}
else if (PKMN == "Zigzagoon")
{
GameObject enemyGo = Instantiate(ZigPrefab, enemyBattleStation);
enemyUnit = enemyGo.GetComponent<Unit>();
}
}
void MenuMoving()
{
if (attackMenu == true)
{
if (Input.GetKeyDown(KeyCode.DownArrow) || Input.GetKeyDown(KeyCode.S))
{
if (yIndex < totalButtonsY - 1)
{
yIndex++;
Vector2 position = selector.transform.position;
position.y -= yOffset;
selector.transform.position = position;
}
}
if (Input.GetKeyDown(KeyCode.UpArrow) || Input.GetKeyDown(KeyCode.W))
{
if (yIndex > 0)
{
yIndex--;
Vector2 position = selector.transform.position;
position.y += yOffset;
selector.transform.position = position;
}
}
if (Input.GetKeyDown(KeyCode.RightArrow) || Input.GetKeyDown(KeyCode.D))
{
if (xIndex < totalButtonsX - 1)
{
xIndex++;
Vector2 position = selector.transform.position;
position.x += xOffset;
selector.transform.position = position;
}
}
if (Input.GetKeyDown(KeyCode.LeftArrow) || Input.GetKeyDown(KeyCode.A))
{
if (xIndex > 0)
{
xIndex--;
Vector2 position = selector.transform.position;
position.x -= xOffset;
selector.transform.position = position;
}
}
}
enemyHUD.SetHUD(enemyUnit);
playerHUD.SetHudPlayer(playerUnit);
}
public void attacking()
{
DialogueText.text = "Choose an action:";
state = BattleState.PLAYERTURN;
attackTextButton.SetActive(true);
runTextButton.SetActive(true);
bagTextButton.SetActive(true);
pokemonTextButton.SetActive(true);
selector.SetActive(true);
}
}