Latest local changes for branching (2).

This commit is contained in:
BKcore
2013-03-16 16:11:34 +01:00
parent 28046f4a66
commit 451e9464a3
95 changed files with 5281 additions and 62 deletions
+10 -10
View File
@@ -12,8 +12,8 @@ bkcore.hexgl.Gameplay = function(opts)
{
var self = this;
this.startDelay = 1000;
this.countDownDelay = 1500;
this.startDelay = opts.hud == null ? 0 : 1000;
this.countDownDelay = opts.hud == null ? 1000 : 1500;
this.active = false;
this.timer = new bkcore.Timer();
@@ -107,7 +107,7 @@ bkcore.hexgl.Gameplay.prototype.simu = function()
{
this.lapTimes = [92300, 91250, 90365];
this.finishTime = this.lapTimes[0]+this.lapTimes[1]+this.lapTimes[2];
this.hud != null && this.hud.display("Finish");
if(this.hud != null) this.hud.display("Finish");
this.step = 100;
this.result = this.results.FINISH;
this.shipControls.active = false;
@@ -128,7 +128,7 @@ bkcore.hexgl.Gameplay.prototype.start = function(opts)
if(this.mode == 'replay')
{
this.cameraControls.mode = this.cameraControls.modes.ORBIT;
this.hud != null && this.hud.messageOnly = true;
if(this.hud != null) this.hud.messageOnly = true;
try {
var d = localStorage['race-'+this.track.name+'-replay'];
@@ -166,12 +166,12 @@ bkcore.hexgl.Gameplay.prototype.end = function(result)
if(result == this.results.FINISH)
{
this.hud != null && this.hud.display("Finish");
if(this.hud != null) this.hud.display("Finish");
this.step = 100;
}
else if(result == this.results.DESTROYED)
{
this.hud != null && this.hud.display("Destroyed");
if(this.hud != null) this.hud.display("Destroyed");
this.step = 100;
}
}
@@ -184,22 +184,22 @@ bkcore.hexgl.Gameplay.prototype.update = function()
if(this.step == 0 && this.timer.time.elapsed >= this.countDownDelay+this.startDelay)
{
this.hud != null && this.hud.display("3");
if(this.hud != null) this.hud.display("3");
this.step = 1;
}
else if(this.step == 1 && this.timer.time.elapsed >= 2*this.countDownDelay+this.startDelay)
{
this.hud != null && this.hud.display("2");
if(this.hud != null) this.hud.display("2");
this.step = 2;
}
else if(this.step == 2 && this.timer.time.elapsed >= 3*this.countDownDelay+this.startDelay)
{
this.hud != null && this.hud.display("1");
if(this.hud != null) this.hud.display("1");
this.step = 3;
}
else if(this.step == 3 && this.timer.time.elapsed >= 4*this.countDownDelay+this.startDelay)
{
this.hud != null && this.hud.display("Go", 0.5);
if(this.hud != null) this.hud.display("Go", 0.5);
this.step = 4;
this.timer.start();
+50 -21
View File
@@ -19,6 +19,7 @@ bkcore.hexgl.HexGL = function(opts)
this.a = window.location.href;
this.mobile = opts.mobile == undefined ? false : opts.mobile;
this.active = true;
this.displayHUD = opts.hud == undefined ? true : opts.hud;
this.width = opts.width == undefined ? window.innerWidth : opts.width;
@@ -34,6 +35,8 @@ bkcore.hexgl.HexGL = function(opts)
this.mode = opts.mode == undefined ? 'timeattack' : opts.mode;
this.controlType = opts.controlType == undefined ? 1 : opts.controlType;
if(this.half)
{
this.width /= 2;
@@ -56,6 +59,10 @@ bkcore.hexgl.HexGL = function(opts)
this.containers.main = opts.container == undefined ? document.body : opts.container;
this.containers.overlay = opts.overlay == undefined ? document.body : opts.overlay;
this.gameover = opts.gameover == undefined ? null : opts.gameover;
this.godmode = opts.godmode == undefined ? false : opts.godmode;
this.hud = null;
this.gameplay = null;
@@ -86,7 +93,7 @@ bkcore.hexgl.HexGL.prototype.start = function()
function raf()
{
requestAnimationFrame( raf );
if(self && self.active) requestAnimationFrame( raf );
self.update();
}
@@ -104,7 +111,8 @@ bkcore.hexgl.HexGL.prototype.reset = function()
bkcore.hexgl.HexGL.prototype.restart = function()
{
this.document.getElementById('finish').style.display = 'none';
try{ this.document.getElementById('finish').style.display = 'none'; }
catch(e){};
this.reset();
}
@@ -122,16 +130,16 @@ bkcore.hexgl.HexGL.prototype.init = function()
{
this.initHUD();
this.track.buildMaterials(this.quality);
this.track.buildMaterials(this.quality, this.mobile);
this.track.buildScenes(this, this.quality);
this.track.buildScenes(this, this.quality, this.mobile);
this.initGameComposer();
}
bkcore.hexgl.HexGL.prototype.load = function(opts)
{
this.track.load(opts, this.quality);
this.track.load(opts, this.quality, this.mobile);
}
bkcore.hexgl.HexGL.prototype.initGameplay = function()
@@ -156,6 +164,23 @@ bkcore.hexgl.HexGL.prototype.initGameplay = function()
bkcore.hexgl.HexGL.prototype.displayScore = function(f, l)
{
this.active = false;
var tf = bkcore.Timer.msToTimeString(f);
var tl = [
bkcore.Timer.msToTimeString(l[0]),
bkcore.Timer.msToTimeString(l[1]),
bkcore.Timer.msToTimeString(l[2])
];
if(this.mobile)
{
this.gameover.style.display = "block";
this.gameover.innerHTML = tf.m + "'" + tf.s + "''" + tf.ms;
this.containers.main.style.display = "none";
return;
}
var t = this.track;
var dc = this.document.getElementById("finish");
var ds = this.document.getElementById("finish-state");
@@ -171,12 +196,6 @@ bkcore.hexgl.HexGL.prototype.displayScore = function(f, l)
var sl = this.document.getElementById("lowfps-msg");
var d = this.difficulty == 0 ? 'casual' : 'hard';
var ts = this.hud.timeSeparators;
var tf = bkcore.Timer.msToTimeString(f);
var tl = [
bkcore.Timer.msToTimeString(l[0]),
bkcore.Timer.msToTimeString(l[1]),
bkcore.Timer.msToTimeString(l[2])
];
if(this.gameplay.result == this.gameplay.results.FINISH)
{
@@ -252,12 +271,15 @@ bkcore.hexgl.HexGL.prototype.initRenderer = function()
clearColor: 0x000000
});
renderer.physicallyBasedShading = true;
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
if(this.quality > 0 && !this.mobile)
{
renderer.physicallyBasedShading = true;
renderer.gammaInput = true;
renderer.gammaOutput = true;
renderer.shadowMapEnabled = true;
renderer.shadowMapSoft = true;
}
renderer.autoClear = false;
renderer.sortObjects = false;
@@ -297,7 +319,8 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
this.composers.game = new THREE.EffectComposer( this.renderer, renderTarget );
var effectScreen = new THREE.ShaderPass( THREE.ShaderExtras[ "screen" ] );
var effectScreen = new THREE.ShaderPass( THREE.ShaderExtras[ "screen" ] );
effectScreen.renderToScreen = true;
var effectVignette = new THREE.ShaderPass( THREE.ShaderExtras[ "vignette" ] );
var effectHex = new THREE.ShaderPass( bkcore.threejs.Shaders[ "hexvignette" ] );
@@ -312,7 +335,7 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
this.composers.game.addPass( renderSky );
this.composers.game.addPass( renderModel );
if(this.quality > 0)
if(this.quality > 0 && !this.mobile)
{
var effectFXAA = new THREE.ShaderPass( THREE.ShaderExtras[ "fxaa" ] );
effectFXAA.uniforms[ 'resolution' ].value.set( 1 / this.width, 1 / this.height );
@@ -321,7 +344,7 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
this.extras.fxaa = effectFXAA;
}
if(this.quality > 1)
if(this.quality > 1 && !this.mobile)
{
var effectBloom = new THREE.BloomPass( 0.8, 25, 4 , 256);
@@ -330,7 +353,10 @@ bkcore.hexgl.HexGL.prototype.initGameComposer = function()
this.extras.bloom = effectBloom;
}
this.composers.game.addPass( effectHex );
if(!this.mobile || this.quality > 0)
this.composers.game.addPass( effectHex );
else
this.composers.game.addPass( effectScreen );
}
@@ -343,7 +369,7 @@ bkcore.hexgl.HexGL.prototype.createMesh = function(parent, geometry, x, y, z, ma
mesh.position.set( x, y, z );
parent.add(mesh);
if(this.quality > 0)
if(this.quality > 0 && !this.mobile)
{
mesh.castShadow = true;
mesh.receiveShadow = true;
@@ -393,4 +419,7 @@ bkcore.hexgl.HexGL.prototype.tweakShipControls = function()
c.driftLerp = 0.3;
c.angularLerp = 0.4;
}
if(this.godmode)
c.shieldDamage = 0.0;
}
+73 -10
View File
@@ -15,6 +15,7 @@ bkcore.hexgl.ShipControls = function(ctx)
this.active = true;
this.destroyed = false;
this.falling = false;
this.dom = domElement;
this.mesh = null;
@@ -96,6 +97,8 @@ bkcore.hexgl.ShipControls = function(ctx)
this.repulsionAmount = 0.0;
this.repulsionForce = new THREE.Vector3();
this.fallVector = new THREE.Vector3(0,-20,0);
this.resetPos = null;
this.resetRot = null;
@@ -115,16 +118,40 @@ bkcore.hexgl.ShipControls = function(ctx)
right: false
};
this.touchController = bkcore.TouchController.isTouchable() ? new bkcore.TouchController(
domElement, ctx.width/2,
function(state, touch, event){
if(event.touches.length <= 1)
self.key.forward = false;
else
self.key.forward = true;
console.log(event.touches.length);
console.log(self.key.forward);
}) : null;
this.touchController = null;
this.orientationController = null;
if(ctx.controlType == 1 && bkcore.controllers.TouchController.isCompatible())
{
this.touchController = new bkcore.controllers.TouchController(
domElement, ctx.width/2,
function(state, touch, event){
if(event.touches.length >= 4)
window.location.reload(false);
else if(event.touches.length == 3)
ctx.restart();
else if(event.touches.length <= 1)
self.key.forward = false;
else
self.key.forward = true;
});
}
else if(ctx.controlType == 2 && bkcore.controllers.OrientationController.isCompatible())
{
this.orientationController = new bkcore.controllers.OrientationController(
domElement, true,
function(state, touch, event){
console.log(event.touches.length);
if(event.touches.length >= 4)
window.location.reload(false);
else if(event.touches.length == 3)
ctx.restart();
else if(event.touches.length < 1)
self.key.forward = false;
else
self.key.forward = true;
});
}
function onKeyDown(event)
{
@@ -212,8 +239,28 @@ bkcore.hexgl.ShipControls.prototype.destroy = function()
this.collision.right = false;
}
bkcore.hexgl.ShipControls.prototype.fall = function()
{
this.active = false;
this.collision.front = false;
this.collision.left = false;
this.collision.right = false;
this.falling = true;
_this = this;
setTimeout(function(){
_this.destroyed = true;
}, 1500);
}
bkcore.hexgl.ShipControls.prototype.update = function(dt)
{
if(this.falling)
{
this.mesh.position.addSelf(this.fallVector);
return;
}
if(!this.active) return;
this.rotation.y = 0;
@@ -229,6 +276,11 @@ bkcore.hexgl.ShipControls.prototype.update = function(dt)
angularAmount -= this.touchController.stickVector.x/100 * this.angularSpeed * dt;
rollAmount += this.touchController.stickVector.x/100 * this.rollAngle;
}
if(this.orientationController != null)
{
angularAmount += this.orientationController.beta/45 * this.angularSpeed * dt;
rollAmount -= this.orientationController.beta/45 * this.rollAngle;
}
if(this.key.forward)
this.speed += this.thrust * dt;
@@ -478,6 +530,17 @@ bkcore.hexgl.ShipControls.prototype.collisionCheck = function(dt)
this.speed = 0;
}
// DIRTY GAMEOVER
if(rCol < 128 && lCol < 128)
{
var fCol = this.collisionMap.getPixel(Math.round(pos.x+2), Math.round(pos.z+2)).r;
if(fCol < 128)
{
console.log('GAMEOVER');
this.fall();
}
}
this.speed *= this.collisionSpeedDecrease;
this.speed *= (1-this.collisionSpeedDecreaseCoef*(1-collision.r/255));
this.boost = 0;
+7 -7
View File
@@ -37,11 +37,11 @@ bkcore.hexgl.tracks.Cityscape = {
analyser: null,
pixelRatio: 2048.0 / 6000.0,
load: function(opts, quality)
load: function(opts, quality, mobile)
{
this.lib = new bkcore.threejs.Loader(opts);
if(quality < 1) // LOW
if((quality < 1 && !mobile) || quality < 2) // LOW
{
this.lib.load({
textures: {
@@ -137,9 +137,9 @@ bkcore.hexgl.tracks.Cityscape = {
}
},
buildMaterials: function(quality)
buildMaterials: function(quality, mobile)
{
if(this.quality < 1) // LOW
if((quality < 1 && !mobile) || quality < 2) // LOW
{
this.materials.track = new THREE.MeshBasicMaterial({
map: this.lib.get("textures", "track.cityscape.diffuse"),
@@ -268,7 +268,7 @@ bkcore.hexgl.tracks.Cityscape = {
}
},
buildScenes: function(ctx, quality)
buildScenes: function(ctx, quality, mobile)
{
// IMPORTANT
this.analyser = this.lib.get("analysers", "track.cityscape.collision");
@@ -311,7 +311,7 @@ bkcore.hexgl.tracks.Cityscape = {
sun.position.set( -4000, 1200, 1800 );
sun.lookAt(new THREE.Vector3());
if(quality > 0)
if(quality > 0 && !mobile)
{
sun.castShadow = true;
sun.shadowCameraNear = 50;
@@ -371,7 +371,7 @@ bkcore.hexgl.tracks.Cityscape = {
boosterLight: boosterLight,
useParticles: false
};
if(quality > 0)
if(quality > 0 && !mobile)
{
fxParams.textureCloud = this.lib.get("textures", "cloud");
fxParams.textureSpark = this.lib.get("textures", "spark");