-
Notifications
You must be signed in to change notification settings - Fork 0
/
sketch.js
146 lines (111 loc) · 3.15 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
const Engine = Matter.Engine;
const World= Matter.World;
const Bodies = Matter.Bodies;
const Constraint = Matter.Constraint;
var engine, world;
var particles;
var plinkos = [];
var divisions =[];
var particle;
var divisionHeight=300;
var score =0;
var count = 0;
var gameState ="start";
var scoringSound;
var gameOver_Sound;
function preload(){
scoringSound = loadSound("jump.wav");
gameOver_Sound = loadSound("collided.wav");
}
function setup() {
createCanvas(800, 800);
engine = Engine.create();
world = engine.world;
ground = new Ground(width/2,height,width,20);
for (var k = 0; k <=width; k = k + 80) {
divisions.push(new Divisions(k, height-divisionHeight/2, 10, divisionHeight));
}
for (var j = 75; j <=width; j=j+50) {
plinkos.push(new Plinko(j,75));
}
for (var j = 50; j <=width-10; j=j+50) {
plinkos.push(new Plinko(j,175));
}
for (var j = 75; j <=width; j=j+50) {
plinkos.push(new Plinko(j,275));
}
for (var j = 50; j <=width-10; j=j+50) {
plinkos.push(new Plinko(j,375));
}
}
function draw() {
background("blue");
textSize(18);
text("Score : "+score,20,40);
fill("black");
textSize(12);
text("You have 5 chances to increase your score",200,20);
fill("white");
textSize(23)
text(" 500 ", 5, 550);
text(" 500 ", 80, 550);
text(" 500 ", 160, 550);
text(" 500 ", 240, 550);
text(" 100 ", 320, 550);
text(" 100 ", 400, 550);
text(" 100 ", 480, 550);
text(" 200 ", 560, 550);
text(" 200 ", 640, 550);
text(" 200 ", 720, 550);
Engine.update(engine);
ground.display();
if ( gameState =="end") {
gameOver_Sound.play();
textSize(90);
text("GameOver", 150, 300);
//return
}
for (var i = 0; i < plinkos.length; i++) {
plinkos[i].display();
}
if(particle!=null)
{
particle.display();
if (particle.body.position.y>760)
{
if (particle.body.position.x < 300)
{
score=score+500;
particle=null;
scoringSound.play();
if ( count>= 5) gameState ="end";
}
else if (particle.body.position.x < 600 && particle.body.position.x > 301 )
{
score = score + 100;
particle=null;
scoringSound.play();
if ( count>= 5) gameState ="end";
}
else if (particle.body.position.x < 900 && particle.body.position.x > 601 )
{
score = score + 200;
particle=null;
scoringSound.play();
if ( count>= 5) gameState ="end";
}
}
}
for (var k = 0; k < divisions.length; k++)
{
divisions[k].display();
}
}
function mousePressed()
{
if(gameState!=="end")
{
count++;
particle=new Particle(mouseX, 10, 10, 10);
}
}