Updated gameplay with replay mode.
This commit is contained in:
@@ -37,6 +37,7 @@ bkcore.hexgl.Gameplay = function(opts)
|
||||
FINISH: 1,
|
||||
DESTROYED: 2,
|
||||
WRONGWAY: 3,
|
||||
REPLAY: 4,
|
||||
NONE: -1
|
||||
};
|
||||
this.result = this.results.NONE;
|
||||
@@ -88,7 +89,17 @@ bkcore.hexgl.Gameplay = function(opts)
|
||||
{
|
||||
self.end(self.results.DESTROYED);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.modes.replay = function()
|
||||
{
|
||||
self.raceData.applyInterpolated(this.timer.time.elapsed);
|
||||
|
||||
if(self.raceData.seek == self.raceData.last)
|
||||
{
|
||||
self.end(self.result.REPLAY);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
bkcore.hexgl.Gameplay.prototype.simu = function()
|
||||
@@ -101,7 +112,7 @@ bkcore.hexgl.Gameplay.prototype.simu = function()
|
||||
this.shipControls.active = false;
|
||||
}
|
||||
|
||||
bkcore.hexgl.Gameplay.prototype.start = function()
|
||||
bkcore.hexgl.Gameplay.prototype.start = function(opts)
|
||||
{
|
||||
this.finishTime = null;
|
||||
this.score = null;
|
||||
@@ -113,6 +124,21 @@ bkcore.hexgl.Gameplay.prototype.start = function()
|
||||
this.previousCheckPoint = this.track.checkpoints.start;
|
||||
|
||||
this.raceData = new bkcore.hexgl.RaceData(this.track.name, this.mode, this.shipControls);
|
||||
if(this.mode == 'replay')
|
||||
{
|
||||
try {
|
||||
var d = localStorage['race-'+this.track.name+'-replay'];
|
||||
if(d == undefined)
|
||||
{
|
||||
console.error('No replay data for '+'race-'+this.track.name+'-replay'+'.');
|
||||
return false;
|
||||
}
|
||||
this.raceData.import(
|
||||
JSON.parse(d)
|
||||
);
|
||||
}
|
||||
catch(e) { console.error('Bad replay format : '+e); return false; }
|
||||
}
|
||||
|
||||
this.active = true;
|
||||
this.step = 0;
|
||||
|
||||
@@ -32,6 +32,8 @@ bkcore.hexgl.HexGL = function(opts)
|
||||
|
||||
this.track = bkcore.hexgl.tracks[ opts.track == undefined ? 'Cityscape' : opts.track ];
|
||||
|
||||
this.mode = opts.mode == undefined ? 'timeattack' : opts.mode;
|
||||
|
||||
if(this.half)
|
||||
{
|
||||
this.width /= 2;
|
||||
@@ -137,16 +139,12 @@ bkcore.hexgl.HexGL.prototype.initGameplay = function()
|
||||
var self = this;
|
||||
|
||||
this.gameplay = new bkcore.hexgl.Gameplay({
|
||||
mode: "timeattack",
|
||||
mode: this.mode,
|
||||
hud: this.hud,
|
||||
shipControls: this.components.shipControls,
|
||||
analyser: this.track.analyser,
|
||||
pixelRatio: this.track.pixelRatio,
|
||||
track: {
|
||||
checkpoints: this.track.checkpoints,
|
||||
spawn: this.track.spawn,
|
||||
spawnRotation: this.track.spawnRotation
|
||||
},
|
||||
track: this.track,
|
||||
onFinish: function() {
|
||||
self.displayScore(this.finishTime, this.lapTimes);
|
||||
}
|
||||
@@ -157,7 +155,7 @@ bkcore.hexgl.HexGL.prototype.initGameplay = function()
|
||||
|
||||
bkcore.hexgl.HexGL.prototype.displayScore = function(f, l)
|
||||
{
|
||||
var t = 'cityscape';
|
||||
var t = this.track;
|
||||
var dc = this.document.getElementById("finish");
|
||||
var ds = this.document.getElementById("finish-state");
|
||||
var dh = this.document.getElementById("finish-hallmsg");
|
||||
@@ -191,7 +189,7 @@ bkcore.hexgl.HexGL.prototype.displayScore = function(f, l)
|
||||
localStorage['score-'+t+'-'+d] = f;
|
||||
|
||||
// Export race data
|
||||
localStorage['race-'+t+'-'+d] = JSON.Stringify(this.gameplay.raceData.export());
|
||||
localStorage['race-'+t+'-replay'] = JSON.Stringify(this.gameplay.raceData.export());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -337,6 +337,42 @@ bkcore.hexgl.ShipControls.prototype.update = function(dt)
|
||||
}
|
||||
};
|
||||
|
||||
bkcore.hexgl.ShipControls.prototype.teleport = function(pos, quat)
|
||||
{
|
||||
this.quaternion.copy(quat);
|
||||
this.dummy.quaternion.copy(this.quaternion);
|
||||
|
||||
this.dummy.position.copy(pos);
|
||||
this.dummy.matrix.setPosition(this.dummy.position);
|
||||
this.dummy.matrix.setRotationFromQuaternion(this.dummy.quaternion);
|
||||
|
||||
if(this.mesh != null)
|
||||
{
|
||||
this.mesh.matrix.identity();
|
||||
/*
|
||||
// Gradient (Mesh only, no dummy physics impact)
|
||||
var gradientDelta = (this.gradientTarget - this.gradient) * this.gradientLerp;
|
||||
if(Math.abs(gradientDelta) > this.epsilon) this.gradient += gradientDelta;
|
||||
if(Math.abs(this.gradient) > this.epsilon)
|
||||
{
|
||||
this.gradientAxis.set(1,0,0);
|
||||
this.mesh.matrix.rotateByAxis(this.gradientAxis, this.gradient);
|
||||
}
|
||||
|
||||
// Tilting (Idem)
|
||||
var tiltDelta = (this.tiltTarget - this.tilt) * this.tiltLerp;
|
||||
if(Math.abs(tiltDelta) > this.epsilon) this.tilt += tiltDelta;
|
||||
if(Math.abs(this.tilt) > this.epsilon)
|
||||
{
|
||||
this.tiltAxis.set(0,0,1);
|
||||
this.mesh.matrix.rotateByAxis(this.tiltAxis, this.tilt);
|
||||
}
|
||||
*/
|
||||
this.mesh.applyMatrix(this.dummy.matrix);
|
||||
this.mesh.updateMatrixWorld(true);
|
||||
}
|
||||
}
|
||||
|
||||
bkcore.hexgl.ShipControls.prototype.boosterCheck = function(dt)
|
||||
{
|
||||
if(!this.collisionMap || !this.collisionMap.loaded)
|
||||
|
||||
Reference in New Issue
Block a user