-
Notifications
You must be signed in to change notification settings - Fork 0
/
BattleHandler.cs
117 lines (105 loc) · 2.79 KB
/
BattleHandler.cs
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
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BattleHandler : MonoBehaviour
{
Player_Base player_base;
PlayerController p_control;
[SerializeField] bool reached_enemy;
public bool encounter, PlayerAttack, PlayerAttackEnded;
private Action onMarchComplete;
public float timer;
private State state;
private enum State
{
Attack,
Marching,
Turning,
Busy,
}
void StartVaribles()
{
player_base=GetComponent<Player_Base>();
p_control=GetComponent<PlayerController>();
reached_enemy=false;
state=State.Busy;
encounter=false;
timer=0;
}
void Start()
{
StartVaribles();
Setup();
}
void FixedUpdate()
{
Player_attack_States();
}
void Setup()
{
//if(isPlayer(Obj))
//{
// player_base.SetPlayerWait();
//}
//else
//{
// //Monter_base.SetMonsterWait();
//}
}
public void Player_Attack(Action onAttackComplete)
{
PlayerAttack=true;
PlayerAttackEnded=false;
state=State.Marching;
onAttackComplete();
}
void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.tag=="Enemy"&& PlayerAttack)
{
reached_enemy=true;
encounter=false;
}
if(collision.gameObject.tag=="encounter_Spawn")
{
encounter=true;
}
}
public void Player_attack_States()
{
if(PlayerAttack)
{
switch (state)
{
case State.Attack:
timer+=Time.deltaTime;
player_base.SetPlayerAttack();
if(timer>=1.7f)
{
timer=0;
state=State.Turning;
reached_enemy=false;
}
break;
case State.Turning:
p_control.Backwards_Movement();
if(encounter)
state=State.Busy;
break;
case State.Busy:
if(encounter)
{ PlayerAttack=false;
PlayerAttackEnded=true;
player_base.SetPlayerWait();
}
break;
case State.Marching:
p_control.Forward_Movement();
if(reached_enemy)
state=State.Attack;
break;
}
}
}
}