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

Commit 1ae588a

Browse files
committed
Merge branch 'master' of github.com:coryt/lightcycle-hackathon
2 parents aa195c1 + d64b52a commit 1ae588a

File tree

2 files changed

+48
-18
lines changed

2 files changed

+48
-18
lines changed

Client/js/brushes/lightTrail.js

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* To change this template use File | Settings | File Templates.
77
*/
88

9-
var BRUSH_SIZE = 1,
9+
var BRUSH_SIZE = 3,
1010
BRUSH_PRESSURE = 1;
1111

1212
function lightTrail( context, color )
@@ -18,26 +18,28 @@ lightTrail.prototype =
1818
{
1919
context: null,
2020

21-
mouseX: null, mouseY: null,
21+
positionX: null, positionY: null,
2222

2323
painters: null,
2424

2525
interval: null,
2626

2727
color:[0,0,0],
2828

29+
lightCycle: new Image() ,
30+
2931
init: function( context, color )
3032
{
3133
var scope = this;
32-
34+
scope.lightCycle.src = "images/lightcycle.png";
3335
this.context = context;
3436
this.context.globalCompositeOperation = 'source-over';
3537

36-
this.mouseX = 400;
37-
this.mouseY = 400;
38+
this.positionX = 400;
39+
this.positionY = 400;
3840

3941
if (!color && color.length != 0){
40-
this.color = color;
42+
scope.color = color;
4143
}// else defaults to RGB 0,0,0
4244

4345
this.painters = new Array();
@@ -56,16 +58,18 @@ lightTrail.prototype =
5658
scope.context.lineWidth = BRUSH_SIZE;
5759
scope.context.strokeStyle = "rgba(" + scope.color[0] + ", " + scope.color[1] + ", " + scope.color[2] + ", " + 0.05 * BRUSH_PRESSURE + ")";
5860

59-
for (i = 0; i < scope.painters.length; i++)
61+
for (i = 0; i < scope.painters.length; i++)
6062
{
6163
scope.context.beginPath();
6264
scope.context.moveTo(scope.painters[i].dx, scope.painters[i].dy);
6365

64-
scope.painters[i].dx -= scope.painters[i].ax = (scope.painters[i].ax + (scope.painters[i].dx - scope.mouseX) * scope.painters[i].div) * scope.painters[i].ease;
65-
scope.painters[i].dy -= scope.painters[i].ay = (scope.painters[i].ay + (scope.painters[i].dy - scope.mouseY) * scope.painters[i].div) * scope.painters[i].ease;
66+
scope.painters[i].dx -= scope.painters[i].ax = (scope.painters[i].ax + (scope.painters[i].dx - scope.positionX) * scope.painters[i].div) * scope.painters[i].ease;
67+
scope.painters[i].dy -= scope.painters[i].ay = (scope.painters[i].ay + (scope.painters[i].dy - scope.positionY) * scope.painters[i].div) * scope.painters[i].ease;
6668
scope.context.lineTo(scope.painters[i].dx, scope.painters[i].dy);
6769
scope.context.stroke();
6870
}
71+
72+
scope.context.drawImage(scope.lightCycle, scope.painters[i-1].dx, scope.painters[i-1].dy, 33.33, 12.66);
6973
}
7074
},
7175

@@ -75,25 +79,25 @@ lightTrail.prototype =
7579
},
7680

7781
//coordinates where the player starts
78-
strokeStart: function( mouseX, mouseY )
82+
strokeStart: function( positionX, positionY )
7983
{
80-
this.mouseX = mouseX;
81-
this.mouseY = mouseY
84+
this.positionX = positionX;
85+
this.positionY = positionY;
8286

8387
for (var i = 0; i < this.painters.length; i++)
8488
{
85-
this.painters[i].dx = mouseX;
86-
this.painters[i].dy = mouseY;
89+
this.painters[i].dx = positionX;
90+
this.painters[i].dy = positionY;
8791
}
8892

8993
this.shouldDraw = true;
9094
},
9195

9296
//new coordinates moved to
93-
stroke: function( mouseX, mouseY )
97+
stroke: function( positionX, positionY )
9498
{
95-
this.mouseX = mouseX;
96-
this.mouseY = mouseY;
99+
this.positionX = positionX;
100+
this.positionY = positionY;
97101
},
98102

99103
//end

Client/js/serverConn.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,27 @@ ServerConn.prototype.parseMessage_ = function(data) {
6868
for (var i = 0; i < players.length; i ++) {
6969
var player = players[i];
7070
if (player) {
71-
state.addPlayer(player);
71+
var pos = player.position;
72+
var x = null;
73+
var y = null;
74+
if (pos) {
75+
var split = pos.split(',');
76+
if (split && split.length == 2) {
77+
x = split[0];
78+
y = split[1];
79+
}
80+
}
81+
var p = this.getPlayer({
82+
ID : player.id,
83+
Nickname : player.name,
84+
Colour : player.color,
85+
StartX : x,
86+
StartY : y,
87+
Direction : player.direction,
88+
Status : player.status
89+
});
90+
91+
state.addPlayer(p);
7292
}
7393
}
7494
}
@@ -115,4 +135,10 @@ ServerConn.prototype.notifyLeft = function() {
115135
/** Send RIGHT event to server */
116136
ServerConn.prototype.notifyRight = function() {
117137
this.notify_(Action.RIGHT);
138+
}
139+
140+
/** Function to get or create a player given a set of properties. Can be overwritten. */
141+
ServerConn.prototype.getPlayer = function(props) {
142+
var player = new Player(props);
143+
return player;
118144
}

0 commit comments

Comments
 (0)