-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsketch.js
54 lines (35 loc) · 820 Bytes
/
sketch.js
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
var wall,bullet;
var speed,thickness,weight;
function setup() {
createCanvas(1600,400);
thickness=random(22,83);
wall=createSprite(1250,200,thickness,width/2);
wall.shapeColor=color(80,80,80);
speed=random(223,321);
weight=random(30,52);
bullet=createSprite(50,200,20,20);
bullet.velocityX=speed;
bullet.shapeColor=color(0,0,0);
}
function draw() {
background("grey");
if(hascollided(bullet,wall)){
bullet.velocityX=0;
var damage=0.5*weight*speed*speed/(thickness*thickness*thickness);
if(damage>10){
wall.shapeColor=color(225,0,0);
}
if(damage<10){
wall.shapeColor=color(0,225,0);
}
}
drawSprites();
}
function hascollided(lbullet,lwall){
bulletRightEdge=lbullet.x+lbullet.width;
wallLeftEdge=lwall.x;
if(bulletRightEdge>=wallLeftEdge){
return true;
}
return false;
}