-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplayer2win.html
108 lines (98 loc) · 3.37 KB
/
player2win.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
<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=[];
var jumlahBola=50;
var now,then;
var playZoom=0;
var gambar=new Image();
gambar.src="img/main_menu.png";
for(var i=0;i<jumlahBola;i++){
bola= new Ball(8,"#2B648F");
bola.setLocation(Math.random()*canvas.width+1,Math.random()*canvas.height+1);
bola.speed=Math.random()*1+0.2;
bola.createTarget(canvas);
console.log(bola.x,bola.y);
arrayBola.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>260&&msx<260+330&&msy>425&&msy<425+76){
window.location.href="start.html";
}
};
function mousemove(e){
var rect = canvas.getBoundingClientRect();
msx = e.pageX - rect.left;
msy = e.pageY - rect.top;
if(msx>260&&msx<260+330&&msy>425&&msy<425+76){
canvas.style.cursor="pointer";
playZoom=0.2;
}else{
canvas.style.cursor="default";
playZoom=0;
}
}
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 drawAllBall(){
for (var i = 0; i < arrayBola.length; i++) {
//context.moveTo(arrayBola[i].x,arrayBola[i].y);
arrayBola[i].drawNoLine(context);
};
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]);
};
};
}
now=new Date().getTime();
function drawFrame(){
context.clearRect(0, 0, canvas.width, canvas.height);
moveBall();
drawAllBall();
context.drawImage(gambar,0,522,503,214,190,50,503,214);
context.drawImage(gambar,0,741,330,76,260-(330*(playZoom/2)),425-(76*(playZoom/2)),330+(330*playZoom),76+(76*playZoom));
window.requestAnimationFrame(drawFrame,canvas)
};
then = new Date().getTime();
drawFrame();
};
</script>
</body>
</html>