-
Notifications
You must be signed in to change notification settings - Fork 0
/
block_virus.cs
182 lines (155 loc) · 4.14 KB
/
block_virus.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
using UnityEngine;
using System.Collections;
public class block_virus : MonoBehaviour {
public int XSpeed;
public int YSpeed;
public float Multiplyer = 1;
public float Increm;
public GameObject BlockVirusGameobject;
public GameObject redVirus;
public GameObject shooterVirus;
public GameObject blueVirus;
public GameObject yellowVirus;
public int SpaceOut;
int level;
public float enemyY;
public enemy_spawner enemyspawner;
public garbage_collector gc;
public Vector2 speed;
public int enemyId;
public int maxValue = 2;
public float cy;
public top_cheat_prev[] tcp;
public GameObject bmi;
public bool blockMode;
// Use this for initialization
void Start () {
blockMode = false;
cy = transform.position.y;
enemyspawner = GameObject.FindObjectOfType<enemy_spawner> ();
gc = GameObject.FindObjectOfType<garbage_collector> ();
tcp = this.GetComponentsInChildren<top_cheat_prev> ();
bmi = GameObject.FindGameObjectWithTag ("block_mode");
if (bmi != null) {
blockMode = true;
}
}
// Update is called once per frame
void Update(){
transform.position = new Vector2 (transform.position.x, cy);
if ((tcp[0].count >= 1)&&(tcp[1].count >= 1)) {
makeItFair();
}
}
void FixedUpdate () {
move ();
}
void OnTriggerEnter2D(Collider2D coll){
if (coll.gameObject.name == "player") {
level = Random.Range(1,4);
enemyId = Random.Range(1,maxValue);
if(blockMode){
enemyId = 1;
}
switch(level){
case 1:
enemyY = -3.5f;
break;
case 2:
enemyY = 0;
break;
case 3:
enemyY = 3.5f;
break;
}
switch(enemyId){
case 1:
Instantiate(BlockVirusGameobject,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 2:
Instantiate(redVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 3:
Instantiate(shooterVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 4 :
Instantiate(blueVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 5 :
Instantiate(yellowVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
}
}
}
void OnCollisionEnter2D(Collision2D coll){
if (coll.collider.gameObject.tag == "enemy") {
Physics2D.IgnoreCollision(gameObject.GetComponent<Collider2D>(),coll.gameObject.GetComponent<Collider2D>());
}
if (coll.collider.gameObject.tag == "bullet") {
Physics2D.IgnoreCollision(gameObject.GetComponent<Collider2D>(),coll.gameObject.GetComponent<Collider2D>());
}
}
void move(){
Multiplyer += 0.05f * Time.deltaTime;
speed = GetComponent<Rigidbody2D> ().velocity = new Vector2 (XSpeed * gc.multiplyer, YSpeed);
if (gc.multiplyer > 1.3) {
maxValue = 3;
}
if (gc.multiplyer > 1.5) {
maxValue = 4;
}
if (gc.multiplyer > 1.7) {
maxValue = 5;
}
if (gc.multiplyer > 2) {
maxValue = 6;
}
}
float RandomX(){
return Random.Range (50, 100);
}
void makeItFair(){
level = Random.Range(1,4);
enemyId = Random.Range(1,maxValue);
if (blockMode) {
enemyId = 1;
}
switch(level){
case 1:
enemyY = -3.5f;
break;
case 2:
enemyY = 0;
break;
case 3:
enemyY = 3.5f;
break;
}
switch(enemyId){
case 1:
Instantiate(BlockVirusGameobject,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 2:
Instantiate(redVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 3:
Instantiate(shooterVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 4 :
Instantiate(blueVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
case 5 :
Instantiate(yellowVirus,new Vector2 (transform.position.x + RandomX(),enemyY),transform.rotation);
break;
}
int num = Random.Range (0, 2);
switch (num) {
case 0:
tcp[0].DestroyCheat();
break;
case 1:
tcp[1].DestroyCheat();
break;
}
}
}