-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgames.js
More file actions
51 lines (50 loc) · 1.78 KB
/
games.js
File metadata and controls
51 lines (50 loc) · 1.78 KB
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
function cfKnightGame(x, y, table)
{
if (table.destroy_segments(x, y, destroySegmentLinearAnimation)) {
return;
}
for (let n = 1; n <= table.lines_cnt; n++) {
if (segments_intersect(x, y, ...table.last_point,
table.points[n - 1][0], table.points[n - 1][1],
table.points[n][0], table.points[n][1])) {
pulseNodeAnimation([256, 0, 0], 3000, 100000)(table.node(y, x));
return;
}
}
let last_point = table.last_point;
if (squared_distance(x, y, last_point[0], last_point[1]) == 0) {
return;
}
if (squared_distance(x, y, last_point[0], last_point[1]) == 5) {
table.add_segment(x, y, drawSegmentLinearAnimation);
return;
}
pulseNodeAnimation([256, 0, 0], 3000, 100000)(table.node(y, x));
}
function cfLengthenGame(x, y, table)
{
if (table.destroy_segments(x, y, destroySegmentLinearAnimation)) {
return;
}
for (let n = 1; n <= table.lines_cnt; n++) {
if (segments_intersect(x, y, ...table.last_point,
table.points[n - 1][0], table.points[n - 1][1],
table.points[n][0], table.points[n][1])) {
pulseNodeAnimation([256, 0, 0], 3000, 100000)(table.node(y, x));
return;
}
}
if (table.lines_cnt == 0) {
table.add_segment(x, y, drawSegmentLinearAnimation);
return;
}
let last_point = table.last_point;
let prelast_point = table.points[table.points.length - 2];
if (squared_distance(x, y, last_point[0], last_point[1]) >
squared_distance(last_point[0], last_point[1], prelast_point[0], prelast_point[1]))
{
table.add_segment(x, y, drawSegmentLinearAnimation);
return;
}
pulseNodeAnimation([256, 0, 0], 3000, 100000)(table.node(y, x));
}