-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gun.pde
53 lines (45 loc) · 1.33 KB
/
Gun.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
class Gun {
final color PEW_TINT = #FFCD00;
final float PEW_SIZE = 0.1;
final float PEW_SHOW_DURATION = 0.03;
PShape model = player_gun_shape;
PVector gun_shooty_end_offset = VEC(0.0, 0.048791, 0.84);
private float shoot_timer = 0;
float shoot_fire_period = 1.0/10;
float hit_damage = 25;
void update(float dt, boolean shooting, Player holder) {
shoot_timer += dt;
if (shooting) {
if (shoot_timer > shoot_fire_period) {
shoot(holder);
}
}
}
void shoot(Player holder) {
shoot_timer = 0;
RayCastResult r = holder.cast_eye_ray();
//println(r);
if (r != null) {
r.shape.parent.hit(r.intersects, hit_damage);
}
}
void show(float dt) {
//shader(player_gun_shader);
scale(1.4);
shape(player_gun_shape);
translate(gun_shooty_end_offset.x, gun_shooty_end_offset.y, gun_shooty_end_offset.z);
//pg.scale(0.004);
//pg.image(pew_image, -pew_image.width/2, -pew_image.height/2);
if (shoot_timer < PEW_SHOW_DURATION) {
tint(PEW_TINT);
beginShape();
noStroke();
texture(pew_image);
vertex(-PEW_SIZE, -PEW_SIZE, 0, 0);
vertex(-PEW_SIZE, PEW_SIZE, 0, pew_image.height);
vertex(PEW_SIZE, PEW_SIZE, pew_image.width, pew_image.height);
vertex(PEW_SIZE, -PEW_SIZE, pew_image.width, 0);
endShape(CLOSE);
}
}
}