Skip to content

Commit 451e946

Browse files
committed
Latest local changes for branching (2).
1 parent 28046f4 commit 451e946

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+5281
-62
lines changed

.htaccess

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
AddType application/x-web-app-manifest+json .webapp
2+
ExpiresByType application/x-web-app-manifest+json "access"
3+
AddType text/cache-manifest .appcache
4+
ExpiresByType text/cache-manifest "access"

bkcore/hexgl/Gameplay.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ bkcore.hexgl.Gameplay = function(opts)
1212
{
1313
var self = this;
1414

15-
this.startDelay = 1000;
16-
this.countDownDelay = 1500;
15+
this.startDelay = opts.hud == null ? 0 : 1000;
16+
this.countDownDelay = opts.hud == null ? 1000 : 1500;
1717

1818
this.active = false;
1919
this.timer = new bkcore.Timer();
@@ -107,7 +107,7 @@ bkcore.hexgl.Gameplay.prototype.simu = function()
107107
{
108108
this.lapTimes = [92300, 91250, 90365];
109109
this.finishTime = this.lapTimes[0]+this.lapTimes[1]+this.lapTimes[2];
110-
this.hud != null && this.hud.display("Finish");
110+
if(this.hud != null) this.hud.display("Finish");
111111
this.step = 100;
112112
this.result = this.results.FINISH;
113113
this.shipControls.active = false;
@@ -128,7 +128,7 @@ bkcore.hexgl.Gameplay.prototype.start = function(opts)
128128
if(this.mode == 'replay')
129129
{
130130
this.cameraControls.mode = this.cameraControls.modes.ORBIT;
131-
this.hud != null && this.hud.messageOnly = true;
131+
if(this.hud != null) this.hud.messageOnly = true;
132132

133133
try {
134134
var d = localStorage['race-'+this.track.name+'-replay'];
@@ -166,12 +166,12 @@ bkcore.hexgl.Gameplay.prototype.end = function(result)
166166

167167
if(result == this.results.FINISH)
168168
{
169-
this.hud != null && this.hud.display("Finish");
169+
if(this.hud != null) this.hud.display("Finish");
170170
this.step = 100;
171171
}
172172
else if(result == this.results.DESTROYED)
173173
{
174-
this.hud != null && this.hud.display("Destroyed");
174+
if(this.hud != null) this.hud.display("Destroyed");
175175
this.step = 100;
176176
}
177177
}
@@ -184,22 +184,22 @@ bkcore.hexgl.Gameplay.prototype.update = function()
184184

185185
if(this.step == 0 && this.timer.time.elapsed >= this.countDownDelay+this.startDelay)
186186
{
187-
this.hud != null && this.hud.display("3");
187+
if(this.hud != null) this.hud.display("3");
188188
this.step = 1;
189189
}
190190
else if(this.step == 1 && this.timer.time.elapsed >= 2*this.countDownDelay+this.startDelay)
191191
{
192-
this.hud != null && this.hud.display("2");
192+
if(this.hud != null) this.hud.display("2");
193193
this.step = 2;
194194
}
195195
else if(this.step == 2 && this.timer.time.elapsed >= 3*this.countDownDelay+this.startDelay)
196196
{
197-
this.hud != null && this.hud.display("1");
197+
if(this.hud != null) this.hud.display("1");
198198
this.step = 3;
199199
}
200200
else if(this.step == 3 && this.timer.time.elapsed >= 4*this.countDownDelay+this.startDelay)
201201
{
202-
this.hud != null && this.hud.display("Go", 0.5);
202+
if(this.hud != null) this.hud.display("Go", 0.5);
203203
this.step = 4;
204204
this.timer.start();
205205

bkcore/hexgl/HexGL.js

+50-21
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ bkcore.hexgl.HexGL = function(opts)
1919

2020
this.a = window.location.href;
2121

22+
this.mobile = opts.mobile == undefined ? false : opts.mobile;
2223
this.active = true;
2324
this.displayHUD = opts.hud == undefined ? true : opts.hud;
2425
this.width = opts.width == undefined ? window.innerWidth : opts.width;
@@ -34,6 +35,8 @@ bkcore.hexgl.HexGL = function(opts)
3435

3536
this.mode = opts.mode == undefined ? 'timeattack' : opts.mode;
3637

38+
this.controlType = opts.controlType == undefined ? 1 : opts.controlType;
39+
3740
if(this.half)
3841
{
3942
this.width /= 2;
@@ -56,6 +59,10 @@ bkcore.hexgl.HexGL = function(opts)
5659
this.containers.main = opts.container == undefined ? document.body : opts.container;
5760
this.containers.overlay = opts.overlay == undefined ? document.body : opts.overlay;
5861

62+
this.gameover = opts.gameover == undefined ? null : opts.gameover;
63+
64+
this.godmode = opts.godmode == undefined ? false : opts.godmode;
65+
5966
this.hud = null;
6067

6168
this.gameplay = null;
@@ -86,7 +93,7 @@ bkcore.hexgl.HexGL.prototype.start = function()
8693

8794
function raf()
8895
{
89-
requestAnimationFrame( raf );
96+
if(self && self.active) requestAnimationFrame( raf );
9097
self.update();
9198
}
9299

@@ -104,7 +111,8 @@ bkcore.hexgl.HexGL.prototype.reset = function()
104111

105112
bkcore.hexgl.HexGL.prototype.restart = function()
106113
{
107-
this.document.getElementById('finish').style.display = 'none';
114+
try{ this.document.getElementById('finish').style.display = 'none'; }
115+
catch(e){};
108116
this.reset();
109117
}
110118

@@ -122,16 +130,16 @@ bkcore.hexgl.HexGL.prototype.init = function()
122130
{
123131
this.initHUD();
124132

125-
this.track.buildMaterials(this.quality);
133+
this.track.buildMaterials(this.quality, this.mobile);
126134

127-
this.track.buildScenes(this, this.quality);
135+
this.track.buildScenes(this, this.quality, this.mobile);
128136

129137
this.initGameComposer();
130138
}
131139

132140
bkcore.hexgl.HexGL.prototype.load = function(opts)
133141
{
134-
this.track.load(opts, this.quality);
142+
this.track.load(opts, this.quality, this.mobile);
135143
}
136144

137145
bkcore.hexgl.HexGL.prototype.initGameplay = function()
@@ -156,6 +164,23 @@ bkcore.hexgl.HexGL.prototype.initGameplay = function()
156164

157165
bkcore.hexgl.HexGL.prototype.displayScore = function(f, l)
158166
{
167+
this.active = false;
168+
169+
var tf = bkcore.Timer.msToTimeString(f);
170+
var tl = [
171+
bkcore.Timer.msToTimeString(l[0]),
172+
bkcore.Timer.msToTimeString(l[1]),
173+
bkcore.Timer.msToTimeString(l[2])
174+
];
175+
176+
if(this.mobile)
177+
{
178+
this.gameover.style.display = "block";
179+
this.gameover.innerHTML = tf.m + "'" + tf.s + "''" + tf.ms;
180+
this.containers.main.style.display = "none";
181+
return;
182+
}
183+
159184
var t = this.track;
160185
var dc = this.document.getElementById("finish");
161186
var ds = this.document.getElementById("finish-state");
@@ -171,12 +196,6 @@ bkcore.hexgl.HexGL.prototype.displayScore = function(f, l)
171196
var sl = this.document.getElementById("lowfps-msg");
172197
var d = this.difficulty == 0 ? 'casual' : 'hard';
173198
var ts = this.hud.timeSeparators;
174-
var tf = bkcore.Timer.msToTimeString(f);
175-
var tl = [
176-
bkcore.Timer.msToTimeString(l[0]),
177-
bkcore.Timer.msToTimeString(l[1]),
178-
bkcore.Timer.msToTimeString(l[2])
179-
];
180199

181200
if(this.gameplay.result == this.gameplay.results.FINISH)
182201
{
@@ -252,12 +271,15 @@ bkcore.hexgl.HexGL.prototype.initRenderer = function()
252271
clearColor: 0x000000
253272
});
254273

255-
renderer.physicallyBasedShading = true;
256-
renderer.gammaInput = true;
257-
renderer.gammaOutput = true;
258274

259-
renderer.shadowMapEnabled = true;
260-
renderer.shadowMapSoft = true;
275+
if(this.quality > 0 && !this.mobile)
276+
{
277+
renderer.physicallyBasedShading = true;
278+
renderer.gammaInput = true;
279+
renderer.gammaOutput = true;
280+
renderer.shadowMapEnabled = true;
281+
renderer.shadowMapSoft = true;
282+
}
261283

262284
renderer.autoClear = false;
263285
renderer.sortObjects = false;
@@ -297,7 +319,8 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
297319

298320
this.composers.game = new THREE.EffectComposer( this.renderer, renderTarget );
299321

300-
var effectScreen = new THREE.ShaderPass( THREE.ShaderExtras[ "screen" ] );
322+
var effectScreen = new THREE.ShaderPass( THREE.ShaderExtras[ "screen" ] );
323+
effectScreen.renderToScreen = true;
301324
var effectVignette = new THREE.ShaderPass( THREE.ShaderExtras[ "vignette" ] );
302325

303326
var effectHex = new THREE.ShaderPass( bkcore.threejs.Shaders[ "hexvignette" ] );
@@ -312,7 +335,7 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
312335
this.composers.game.addPass( renderSky );
313336
this.composers.game.addPass( renderModel );
314337

315-
if(this.quality > 0)
338+
if(this.quality > 0 && !this.mobile)
316339
{
317340
var effectFXAA = new THREE.ShaderPass( THREE.ShaderExtras[ "fxaa" ] );
318341
effectFXAA.uniforms[ 'resolution' ].value.set( 1 / this.width, 1 / this.height );
@@ -321,7 +344,7 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
321344

322345
this.extras.fxaa = effectFXAA;
323346
}
324-
if(this.quality > 1)
347+
if(this.quality > 1 && !this.mobile)
325348
{
326349
var effectBloom = new THREE.BloomPass( 0.8, 25, 4 , 256);
327350

@@ -330,7 +353,10 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
330353
this.extras.bloom = effectBloom;
331354
}
332355

333-
this.composers.game.addPass( effectHex );
356+
if(!this.mobile || this.quality > 0)
357+
this.composers.game.addPass( effectHex );
358+
else
359+
this.composers.game.addPass( effectScreen );
334360

335361

336362
}
@@ -343,7 +369,7 @@ bkcore.hexgl.HexGL.prototype.createMesh = function(parent, geometry, x, y, z, ma
343369
mesh.position.set( x, y, z );
344370
parent.add(mesh);
345371

346-
if(this.quality > 0)
372+
if(this.quality > 0 && !this.mobile)
347373
{
348374
mesh.castShadow = true;
349375
mesh.receiveShadow = true;
@@ -393,4 +419,7 @@ bkcore.hexgl.HexGL.prototype.tweakShipControls = function()
393419
c.driftLerp = 0.3;
394420
c.angularLerp = 0.4;
395421
}
422+
423+
if(this.godmode)
424+
c.shieldDamage = 0.0;
396425
}

bkcore/hexgl/ShipControls.js

+73-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ bkcore.hexgl.ShipControls = function(ctx)
1515

1616
this.active = true;
1717
this.destroyed = false;
18+
this.falling = false;
1819

1920
this.dom = domElement;
2021
this.mesh = null;
@@ -96,6 +97,8 @@ bkcore.hexgl.ShipControls = function(ctx)
9697
this.repulsionAmount = 0.0;
9798
this.repulsionForce = new THREE.Vector3();
9899

100+
this.fallVector = new THREE.Vector3(0,-20,0);
101+
99102
this.resetPos = null;
100103
this.resetRot = null;
101104

@@ -115,16 +118,40 @@ bkcore.hexgl.ShipControls = function(ctx)
115118
right: false
116119
};
117120

118-
this.touchController = bkcore.TouchController.isTouchable() ? new bkcore.TouchController(
119-
domElement, ctx.width/2,
120-
function(state, touch, event){
121-
if(event.touches.length <= 1)
122-
self.key.forward = false;
123-
else
124-
self.key.forward = true;
125-
console.log(event.touches.length);
126-
console.log(self.key.forward);
127-
}) : null;
121+
this.touchController = null;
122+
this.orientationController = null;
123+
124+
if(ctx.controlType == 1 && bkcore.controllers.TouchController.isCompatible())
125+
{
126+
this.touchController = new bkcore.controllers.TouchController(
127+
domElement, ctx.width/2,
128+
function(state, touch, event){
129+
if(event.touches.length >= 4)
130+
window.location.reload(false);
131+
else if(event.touches.length == 3)
132+
ctx.restart();
133+
else if(event.touches.length <= 1)
134+
self.key.forward = false;
135+
else
136+
self.key.forward = true;
137+
});
138+
}
139+
else if(ctx.controlType == 2 && bkcore.controllers.OrientationController.isCompatible())
140+
{
141+
this.orientationController = new bkcore.controllers.OrientationController(
142+
domElement, true,
143+
function(state, touch, event){
144+
console.log(event.touches.length);
145+
if(event.touches.length >= 4)
146+
window.location.reload(false);
147+
else if(event.touches.length == 3)
148+
ctx.restart();
149+
else if(event.touches.length < 1)
150+
self.key.forward = false;
151+
else
152+
self.key.forward = true;
153+
});
154+
}
128155

129156
function onKeyDown(event)
130157
{
@@ -212,8 +239,28 @@ bkcore.hexgl.ShipControls.prototype.destroy = function()
212239
this.collision.right = false;
213240
}
214241

242+
243+
bkcore.hexgl.ShipControls.prototype.fall = function()
244+
{
245+
this.active = false;
246+
this.collision.front = false;
247+
this.collision.left = false;
248+
this.collision.right = false;
249+
this.falling = true;
250+
_this = this;
251+
setTimeout(function(){
252+
_this.destroyed = true;
253+
}, 1500);
254+
}
255+
215256
bkcore.hexgl.ShipControls.prototype.update = function(dt)
216257
{
258+
if(this.falling)
259+
{
260+
this.mesh.position.addSelf(this.fallVector);
261+
return;
262+
}
263+
217264
if(!this.active) return;
218265

219266
this.rotation.y = 0;
@@ -229,6 +276,11 @@ bkcore.hexgl.ShipControls.prototype.update = function(dt)
229276
angularAmount -= this.touchController.stickVector.x/100 * this.angularSpeed * dt;
230277
rollAmount += this.touchController.stickVector.x/100 * this.rollAngle;
231278
}
279+
if(this.orientationController != null)
280+
{
281+
angularAmount += this.orientationController.beta/45 * this.angularSpeed * dt;
282+
rollAmount -= this.orientationController.beta/45 * this.rollAngle;
283+
}
232284

233285
if(this.key.forward)
234286
this.speed += this.thrust * dt;
@@ -478,6 +530,17 @@ bkcore.hexgl.ShipControls.prototype.collisionCheck = function(dt)
478530
this.speed = 0;
479531
}
480532

533+
// DIRTY GAMEOVER
534+
if(rCol < 128 && lCol < 128)
535+
{
536+
var fCol = this.collisionMap.getPixel(Math.round(pos.x+2), Math.round(pos.z+2)).r;
537+
if(fCol < 128)
538+
{
539+
console.log('GAMEOVER');
540+
this.fall();
541+
}
542+
}
543+
481544
this.speed *= this.collisionSpeedDecrease;
482545
this.speed *= (1-this.collisionSpeedDecreaseCoef*(1-collision.r/255));
483546
this.boost = 0;

0 commit comments

Comments
 (0)