-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
95 lines (53 loc) · 1.5 KB
/
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
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
var fixSprite1, fixSprite2, fixSprite3, fixSprite4 ;
var movingSprite;
var music;
var edges;
function preload(){
music = loadSound("music.mp3");
}
function setup(){
canvas = createCanvas(800,600);
movingSprite=createSprite(random(10,750),100,40,40);
movingSprite.shapeColor=("white");
movingSprite.velocityX=6;
movingSprite.velocityY=9;
fixSprite1=createSprite(100,590,180,20);
fixSprite1.shapeColor=("red");
fixSprite2=createSprite(300,590,180,20);
fixSprite2.shapeColor=("green");
fixSprite3=createSprite(500,590,180,20);
fixSprite3.shapeColor=("blue");
fixSprite4=createSprite(700,590,180,20);
fixSprite4.shapeColor=("yellow");
}
function draw() {
background(rgb(10,10,10));
edges=createEdgeSprites();
movingSprite.bounceOff(edges);
if(movingSprite.isTouching(fixSprite4)){
music.play()
movingSprite.shapeColor=("yellow");
movingSprite.bounceOff(fixSprite4);
}
if(movingSprite.isTouching(fixSprite3)){
music.stop()
movingSprite.shapeColor=("blue");
movingSprite.velocityX=0;
movingSprite.velocityY=0;
}
if(movingSprite.isTouching(fixSprite2)){
music.play()
movingSprite.shapeColor=("green");
movingSprite.bounceOff(fixSprite2)
}
if(movingSprite.isTouching(fixSprite1)){
music.play()
movingSprite.shapeColor=("red");
movingSprite.bounceOff(fixSprite1)
}
if (movingSprite.y<0){
music.stop()
movingSprite.velocityY=3
}
drawSprites()
}