-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pong.html
112 lines (89 loc) · 2.6 KB
/
Pong.html
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
<html>
<head>
<title> Pong </title>
<script src="https://simplycodingcourses.com/files/simplyjs/simply.js"></script>
<script>
function start(){
sjs.open("target", 700, 700);
//ball
var ball = new sjs.Image("Images/arson the blob.png");
ball.type = ("ball");
ball.setSize(150, 150);
ball.center();
ball.friction = 0;
ball.bounce();
ball.pushRight(3);
ball.pushUp(4);
//paddle code
var paddle1 = new sjs.Image("Images/paddle.png");
paddle1.type = "paddle";
paddle1.centerH();
paddle1.setSize(100,20);
//paddle2 code
var paddle2 = new sjs.Image ("Images/paddle2.png");
paddle2.type = "paddle";
paddle2.center().bottom();
paddle2.setSize(100,20);
//Score
var score = 0;
var score_txt = new sjs.Text("Score: 0", 21, "Magenta");
//keys moving paddles
sjs.keyDown(LEFT_KEY, function(){
paddle1.pushLeft();
paddle2.pushLeft();
});
//sounds
var soundEffect = new Audio ('Music/pop.mp3');
sjs.onHit("ball",["top_screen","bottom_screen"], function(){
window.location = "gameover.html";
});
sjs.onHit("ball", "paddle",function(ball, paddle){
score = score + 1;
score_txt.setText("Score: "+score);
sjs.onHit("ball",["top_screen","bottom_screen"], function(){
window.location = "gameover.html";
});
if (score == 25){
var newball = new sjs.Image("Images/arson the blob.png");
newball.type = ("ball");
newball.setSize(150, 150);
newball.center();
newball.friction = 0;
newball.bounce();
newball.pushRight(3);
newball.pushUp(4);
}
sjs.onHit("newball",["top_screen","bottom_screen"], function(){
window.location = "gameover.html";
});
sjs.onHit("newball","paddle", function(newball,paddle){
score = score + 1;
score_txt.setText("Score: "+score);
sjs.bounceOff(newball,paddle);
});
sjs.bounceOff(ball, paddle);
soundEffect.play();
});
//right push paddle
sjs.keyDown(RIGHT_KEY, function(){
paddle1.pushRight();
paddle2.pushRight();
});
/*
var newball = new sjs.Image("Images/arson the blob.png");
newball.type = "ball";
newball.setSize(150,150);
newball.center();
newball.friction = 0;
newball.bounce();
newball.pushRight(3);
newball.pushUp(4);
*/
}
</script>
</head>
<body onload="start()">
<h1> Epic Pong game </h1>
<div id="target" style="margin:auto;background:lavender;"></div>
</body>
</html>