-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass_bullet.pde
73 lines (72 loc) · 2.15 KB
/
class_bullet.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
class Bullet {
public PVector loc, vel;
int lifetime;
int maxlife;
int bounces;
color bulletColor;
int gridLoc;
Bullet(PVector loc_, PVector vel_, color bulletColor_, int maxlife_) {
this.loc = loc_;
this.vel = vel_;
bounces = 0;
gridLoc = 0;
bulletColor = bulletColor_;
maxlife = maxlife_;
}
void updateBullet(Bullet b, int i) {
lifetime++;
b.loc = b.loc.add(b.vel);
//this.loc.set(this.loc.x+this.vel.x, this.loc.y+this.vel.y);//+.001*dot.x;
//loc.x = loc.x+vel.x;//+.001*dot.x;
//loc.y = loc.y+vel.y;//+.001*dot.y;
if (b.loc.x>=width) {
bounces ++;
b.vel.x*=-1;
}
if (b.loc.x<=0) {
bounces ++;
b.vel.x*=-1;
}
if (b.loc.y>=height) {
bounces ++;
b.vel.y*=-1;
}
if (b.loc.y<=0) {
bounces ++;
b.vel.y*=-1;
}
gridLoc = int(loc.x)/int(width/gridGranularity) + gridGranularity*(-1+int(loc.y)/int(height/gridGranularity));
drawBullet(b, i);
}
//void updateBullet(PVector vel_) {
// lifetime++;
// this.loc.set(this.loc.x+vel_.x, this.loc.y+vel_.y);//+.001*dot.x;
// //z+=vz_;
// //periodic boundary conditions
//}
void drawBullet(Bullet b, int i) {
pushMatrix();
// translate(0, 0, -z);255-105-180 = hot pink
//color from = color(0, 0, 0);
//color to = color(255, 105, 180);
//stroke(blendColor(color(map(i+1,0,bullets.size(),0,255),map(i+1,0,bullets.size(),0,105),map(i+1,0,bullets.size(),0,180)),mapcolor,SUBTRACT));
stroke(bulletColor);
//stroke(lerpColor(from,to,map(i+1,1,bullets.size(),0,1)));
line(b.loc.x-b.vel.x, b.loc.y-b.vel.y, b.loc.x, b.loc.y);
translate(b.loc.x, b.loc.y);
stroke(bulletColor);
ellipse(0, 0, 3, 3);
popMatrix();
}
}
void updatebullets() {
Bullet currentbullet;
for (int i=0; i<bullets.size(); i++) {
currentbullet = bullets.get(i);
if (currentbullet.lifetime > currentbullet.maxlife || currentbullet.bounces > 2) {// || currentbullet.x<0 || currentbullet.x>width || currentbullet.y<0 || currentbullet.y>height) {
bullets.remove(currentbullet);
}
currentbullet.updateBullet(currentbullet, i);
//currentbullet.drawBullet();
}
}