Skip to content
This repository was archived by the owner on Oct 19, 2025. It is now read-only.

Commit 00596aa

Browse files
committed
Added the light cycles to the light trail.
1 parent bae0f54 commit 00596aa

File tree

1 file changed

+57
-6
lines changed

1 file changed

+57
-6
lines changed

Client/js/brushes/lightTrail2.js

Lines changed: 57 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,26 @@ function gameDisplay()
44
var lines ={};
55
var pointAges = {};
66
var colors = {};
7+
var rotation = {};
8+
9+
var lightCycle = new Image();
10+
lightCycle.src = "images/lightcycle.png";
711

812
self.setColor = function(name, color)
913
{
1014
colors[name] = color;
1115
}
1216

13-
self.addPoint = function (name, x, y)
17+
self.addPoint = function (name, x, y, r)
1418
{
1519
var line = lines[name];
1620
if (!line)
1721
{
1822
line = [];
1923
lines[name] = line;
20-
pointAges[name] = 0;
2124
}
2225
pointAges[name] = (new Date()).getTime();
26+
rotation[name] = r;
2327
line.push({"x":x,"y":y});
2428
}
2529

@@ -28,11 +32,43 @@ function gameDisplay()
2832
lines[name] = [];
2933
}
3034

35+
function determineAngle(x1,y1,x2,y2)
36+
{
37+
var quarter = Math.PI/2;
38+
var angle = 0;
39+
try
40+
{
41+
var dx = x2-x1;
42+
var dy = y2-y1;
43+
44+
if (dy == 0)
45+
{
46+
angle=dx>0?0:Math.PI;
47+
}
48+
else
49+
{
50+
angle=Math.atan(Math.abs(dx/dy));
51+
}
52+
if (dx < 0 && dy > 0)
53+
{angle+=quarter;}
54+
else if (dx < 0 && dy < 0)
55+
{angle+=quarter*2;}
56+
else if (dx > 0 && dy < 0)
57+
{angle+=quarter*3;}
58+
}
59+
catch (err)
60+
{}
61+
angle = angle ? angle : 0;
62+
angle = Math.max(0, angle);
63+
angle = Math.min(Math.PI * 2, angle);
64+
return angle;
65+
}
66+
3167
function drawPlayer(context, name)
3268
{
3369
context.save();
3470
context.strokeStyle = colors[name];
35-
context.lineWidth = 3;
71+
context.lineWidth = 4;
3672
context.lineCap = "round";
3773
context.lineJoin = "round";
3874
var line = lines[name];
@@ -56,7 +92,20 @@ function gameDisplay()
5692
context.quadraticCurveTo(line[line.length-2].x, line[line.length-2].y, lx, ly);
5793
context.moveTo(line[0].x, line[0].y);
5894
context.closePath();
59-
context.stroke();
95+
context.stroke();
96+
97+
context.save();
98+
var whatAngle = rotation[name];
99+
if (!whatAngle)
100+
{
101+
whatAngle = determineAngle(line[l2].x, line[l2].y, lx, ly);
102+
}
103+
context.translate(lx, ly);
104+
105+
context.rotate(whatAngle);
106+
context.translate(-20, -5);
107+
context.drawImage(lightCycle, 0, 0, 30, 12);
108+
context.restore();
60109
}
61110
context.restore();
62111
}
@@ -93,7 +142,9 @@ function fakePlayer(name, gameDisplay, color)
93142
{
94143
//this random function has a clockwise bias. This is intentional as it gives more
95144
//interesting paths
96-
var dr = (Math.random() * 30- 11) / 360 * Math.PI * 2;
145+
var maxDR = 15;
146+
var bias = 0.55;
147+
var dr = (Math.random() * (maxDR)- (maxDR/2*bias)) / 360 * Math.PI * 2;
97148
angle += dr;
98149
angle %= Math.PI * 2;
99150

@@ -111,7 +162,7 @@ function fakePlayer(name, gameDisplay, color)
111162
gameDisplay.removePoints(name);
112163
}
113164

114-
gameDisplay.addPoint(name, x, y);
165+
gameDisplay.addPoint(name, x, y, angle);
115166
}
116167

117168
init();

0 commit comments

Comments
 (0)