-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrawingTools.js
74 lines (65 loc) · 1.58 KB
/
drawingTools.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
var Kingimg;
window.onload = function() {
Kingimg = document.getElementById("king");
};
function drawChecker(row, col, w, color, King, kingColor) {
var x = row * w;
var y = col * w;
if(King) {
drawFillCircle(x + w/2, y + w/2, w/2, color);
ctx.drawImage(Kingimg, x + w/13, y + w/8, w/1.5 * 1.308, w/1.5);
}
else {
drawFillCircle(x + w/2, y + w/2, w/2, color);
}
}
function DrawPossibleMove(row, col, w, color) {
var x = row * w;
var y = col * w;
drawFillRect(x, y, w, w, color);
}
function drawFillRect(x, y, w, h, color) {
ctx.beginPath();
ctx.fillStyle = color;
ctx.fillRect(x, y, w, h);
ctx.stroke();
}
function drawFillCircle(x, y, r, color) {
ctx.beginPath();
ctx.fillStyle = color;
ctx.arc(x, y, r, 0, 2 * Math.PI);
ctx.fill();
}
var mouse = {
pressed: false,
lastPressed: false,
lastPos: {
x: 0,
y: 0
},
x: 0,
y: 0
}
function MouseUp(e) {
if(mouse.pressed == true) {
mouse.pressed = false;
}
}
function MouseDown(e) {
if(mouse.pressed == false) {
mouse.pressed = true;
if(game.adding == true) {
addPiece();
}
else if (game.moving == false) {
pickUpPiece(board1, player1, player2);
}
}
}
function MouseMove(e) {
mouse.x = e.x;
mouse.y = e.y;
}
document.addEventListener("mouseup", MouseUp);
document.addEventListener("mousedown", MouseDown);
document.addEventListener("mousemove", MouseMove);