-
Notifications
You must be signed in to change notification settings - Fork 0
/
ThrowCar.cs
196 lines (168 loc) · 5.29 KB
/
ThrowCar.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
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
189
190
191
192
193
194
195
196
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ThrowCar : MonoBehaviour, IDiffcultyAdjuster
{
public float carDamage = 40.0f;
private float baseCarDamage;
public bool collision; // see whether the car has hit the boundry
public bool thrown; // used to initiate damage and rotation
Vector2 knockback;
float rotationTime;
int rotationMultiplier = 1; // used to determine which way to rotate the car
private bool dazed;
private float dazedLength = 4.0f;
private float dazedTime;
private float baseDaze;
private Player_stats ps;
private DynamicDifficultyAdjuster dda;
private Stat_Manager stat_manager;
private int difficulty;
private GameObject icon; // icon used to indicate player is slowed down
private float flickerTimer;
private float flickerCount = 10;
private bool destroyed;
private void Start()
{
baseCarDamage = carDamage;
baseDaze = dazedLength;
ps = FindObjectOfType<Player_stats>();
stat_manager = GameObject.Find("StatManager").GetComponent<Stat_Manager>();
difficulty = stat_manager.GetDifficulty();
StartDifficulty(difficulty); // will make enemies harder as player progresses through the game
dda = GameObject.Find("DDA").GetComponent<DynamicDifficultyAdjuster>();
dda.Subscribe(this);
icon = GameObject.Find("GameUI").transform.Find("DownSpeedIcon").gameObject;
}
private void Update()
{
//rotate thrown car
if (thrown && Time.time > rotationTime && !collision)
{
rotateCar();
}
// slow down player if hit by car
if (dazed)
{
slowDown();
}
if (thrown && collision && Time.time > flickerTimer)
{
destroyCar();
flickerCount--;
if (flickerCount == 0)
{
destroyed = true;
}
}
}
void rotateCar()
{
transform.eulerAngles = Vector3.forward * 45 * rotationMultiplier;
rotationTime = Time.time + .2f;
if (rotationMultiplier == 4)
{
rotationMultiplier = 1;
}
else
{
rotationMultiplier++;
}
}
void OnTriggerEnter2D(Collider2D col)
{
if (col.gameObject.CompareTag("Enemy") && thrown || col.gameObject.CompareTag("Shot")
|| col.gameObject.CompareTag("bullet") || col.gameObject.CompareTag("Magnet"))
{
Debug.Log("Collision with " + col + " nothing should happpen");
}
else if (col.gameObject.CompareTag("ThrownCar"))
{
Rigidbody2D carRB = gameObject.GetComponent<Rigidbody2D>();
knockback = carRB.velocity;
carRB.AddForce(-knockback * 0);
collision = true;
}
else if (col.gameObject.CompareTag("Player") && !collision && thrown)
{
collision = true;
Debug.Log("Thrown car hit player");
if ((ps.healthCurrent - carDamage) > 0)
{
dazed = true;
dazedTime = Time.time + dazedLength;
}
ps.RemoveHealth(carDamage);
}
else
{
Debug.Log("Collsion with other " + col);
collision = true;
}
flickerTimer = Time.time + dazedLength;
}
private void OnCollisionEnter2D(Collision2D col)
{
string[] tags = { "Shot", "Power_Up", "Magnet", "bullet" };
for (int i = 0; i < tags.Length; i++)
{
if (col.gameObject.CompareTag(tags[i]))
{
Debug.Log("Thrown car collided with " + tag);
}
else if (thrown)
{
collision = true;
}
}
}
public void StartDifficulty(int difficulty)
{
}
public void ChangeDifficulty(int difficulty)
{
carDamage = (baseCarDamage + (difficulty * 5.0f));
Debug.Log("car damge: " + carDamage);
if(dazedLength > 1.0f)
{
dazedLength = baseDaze + difficulty;
Debug.Log("DazeTime: " );
}
}
public void slowDown()
{
if(Time.time < dazedTime)
{
Debug.Log("Dazed " );
ps.move_speed = 40;
icon.SetActive(true);
}
else
{
Debug.Log(" Not Dazed anymore");
ps.move_speed = 80;
dazed = false;
icon.SetActive(false);
}
}
private void destroyCar()
{
if (destroyed)
{
dda.Unsubscribe(this);
gameObject.active = false;
}
else if (gameObject.GetComponent<Renderer>().enabled == true)
{
gameObject.GetComponent<Renderer>().enabled = false;
flickerCount--;
flickerTimer = Time.time + .1f;
}
else if (gameObject.GetComponent<Renderer>().enabled == false)
{
gameObject.GetComponent<Renderer>().enabled = true;
flickerCount--;
flickerTimer = Time.time + .1f;
}
}
}