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

Commit 6c87bcd

Browse files
committed
Light cycles now also use dead-reckoning for their rotations
1 parent 00596aa commit 6c87bcd

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

Client/js/brushes/lightTrail2.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ function gameDisplay()
55
var pointAges = {};
66
var colors = {};
77
var rotation = {};
8+
var lastRotation = {};
89

910
var lightCycle = new Image();
1011
lightCycle.src = "images/lightcycle.png";
@@ -81,7 +82,7 @@ function gameDisplay()
8182
context.quadraticCurveTo(line[i].x, line[i].y, line[i+1].x, line[i+1].y);
8283
}
8384

84-
var percent = Math.min(1, (new Date().getTime() - pointAges[name])/200);
85+
var percent = Math.min(1, (new Date().getTime() - pointAges[name])/250);
8586
var invPercent = 1- percent;
8687
var l1 = line.length-1;
8788
var l2 = l1 -1;
@@ -100,8 +101,16 @@ function gameDisplay()
100101
{
101102
whatAngle = determineAngle(line[l2].x, line[l2].y, lx, ly);
102103
}
103-
context.translate(lx, ly);
104+
var lr = lastRotation[name];
105+
if (!lr){lr=whatAngle;}
104106

107+
if (lr - whatAngle > Math.PI)
108+
{whatAngle+=Math.PI*2;}
109+
110+
whatAngle = (whatAngle*percent) + (lr*invPercent);
111+
lastRotation[name]=whatAngle%(Math.PI*2);
112+
113+
context.translate(lx, ly);
105114
context.rotate(whatAngle);
106115
context.translate(-20, -5);
107116
context.drawImage(lightCycle, 0, 0, 30, 12);
@@ -135,15 +144,15 @@ function fakePlayer(name, gameDisplay, color)
135144
x=400;
136145
y=400;
137146
angle = Math.random() * Math.PI * 2;
138-
speed=10;
147+
speed=20;
139148
}
140149

141150
function step()
142151
{
143152
//this random function has a clockwise bias. This is intentional as it gives more
144153
//interesting paths
145-
var maxDR = 15;
146-
var bias = 0.55;
154+
var maxDR = 45;
155+
var bias = 0.6;
147156
var dr = (Math.random() * (maxDR)- (maxDR/2*bias)) / 360 * Math.PI * 2;
148157
angle += dr;
149158
angle %= Math.PI * 2;
@@ -166,5 +175,5 @@ function fakePlayer(name, gameDisplay, color)
166175
}
167176

168177
init();
169-
setInterval(step, 200);
178+
setInterval(step, 250);
170179
}

0 commit comments

Comments
 (0)