-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbullets.js
More file actions
120 lines (115 loc) · 2.93 KB
/
bullets.js
File metadata and controls
120 lines (115 loc) · 2.93 KB
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
class bullet{
constructor(a,b,c,d,e){
//x and y projectile
this.prox = a;
this.proy = b;
//x and y target
this.proxt = c;
this.proyt = d;
//speed to move at
this.speed = e;
this.rotation = random(0,180);
this.direction = random(0,100);
if(this.direction>=50){
this.direction = 1;
}else{
this.direction = -1;
}
this.life = 300;
}
move(){
this.life--;
let hyp = dis(this.prox,this.proy,this.proxt,this.proyt);
let xv = (this.proxt-this.prox)/hyp*this.speed;
let yv = (this.proyt-this.proy)/hyp*this.speed;
this.prox+=xv;
this.proy+=yv;
this.proxt+=xv;
this.proyt+=yv;
this.rotation+=this.direction*10;
this.show();
for(let i=0; i<blocks.length; i++){
if(rectHit(this.prox,this.proy,blocks[i].bx,blocks[i].by,20,20,blocks[i].bsx,blocks[i].bsy)&&blocks[i].life>0&&blocks[i].type!=11){
this.life=0;
for(var c=0; c<20; c++){
let angle = random(0,2*PI);
let fast = random(2,9);
bulletsP[bulletsP.length] = new bulletP(this.prox,this.proy,this.prox+cos(angle)*50,this.proy+sin(angle)*50,fast);
blocks[i].showcv+=6/(blocks[i].bsx*blocks[i].bsy);
}
blocks[i].broken = true;
}
}
}
show(){
push();
translate(this.prox,this.proy)
rotate(this.rotation*PI/180);
noFill();
stroke("#DEC6B8");
ellipse(0,0,20,15);
pop();
}
}
class bulletP{
constructor(a,b,c,d,e,f){
//x and y projectile
this.prox = a;
this.proy = b;
//x and y target
this.proxt = c;
this.proyt = d;
//speed to move at
this.speed = e;
this.size = floor(random(8,12));
this.roll = 0;
this.type = f ?? 0;
}
move(){
let hyp = dis(this.prox,this.proy,this.proxt,this.proyt);
let xv = (this.proxt-this.prox)/hyp*this.speed;
let yv = (this.proyt-this.proy)/hyp*this.speed;
this.prox+=xv;
this.proy+=yv;
this.proxt+=xv;
this.proyt+=yv;
this.show();
this.speed/=1.1;
this.size-=0.2;
if(this.size<=0){
this.size=0;
}
this.roll-=(xv+yv)/10
}
show(){
push();
translate(this.prox,this.proy)
fill("#DEC6B8");
rotate(this.roll)
noStroke();
if(this.type == 0){
// image(tileSprite[2][4],0,0,this.size*1.5,this.size*1.5);
}else if(this.type ==1){
//image(tileSprite[9][5],0,0,this.size*2,this.size*2)
// image(tileSprite[3][4],0,0,this.size*1.5,this.size*1.5);
}else if(this.type ==2){
//image(tileSprite[9][5],0,0,this.size*2,this.size*2)
fill("#c4398b")
rect(0,0,this.size,this.size);
}
image(tileSprite[2+this.type][4],0,0,this.size*1.5,this.size*1.5);
pop();
}
}
//also used for blockP
function bulletShow(){
for(var i = 0; i<bullets.length; i++){
bullets[i].move();
}
for(var i = 0; i<bulletsP.length; i++){
bulletsP[i].move();
}
for(var i = 0; i<blockP.length; i++){
blockP[i].work();
}
}