diff --git a/bkcore/hexgl/Gameplay.js b/bkcore/hexgl/Gameplay.js index e0f3a61..79c22b5 100644 --- a/bkcore/hexgl/Gameplay.js +++ b/bkcore/hexgl/Gameplay.js @@ -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; diff --git a/bkcore/hexgl/HexGL.js b/bkcore/hexgl/HexGL.js index 66127a7..fc0e3f0 100644 --- a/bkcore/hexgl/HexGL.js +++ b/bkcore/hexgl/HexGL.js @@ -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 { diff --git a/bkcore/hexgl/ShipControls.js b/bkcore/hexgl/ShipControls.js index 9fe0f51..2fb4c9d 100644 --- a/bkcore/hexgl/ShipControls.js +++ b/bkcore/hexgl/ShipControls.js @@ -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) diff --git a/index.html b/index.html index 963194c..4487e59 100644 --- a/index.html +++ b/index.html @@ -85,6 +85,7 @@ quality: bkcore.Utils.getURLParameter('quality'), difficulty: bkcore.Utils.getURLParameter('difficulty'), half: bkcore.Utils.getURLParameter('half'), + mode: 'timeattack', track: 'Cityscape' });