-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.html
202 lines (185 loc) · 6.89 KB
/
start.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<html>
<head>
<meta charset="utf-8">
<title>Awas Ketiban !</title>
<style type="text/css">
body{
text-align: center;
}
</style>
</head>
<body>
<canvas id = "canvas" width = "900" height = "600" style="border :#123578 2px solid"></canvas>
<script src = "Ball.js"></script>
<script src = "utils.js"></script>
<script>
window.onload=function(){
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d');
var bola;
var arrayBola=[],arrayBola1=[];
var jumlahBola=50;
var now,then,angle=0;
var playZoom=0,vsComZoom=0;
var papan ={
x:180,
y:50
};
var isInPLay=false,isInPLay2=false;
var click=new Audio("click.mp3");
var opening = new Audio("opening.mp3");
opening.play();
var gambar=new Image();
gambar.src="img/main_menu.png";
var tulisan = new Image();
tulisan.src="img/tulisan.png";
for(var i=0;i<jumlahBola;i++){
bola= new Ball(Math.random()*6+6,utils.randomColor());
bola.setLocation(Math.random()*canvas.width+1,Math.random()*canvas.height+1);
bola.speed=Math.random()*1+0.2;
bola.createTarget(canvas);
bola.vx=Math.random()*6-3;
bola.vy=Math.random()*6-3;
bola.globalAlpha=(bola.radius/12)*1;
arrayBola.push(bola);
}
for (var i = 0; i <jumlahBola; i++) {
bola = new Ball(Math.ceil(Math.random()*10),"#123578");
bola.setLocation(Math.random()*canvas.width+1,Math.random()*canvas.height+1);
bola.vx=bola.radius/10;
bola.globalAlpha=(bola.radius/50)*1;
arrayBola1.push(bola);
};
window.addEventListener("mousedown", mousedn, true);
window.addEventListener("mousemove", mousemove, true);
function mousedn(e) {
var rect = canvas.getBoundingClientRect();
msx = e.pageX - rect.left;
msy = e.pageY - rect.top;
if(msx>335&&msx<335+219&&msy>380&&msy<380+63){
window.location.href="p1vsp2.html";
}
if(msx>300&&msx<300+293&&msy>470&&msy<470+63){
window.location.href="p1vsCom.html";
}
};
function mousemove(e){
var rect = canvas.getBoundingClientRect();
msx = e.pageX - rect.left;
msy = e.pageY - rect.top;
if(msx>335&&msx<335+219&&msy>380&&msy<380+63){
playZoom=0.2;
}else{
playZoom=0;
}
if(msx>300&&msx<300+293&&msy>470&&msy<470+63){
vsComZoom=0.2;
}else{
vsComZoom=0;
}
if(msx>335&&msx<335+219&&msy>380&&msy<380+63||msx>300&&msx<300+293&&msy>470&&msy<470+63){
canvas.style.cursor="pointer";
if(isInPLay===false){
click.play();
isInPLay=true;
}
}else{
canvas.style.cursor="default";
isInPLay=false;
}
}
function moveBall(){
now=new Date().getTime();
var delta = now-then;
for (var i = 0; i < arrayBola.length; i++) {
dy=arrayBola[i].targetY-arrayBola[i].y;
dx=arrayBola[i].targetX-arrayBola[i].x;
angle=Math.atan2(dy,dx);
arrayBola[i].vy=Math.sin(angle)*bola.speed;
arrayBola[i].vx=Math.cos(angle)*bola.speed;
if(arrayBola[i].targetDistance()<2){
arrayBola[i].createTarget(canvas);
}
arrayBola[i].moveToTarget(delta);
};
then=now;
};
function spring(partA, partB) {
springAmount=0.005;
var dx = partB.x - partA.x,
dy = partB.y - partA.y,
dist = Math.sqrt(dx * dx + dy * dy);
if (dist < 4*partA.radius) {
context.strokeStyle = partA.color;
/*context.beginPath();
context.moveTo(partA.x, partA.y);
context.lineTo(partB.x, partB.y);
context.stroke();*/
partA.lineToBall(context,partB);
var ax = dx * springAmount,
ay = dy * springAmount;
partA.vx += ax;
partA.vy += ay;
partB.vx -= ax;
partB.vy -= ay;
}
}
function move(partA, i) {
partA.x += partA.vx;
partA.y += partA.vy;
if (partA.x > canvas.width) {
partA.x = 0;
} else if (partA.x < 0) {
partA.x = canvas.width;
}
if (partA.y > canvas.height) {
partA.y = 0;
} else if (partA.y < 0) {
partA.y = canvas.height;
}
for (var partB, j = i + 1; j < jumlahBola; j++) {
partB = arrayBola[j];
spring(partA, partB);
}
}
function drawAllBall(){
context.save()
for (var i = 0; i < arrayBola.length; i++) {
//context.moveTo(arrayBola[i].x,arrayBola[i].y);
context.globalAlpha=arrayBola[i].globalAlpha;
arrayBola[i].drawNoLine(context);
};
context.restore();
for(var i=0;i<arrayBola.length;i++){
/* context.lineTo(arrayBola[i].x,arrayBola[i].y);*/
for (var j = i+1; j < arrayBola.length; j++) {
arrayBola[i].createLine(context,arrayBola[j]);
};
};
}
function linearMove(ball,i){
ball.x+=ball.vx;
if(ball.x>canvas.width){
ball.x=0;
ball.y=Math.ceil(Math.random()*canvas.height);
}
ball.drawNoLine(context);
}
now=new Date().getTime();
function drawFrame(){
context.clearRect(0, 0, canvas.width, canvas.height);
arrayBola1.forEach(linearMove);
arrayBola.forEach(move);
drawAllBall();
context.drawImage(gambar,2,2,550,285,papan.x,25,550,285);
//context.drawImage(gambar,554,2,170,80,371-(170*(playZoom/2)),425-(80*(playZoom/2)),170+(170*playZoom),80+(80*playZoom));
context.drawImage(tulisan,0,0,219,63,335-(219*(playZoom/2)),380-(63*(playZoom/2)),219+(219*playZoom),63+(63*playZoom));
context.drawImage(tulisan,0,76,297,63,300-(297*(vsComZoom/2)),470-(63*(vsComZoom/2)),297+(297*vsComZoom),63+(vsComZoom*63));
window.requestAnimationFrame(drawFrame,canvas)
};
then = new Date().getTime();
drawFrame();
};
</script>
</body>
</html>