forked from mperes/ZombieAttack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHorde.pde
146 lines (129 loc) · 4.08 KB
/
Horde.pde
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
class Horde {
ArrayList<Enemy> enemies;
ArrayList<DeadZombie> deadZombies;
Player player;
ArrayList<AudioSample> fx_die;
AudioSample fx_die1;
AudioSample fx_die2;
AudioSample fx_die3;
AudioSample fx_damage;
PImage[] enemySprites;
int level;
float lastWave;
float lastSpawn;
float goreCount;
Boolean gore;
String[] enemy_deaths = {
SOUNDFXPATH+"enemy_die1.mp3",
SOUNDFXPATH+"enemy_die2.mp3",
SOUNDFXPATH+"enemy_die3.mp3"
};
Horde(Player player) {
enemies = new ArrayList<Enemy>();
deadZombies = new ArrayList<DeadZombie>();
fx_die = new ArrayList<AudioSample>();
this.player = player;
for(int x = 0;x < enemy_deaths.length;x++){
fx_die.add(minim.loadSample(enemy_deaths[x], SOUNDBUFFERSIZE));
}
fx_damage = minim.loadSample(SOUNDFXPATH+"player_hit1.mp3");
enemySprites = new PImage[3];
enemySprites[0] = loadImage(IMGPATH+"enemy_sprite_1.png");
enemySprites[1] = loadImage(IMGPATH+"enemy_sprite_2.png");
enemySprites[2] = loadImage(IMGPATH+"enemy_sprite_3.png");
level = 0;
lastWave = millis();
lastSpawn = millis();
goreCount = 0;
gore = false;
}
void spawn() {
float angle = random(2*PI); //radians(90);
float spawndist = random(40);
float spawnX = sin(angle)*(RADARSIZE/2+2*ENEMYSIZE+spawndist)+width/2;
float spawnY = cos(angle)*(RADARSIZE/2+2*ENEMYSIZE+spawndist)+height/2;
//Enemy generation
//int energy, float x, float y, float speed, float power, float awareness, int sprite
int levelEnergy = min( levelEnergy = 1 + round(random(level)), 5);
float levelSpeed = 0.25 + random(level);
float levelPower = 5 + random(level);
float levelAwareness = random(4)+random(level)+1;
enemies.add(new Enemy(levelEnergy, spawnX, spawnY, levelSpeed, levelPower, levelAwareness, round(random(enemySprites.length-1)), round(random(enemy_deaths.length-1))));
}
void update() {
//Check gore effect
checkGore();
//Advances level;
if(millis()-lastWave > WAVEDURATION) {
level++;
lastWave = millis();
//Regenerates energy on level up
//player.currentEnergy = player.energy;
//println("Advance to level "+level);
}
//Spawn enemies;
if(millis()-lastSpawn > WAVESPAWN / (level+1)) {
lastSpawn = millis();
spawn();
//println("Enemy spawned");
}
for(int b=0; b<player.weapon.bullets.size(); b++) {
Bullet bullet = player.weapon.bullets.get(b);
for(int e=0; e<enemies.size(); e++) {
Enemy enemy = enemies.get(e);
if( pow((bullet.position.x-enemy.position.x), 2) + pow((bullet.position.y - enemy.position.y), 2) < pow(15, 2) ) {
//Enemy hit;
player.weapon.fx_hit.trigger();
player.weapon.bullets.remove(b);
enemy.energy--;
//Enemy killed
if(enemy.energy <= 0) {
fx_die.get(enemy.death_sound).trigger();
player.kills++;
player.score =+ enemy.getScore();
enemy.die();
deadZombies.add(new DeadZombie(new PVector(enemy.position.x, enemy.position.y)));
enemies.remove(e);
}
break;
}
}
}
for(int e=0; e<enemies.size(); e++) {
Enemy enemy = enemies.get(e);
enemy.update(player);
if( pow((enemy.position.x-player.position.x), 2) + pow((enemy.position.y - player.position.y), 2) < pow(PLAYERSIZE, 2) ) {
fx_damage.trigger();
doGore();
player.currentEnergy -= enemy.power;
enemy.die();
enemies.remove(e);
}
}
for(int d=0; d<deadZombies.size(); d++) {
DeadZombie dz = deadZombies.get(d);
dz.update();
if(dz.stayCounter > CORPSESTAY){
deadZombies.remove(dz);
}
}
}
void evade(Player player) {
}
void checkGore() {
if(gore) {
goreCount -= 1;
if(goreCount <= 0) {
gore = false;
goreCount = 0;
}
}
}
void doGore() {
if(goreCount > 0) {
} else {
gore = true;
goreCount = 100;
}
}
}