-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
44 lines (36 loc) · 946 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
var wall, thickness;
var bullet, speed, weight;
function setup() {
createCanvas(1600,400);
thickness = Math.round(random(22, 83));
speed = Math.round(random(223, 321));
weight = Math.round(random(30, 52));
//Wall Sprite
wall = createSprite(1200, 200, thickness, height/2);
wall.shapeColor = color(80, 80, 80);
//Bullet Sprite
bullet=createSprite(50, 200, 50, 50);
}
function draw() {
background(255,255,255);
bullet.velocityX = speed;
if (hasColided(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 hasColided(lbullet, lwall){
bulletRightEdge = lbullet.x + lbullet.width;
wallLeftEdge = lwall.x
if (bulletRightEdge>=wallLeftEdge){
return true;
}
return false;
}