-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
136 lines (114 loc) · 3.03 KB
/
index.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<html><head>
<title>Girls Who Code Sample</title>
<script type="text/javascript" src="./processing.min.js"></script>
</head>
<body>
<h1>GwC Lexington Sample</h1>
<p>Check out my brick out game!</p>
<canvas id="processing-canvas" tabindex="0" style="width='5000px' height='5000px'"></canvas>
<script type="text/processing" data-processing-target="processing-canvas">
size(400, 400);
var paddleW = 75;
var paddleH = 10;
var bottom = 390 - paddleH;
var right = 400 - paddleW;
var bricksToDraw = [true, true, true, true, true, true, true, true];
var brickH = 15;
var brickW = 90;
var brickTop1 = 30;
var brickTop2 = brickTop1 + brickH + 10;
var x = 0;
var speedFloor = 2;
var speedCeiling = 7;
var speedX = speedFloor;
var speedY = speedFloor;
var ballX = 200;
var ballY = 200;
var drawBricks = function() {
for(var i = 0; i < 4; ++i) {
var pos = i * 100;
if(bricksToDraw[i]) {
rect(pos + 5, brickTop1, brickW, brickH);
}
if(bricksToDraw[i+4]) {
rect(pos + 5, brickTop2, brickW, brickH);
}
}
};
var testBricks = function() {
for(var i = 0; i < 4; ++i) {
var pos = i * 100;
var changeSpeed = false;
var directionX = 1;
if(ballX > (pos+5) && ballX < (pos+5+brickW) &&
ballY > brickTop1 && ballY < (brickTop1+brickH)) {
if(bricksToDraw[i]) {
bricksToDraw[i] = false;
changeSpeed = true;
}
}
if(ballX > (pos+5) && ballX < (pos+5+brickW) &&
ballY > brickTop2 && ballY < (brickTop2+brickH)) {
if(bricksToDraw[i+4]) {
bricksToDraw[i+4] = false;
changeSpeed = true;
}
}
if(changeSpeed) {
speedX = random(speedFloor,speedCeiling);
speedY = random(speedFloor,speedCeiling);
}
}
};
var testPaddle = function() {
if(ballX > x && ballX < (x + paddleW) && ballY > bottom) {
speedX = -random(speedFloor,speedCeiling);
speedY = -random(speedFloor,speedCeiling);
}
};
var testWall = function() {
if(ballX > 400 || ballX < 0) {
speedX = -speedX;
}
if(ballY > 400) {
ballX = 200;
ballY = 150;
speedY = speedFloor;
speedX = speedFloor;
} else if(ballY < 0) {
speedY = -speedY;
}
};
var testWin = function() {
var iWon = true;
for(var i = 0; i < 8 && iWon; i++) {
if(bricksToDraw[i]) {
iWon = false;
}
}
if(iWon) {
background(255, 0, 0);
text("CONGRATULATIONS!!", 10, 100, 380, 200);
}
};
draw = function() {
background(0, 0, 0);
drawBricks();
// Paddle
x = mouseX;
if(x > right) {
x = right;
}
rect(x, bottom, paddleW, paddleH, 100);
// Ball
ballX += speedX;
ballY += speedY;
ellipse(ballX, ballY, 10, 10);
// Test Contact
testBricks();
testPaddle();
testWall();
testWin();
};
</script>
</body></html>