-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsketch.js
93 lines (74 loc) · 2.73 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
let ground, leftwall, rightwall, ceiling, ball, ball2, paddle, bottom, myscore, obstacle1, obstacle2, obstacle3, obstacle4, backimg, bloop, gameover, introtrans
myscore = 0
function setup() {
new Canvas();
world.gravity.y = 4
leftwall = new Sprite(20, 400, 40, 1200, 'static');//wall
leftwall.color = '#07090F';//leftwall code
rightwall = new Sprite(830, 400, 40, 1200, 'static');
rightwall.color = '#07090F';//rightwall code
ceiling = new Sprite(250, 0, 1200, 40, 'static');
ceiling.color = '#07090F';// ceiling code
bottom = new Sprite(250, 800, 1200, 40, 'static');
bottom.color = '#07090F';// bottom code
ball = new Sprite(400, 200, 50);
ball.color = '#5AD2F4';
ball2 = new Sprite(300, 200, 50);
ball2.color = '#5AD2F4';//code to do with the two balls
paddle = new Sprite(300, 300, 100, 40, 'kinetic');
paddle.color = '#D1495B'// paddle code
obstacle1 = new Sprite(75, 300, 100, 40, 'kinetic');
obstacle1.color = '#FFD972';//obstacle1 code
obstacle2 = new Sprite(725, 300, 100, 40, 'kinetic');
obstacle2.color = '#A7E8BD';//obstacle2 code
ball.speed = 50;
ball.bounciness = 0.7;
ball2.speed = 50;
ball2.bounciness = 0.7;//speed and bounciness of balls code
obstacle3 = new Sprite(225, 500, 100, 40, 'kinetic');
obstacle3.color = '#40476D';//obstacle3 code
obstacle4 = new Sprite(575, 500, 100, 40, 'kinetic');
obstacle4.color = '#593F62';//obstacle4 code
instructions = new Sprite(width/2, height/2,width, height,'static');
instructions.color = "pink";
instructions.text ="keep the balls in the air for as long as you can and score the most points, good luck ";
instructions.textSize = 20;
instructions.textColor = "purple";
instructions.life = 200// disappears after 200 milliseconds
instructions.layer = 100// on top of everything
}//end setup function
function draw() {
background(255);
imageMode(CENTER);
image(backimg, width/2, height/2, width, height);
paddle.moveTowards(mouse, 0.30)
if (paddle.collides(ball)) {
console.log("hit")
myscore = myscore + 1
paddle.text = myscore
ball.vel.y = -20
}//logging the score
if (ball.collides(bottom)) {
console.log("game over");
alert("game over");
ball.remove();
ball2.remove();
paddle.remove();
}// game over code
if (paddle.collides(ball2)) {
console.log("hit")
myscore = myscore + 1
paddle.text = myscore
ball2.vel.y = -20
}// logging the score with ball two
if (ball2.collides(bottom)) {
console.log("game over");
alert("game over");
ball2.remove();
ball.remove();
paddle.remove();
}// game over code for ball2
}//end draw function
function preload(){
backimg = loadImage('/backgroundimg.jpg');
}// end of preload function