-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
47 lines (36 loc) · 943 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
var bullet, wall;
var speed, weight, thickness;
function setup() {
createCanvas(1600,400);
bullet = createSprite(50, 200, 60, 10);
bullet.shapeColor = color("white")
wall = createSprite(1200, 200, thickness, height / 2);
wall.shapeColor = color("gray");
speed = random(223, 321);
weight = random(30, 52);
thickness = random(22, 83);
bullet.velocityX = speed;
}
function draw() {
background("black");
if (hasCollided(bullet, wall)){
bullet.velocityX = 0;
var damage = 0.5 * weight * speed * speed / (thickness * thickness * thickness);
if (damage > 10){
wall.shapeColor = color(255, 0, 0);
}
if (damage < 10){
wall.shapeColor = color(0, 255, 0);
}
}
drawSprites();
}
function hasCollided(lbullet, lwall){
bulletRightEdge = lbullet.x + lbullet.width;
wallLeftEdge = lwall.x;
if (bulletRightEdge >= wallLeftEdge){
return true;
} else {
return false;
}
}