-
Notifications
You must be signed in to change notification settings - Fork 1
/
BulletEmitter.pde
87 lines (78 loc) · 2.79 KB
/
BulletEmitter.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
//----------------------------------------------------------
// BulletEmitter class
//----------------------------------------------------------
class BulletEmitter {
float bulletPause;
BulletEmitter(){
bulletPause = 0.0;
}
void at_player(ArrayList<Bullet> list, float[] loc, float speed, float frequency, float rate){
if (rate > bulletPause+frequency){
float x = loc[0];
float y = loc[1];
float delta_x = player.x - x;
float delta_y = player.y - y;
float angle = (float)atan2(delta_y, delta_x);
list.add(new Bullet(x, y, 20.0, speed, angle, color(255,0,0)));
bulletPause = rate;
}
}
void direction_player_is_facing(ArrayList<Bullet> list, float[] loc, float speed, float frequency, float rate){
if (rate > bulletPause+frequency){
sfx.get("shoot").play(1.0,0.0,0.18);
String direction = player.dirFlag;
float x = loc[0];
float y = loc[1];
float angle = 0.0;
switch(direction){
case "w":
angle = 3.0*PI/2.0;
break;
case "a":
angle = PI;
break;
case "s":
angle = PI/2.0;
break;
case "d":
angle = 0.0;
break;
}
//println(direction+ " " + angle);
list.add(new Bullet(x, y, 10.0, speed, angle, color(255,255,255)));
bulletPause = rate;
}
}
void bomb_behind(ArrayList<Bomb> list, float[] loc, float speed, float frequency, float rate){
if (rate > bulletPause+frequency){
//sfx.get("shoot").play(1.0,0.0,0.18);
String direction = player.dirFlag;
float x = loc[0];
float y = loc[1];
switch(direction){
case "w":
list.add(new Bomb(x, y, 30.0, speed, PI/2, color(0,255,0), true));
list.add(new Bomb(x, y, 30.0, speed, 0.0, color(0,255,0), false));
list.add(new Bomb(x, y, 30.0, speed, PI, color(0,255,0), false));
print("fuck");
break;
case "a":
list.add(new Bomb(x, y, 30.0, speed, 0.0, color(0,255,0), true));
list.add(new Bomb(x, y, 30.0, speed, PI/2, color(0,255,0), false));
list.add(new Bomb(x, y, 30.0, speed, 3.0*PI/2.0, color(0,255,0), false));
break;
case "s":
list.add(new Bomb(x, y, 30.0, speed, 3.0*PI/2.0, color(0,255,0), true));
list.add(new Bomb(x, y, 30.0, speed, PI, color(0,255,0), false));
list.add(new Bomb(x, y, 30.0, speed, 0.0, color(0,255,0), false));
break;
case "d":
list.add(new Bomb(x, y, 30.0, speed, PI, color(0,255,0), true));
list.add(new Bomb(x, y, 30.0, speed, PI/2, color(0,255,0), false));
list.add(new Bomb(x, y, 30.0, speed, 3.0*PI/2.0, color(0,255,0), false));
break;
}
bulletPause = rate;
}
}
}