-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsketch.js
More file actions
62 lines (35 loc) · 895 Bytes
/
sketch.js
File metadata and controls
62 lines (35 loc) · 895 Bytes
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
var bullet,wall;
var thickness,speed,weight;
function setup() {
createCanvas(1600,400);
speed = random(223,321);
weight = random(30,52);
thickness = random(22,83);
bullet = createSprite(50,200,50,50);
bullet.velocityX = speed;
bullet.shapecolor=color(255);
wall = createSprite(1200,200,thickness, height/2);
wall.shapecolor = color(80,80,80)
}
function draw() {
background(0,0,0);
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
}
return false;
}