Вход Регистрация
Файл: Space race/bkcore/hexgl/tracks/Cityscape.js
Строк: 384
<?php
/*
 * HexGL
 * @author Thibaut 'BKcore' Despoulain <http://bkcore.com>
 * @license This work is licensed under the Creative Commons Attribution-NonCommercial 3.0 Unported License.
 *          To view a copy of this license, visit http://creativecommons.org/licenses/by-nc/3.0/.
 */

var bkcore bkcore || {};
bkcore.hexgl bkcore.hexgl || {};
bkcore.hexgl.tracks bkcore.hexgl.tracks || {};

bkcore.hexgl.tracks.Cityscape = {

    
libnull,
    
materials: {},

    
name"Cityscape",

    
checkpoints: {
        list: [
0,1,2],
        
start0,
        
last2
    
},

    
spawn: {
        
x: -1134*2,
        
y387,
        
z: -443*2
    
},

    
spawnRotation: {
        
x0,
        
y0,
        
z0
    
},

    
analysernull,
    
pixelRatio2048.0 6000.0,

    
load: function(optsquality)
    {
        
this.lib = new bkcore.threejs.Loader(opts);

        
// desktop + quality low
        // OR
        // mobile + quality low or mid
        
if(quality 2// LOW
        
{
            
this.lib.load({
                
textures: {
                    
'hex'                                "textures/hud/hex.jpg",
                    
'spark'                                "textures/particles/spark.png",
                    
'cloud'                                "textures/particles/cloud.png",
                    
'ship.feisar.diffuse'                "textures/ships/feisar/diffuse.jpg",
                    
'booster.diffuse'                    "textures/ships/feisar/booster/booster.png",
                    
'booster.sprite'                    "textures/ships/feisar/booster/boostersprite.jpg",
                    
'track.cityscape.diffuse'            "textures/tracks/cityscape/diffuse.jpg",
                    
'track.cityscape.scrapers1.diffuse'    "textures/tracks/cityscape/scrapers1/diffuse.jpg",
                    
'track.cityscape.scrapers2.diffuse'    "textures/tracks/cityscape/scrapers2/diffuse.jpg",
                    
'track.cityscape.start.diffuse'        "textures/tracks/cityscape/start/diffuse.jpg",
                    
'track.cityscape.start.banner'        "textures/tracks/cityscape/start/start.jpg",
                    
'bonus.base.diffuse'                "textures/bonus/base/diffuse.jpg"
                
},
                
texturesCube: {
                    
'skybox.dawnclouds'                    "textures/skybox/dawnclouds/%1.jpg"
                
},
                
geometries: {
                    
'bonus.base'                        "geometries/bonus/base/base.js",
                    
'booster'                            "geometries/booster/booster.js",
                    
'ship.feisar'                        "geometries/ships/feisar/feisar.js",
                    
'track.cityscape'                    "geometries/tracks/cityscape/track.js",
                    
'track.cityscape.scrapers1'            "geometries/tracks/cityscape/scrapers1.js",
                    
'track.cityscape.scrapers2'            "geometries/tracks/cityscape/scrapers2.js",
                    
'track.cityscape.start'                "geometries/tracks/cityscape/start.js",
                    
'track.cityscape.start.banner'        "geometries/tracks/cityscape/startbanner.js",
                    
'track.cityscape.bonus.speed'        "geometries/tracks/cityscape/bonus/speed.js"
                
},
                
analysers: {
                    
'track.cityscape.collision'            "textures/tracks/cityscape/collision.png",
                    
'track.cityscape.height'            "textures/tracks/cityscape/height.png"
                
},
                
images: {
                    
'hud.bg'                            "textures/hud/hud-bg.png",
                    
'hud.speed'                            "textures/hud/hud-fg-speed.png",
                    
'hud.shield'                        "textures/hud/hud-fg-shield.png"
                
},
                
sounds: {
                    
bg: {
                        
src'audio/bg.ogg',
                        
looptrue,
                        
usePannerfalse
                    
},
                    
crash: {
                        
src'audio/crash.ogg',
                        
loopfalse,
                        
usePannertrue
                    
},
                    
destroyed: {
                        
src'audio/destroyed.ogg',
                        
loopfalse,
                        
usePannerfalse
                    
},
                    
boost: {
                        
src'audio/boost.ogg',
                        
loopfalse,
                        
usePannertrue
                    
},
                    
wind: {
                        
src'audio/wind.ogg',
                        
looptrue,
                        
usePannertrue
                    
}
                }
            });
        }
        
// desktop + quality mid or high
        // OR
        // mobile + quality high
        
else // HIGH
        
{console.log('HIGH');
            
this.lib.load({
                
textures: {
                    
'hex'                                "textures.full/hud/hex.jpg",
                    
'spark'                                "textures.full/particles/spark.png",
                    
'cloud'                                "textures.full/particles/cloud.png",
                    
'ship.feisar.diffuse'                "textures.full/ships/feisar/diffuse.jpg",
                    
'ship.feisar.specular'                "textures.full/ships/feisar/specular.jpg",
                    
'ship.feisar.normal'                "textures.full/ships/feisar/normal.jpg",
                    
'booster.diffuse'                    "textures.full/ships/feisar/booster/booster.png",
                    
'booster.sprite'                    "textures.full/ships/feisar/booster/boostersprite.jpg",
                    
'track.cityscape.diffuse'            "textures.full/tracks/cityscape/diffuse.jpg",
                    
'track.cityscape.specular'            "textures.full/tracks/cityscape/specular.jpg",
                    
'track.cityscape.normal'            "textures.full/tracks/cityscape/normal.jpg",
                    
'track.cityscape.scrapers1.diffuse'    "textures.full/tracks/cityscape/scrapers1/diffuse.jpg",
                    
'track.cityscape.scrapers1.specular'"textures.full/tracks/cityscape/scrapers1/specular.jpg",
                    
'track.cityscape.scrapers1.normal'    "textures.full/tracks/cityscape/scrapers1/normal.jpg",
                    
'track.cityscape.scrapers2.diffuse'    "textures.full/tracks/cityscape/scrapers2/diffuse.jpg",
                    
'track.cityscape.scrapers2.specular'"textures.full/tracks/cityscape/scrapers2/specular.jpg",
                    
'track.cityscape.scrapers2.normal'    "textures.full/tracks/cityscape/scrapers2/normal.jpg",
                    
'track.cityscape.start.diffuse'        "textures.full/tracks/cityscape/start/diffuse.jpg",
                    
'track.cityscape.start.specular'    "textures.full/tracks/cityscape/start/specular.jpg",
                    
'track.cityscape.start.normal'        "textures.full/tracks/cityscape/start/normal.jpg",
                    
'track.cityscape.start.banner'        "textures.full/tracks/cityscape/start/start.jpg",
                    
'bonus.base.diffuse'                "textures.full/bonus/base/diffuse.jpg",
                    
'bonus.base.normal'                    "textures.full/bonus/base/normal.jpg",
                    
'bonus.base.specular'                "textures.full/bonus/base/specular.jpg"
                
},
                
texturesCube: {
                    
'skybox.dawnclouds'                    "textures.full/skybox/dawnclouds/%1.jpg"
                
},
                
geometries: {
                    
'bonus.base'                        "geometries/bonus/base/base.js",
                    
'booster'                            "geometries/booster/booster.js",
                    
'ship.feisar'                        "geometries/ships/feisar/feisar.js",
                    
'track.cityscape'                    "geometries/tracks/cityscape/track.js",
                    
'track.cityscape.scrapers1'            "geometries/tracks/cityscape/scrapers1.js",
                    
'track.cityscape.scrapers2'            "geometries/tracks/cityscape/scrapers2.js",
                    
'track.cityscape.start'                "geometries/tracks/cityscape/start.js",
                    
'track.cityscape.start.banner'        "geometries/tracks/cityscape/startbanner.js",
                    
'track.cityscape.bonus.speed'        "geometries/tracks/cityscape/bonus/speed.js"
                
},
                
analysers: {
                    
'track.cityscape.collision'            "textures.full/tracks/cityscape/collision.png",
                    
'track.cityscape.height'            "textures.full/tracks/cityscape/height.png"
                
},
                
images: {
                    
'hud.bg'                            "textures.full/hud/hud-bg.png",
                    
'hud.speed'                            "textures.full/hud/hud-fg-speed.png",
                    
'hud.shield'                        "textures.full/hud/hud-fg-shield.png"
                
},
                
sounds: {
                    
bg: {
                        
src'audio/bg.ogg',
                        
looptrue
                    
},
                    
crash: {
                        
src'audio/crash.ogg',
                        
loopfalse
                    
},
                    
destroyed: {
                        
src'audio/destroyed.ogg',
                        
loopfalse
                    
},
                    
boost: {
                        
src'audio/boost.ogg',
                        
loopfalse
                    
},
                    
wind: {
                        
src'audio/wind.ogg',
                        
looptrue
                    
}
                }
            });
        }
    },

    
buildMaterials: function(quality)
    {
        
// desktop + quality low
        // OR
        // mobile + quality low or mid
        
if(quality 2// LOW
        
{
            
this.materials.track = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""track.cityscape.diffuse"),
                
ambient0xcccccc
            
});

            
this.materials.bonusBase = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""bonus.base.diffuse"),
                
ambient0xcccccc
            
});

            
this.materials.bonusSpeed = new THREE.MeshBasicMaterial({
                
color0x0096ff
            
});

            
this.materials.ship = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""ship.feisar.diffuse"),
                
ambient0xaaaaaa
            
});

            
this.materials.booster = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""booster.diffuse"),
                
transparenttrue
            
});

            
this.materials.scrapers1 = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""track.cityscape.scrapers1.diffuse"),
                
ambient0xcccccc
            
});

            
this.materials.scrapers2 = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""track.cityscape.scrapers2.diffuse"),
                
ambient0xcccccc
            
});

            
this.materials.start = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""track.cityscape.start.diffuse"),
                
ambient0xcccccc
            
});

            
this.materials.startBanner = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""track.cityscape.start.banner"),
                
transparentfalse
            
});
        }
        
// desktop + quality mid or high
        // OR
        // mobile + quality high
        
else // HIGH
        
{
            
this.materials.track bkcore.Utils.createNormalMaterial({
                
diffusethis.lib.get("textures""track.cityscape.diffuse"),
                
specularthis.lib.get("textures""track.cityscape.specular"),
                
normalthis.lib.get("textures""track.cityscape.normal"),
                
ambient0xffffff,
                
shininess42,
                
metaltrue,
                
perPixeltrue
            
});

            
this.materials.bonusBase bkcore.Utils.createNormalMaterial({
                
diffusethis.lib.get("textures""bonus.base.diffuse"),
                
specularthis.lib.get("textures""bonus.base.specular"),
                
normalthis.lib.get("textures""bonus.base.normal"),
                
normalScale3.0,
                
ambient0x444444,
                
shininess42,
                
metalfalse,
                
perPixelfalse
            
});

            
this.materials.bonusSpeed = new THREE.MeshBasicMaterial({
                
color0x0096ff
            
});

            
this.materials.ship bkcore.Utils.createNormalMaterial({
                
diffusethis.lib.get("textures""ship.feisar.diffuse"),
                
specularthis.lib.get("textures""ship.feisar.specular"),
                
normalthis.lib.get("textures""ship.feisar.normal"),
                
ambient0x444444,
                
shininess42,
                
metaltrue,
                
perPixelfalse
            
});

            
this.materials.booster = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""booster.diffuse"),
                
transparenttrue
            
});

            
this.materials.scrapers1 bkcore.Utils.createNormalMaterial({
                
diffusethis.lib.get("textures""track.cityscape.scrapers1.diffuse"),
                
specularthis.lib.get("textures""track.cityscape.scrapers1.specular"),
                
normalthis.lib.get("textures""track.cityscape.scrapers1.normal"),
                
cubethis.lib.get("texturesCube""skybox.dawnclouds"),
                
reflectivity0.8,
                
ambient0x444444,
                
shininess42,
                
metalfalse,
                
perPixelfalse
            
});

            
this.materials.scrapers2 bkcore.Utils.createNormalMaterial({
                
diffusethis.lib.get("textures""track.cityscape.scrapers2.diffuse"),
                
specularthis.lib.get("textures""track.cityscape.scrapers2.specular"),
                
normalthis.lib.get("textures""track.cityscape.scrapers2.normal"),
                
cubethis.lib.get("texturesCube""skybox.dawnclouds"),
                
reflectivity0.8,
                
ambient0x000000,
                
shininess42,
                
metalfalse,
                
perPixelfalse
            
});

            
this.materials.start bkcore.Utils.createNormalMaterial({
                
diffusethis.lib.get("textures""track.cityscape.start.diffuse"),
                
specularthis.lib.get("textures""track.cityscape.start.specular"),
                
normalthis.lib.get("textures""track.cityscape.start.normal"),
                
ambient0xaaaaaa,
                
shininess42,
                
metalfalse,
                
perPixelfalse
            
});

            
this.materials.startBanner = new THREE.MeshBasicMaterial({
                
mapthis.lib.get("textures""track.cityscape.start.banner"),
                
transparentfalse
            
});
        }
    },

    
buildScenes: function(ctxquality)
    {
        
// IMPORTANT
        
this.analyser this.lib.get("analysers""track.cityscape.collision");

        
// SKYBOX
        
var sceneCube = new THREE.Scene();

        var 
cameraCube = new THREE.PerspectiveCamera70ctx.width ctx.height16000 );
        
sceneCube.addcameraCube );

        var 
skyshader THREE.ShaderUtils.lib"cube" ];
        
skyshader.uniforms"tCube" ].texture this.lib.get("texturesCube""skybox.dawnclouds");

        var 
skymaterial = new THREE.ShaderMaterial(
        {
            
fragmentShaderskyshader.fragmentShader,
            
vertexShaderskyshader.vertexShader,
            
uniformsskyshader.uniforms,
            
depthWritefalse
        
});

        var 
mesh = new THREE.Mesh( new THREE.CubeGeometry100100100 ), skymaterial );
        
mesh.flipSided true;

        
sceneCube.add(mesh);

        
ctx.manager.add("sky"sceneCubecameraCube);

        var 
ambient 0xbbbbbbdiffuse 0xffffffspecular 0xffffffshininess 42scale 23;

        
// MAIN SCENE
        
var camera = new THREE.PerspectiveCamera70ctx.width ctx.height160000 );

        var 
scene = new THREE.Scene();
        
scene.addcamera );
        
scene.add( new THREE.AmbientLightambient ) );

        
// SUN
        
var sun = new THREE.DirectionalLightdiffuse1.530000 );
        
sun.position.set( -400012001800 );
        
sun.lookAt(new THREE.Vector3());

        
// desktop + quality mid or high
        
if(quality 2)
        {
            
sun.castShadow true;
            
sun.shadowCameraNear 50;
            
sun.shadowCameraFar camera.far*2;
            
sun.shadowCameraRight     =  3000;
            
sun.shadowCameraLeft      = -3000;
            
sun.shadowCameraTop       =  3000;
            
sun.shadowCameraBottom    = -3000;
            
//sun.shadowCameraVisible = true;
            
sun.shadowBias 0.0001;
            
sun.shadowDarkness 0.7;
            
sun.shadowMapWidth 2048;
            
sun.shadowMapHeight 2048;
        }
        
scene.addsun );

        
// SHIP
        
var ship ctx.createMesh(scenethis.lib.get("geometries""ship.feisar"), -1134*210, -443*2this.materials.ship);

        var 
booster ctx.createMesh(shipthis.lib.get("geometries""booster"), 00.665, -3.8this.materials.booster);
        
booster.depthWrite false;

        var 
boosterSprite = new THREE.Sprite({
            
mapthis.lib.get("textures""booster.sprite"),
            
blendingTHREE.AdditiveBlending,
            
useScreenCoordinatesfalse,
            
color0xffffff
        
});
        
boosterSprite.scale.set(0.020.020.02);
        
boosterSprite.mergeWith3D false;
        
booster.add(boosterSprite);

        var 
boosterLight = new THREE.PointLight(0x00a2ff4.060);
        
boosterLight.position.set(00.665, -4);
        
        
// desktop + quality low, mid or high
        // OR
        // mobile + quality mid or high
        // NB booster is now enabled on desktop + low quality,
        // when it wasn't before; this is because this booster setting
        // is the only difference between mobile + mid quality
        // and desktop + low quality, so I merged them for convenience
        
if(quality 0)
            
ship.add(boosterLight);

        
// SHIP CONTROLS
        
var shipControls = new bkcore.hexgl.ShipControls(ctx);
        
shipControls.collisionMap this.lib.get("analysers""track.cityscape.collision");
        
shipControls.collisionPixelRatio 2048.0 6000.0;
        
shipControls.collisionDetection true;
        
shipControls.heightMap this.lib.get("analysers""track.cityscape.height");;
        
shipControls.heightPixelRatio 2048.0 6000.0;
        
shipControls.heightBias 4.0;
        
shipControls.heightScale 10.0;
        
shipControls.control(ship);
        
ctx.components.shipControls shipControls;
        
ctx.tweakShipControls();

        
// SHIP EFFECTS AND PARTICLES
        
var fxParams = {
            
scenescene,
            
shipControlsshipControls,
            
boosterbooster,
            
boosterSpriteboosterSprite,
            
boosterLightboosterLight,
            
useParticlesfalse
        
};
        
        
// desktop + quality mid or high
        
if(quality 2)
        {
            
fxParams.textureCloud this.lib.get("textures""cloud");
            
fxParams.textureSpark this.lib.get("textures""spark");
            
fxParams.useParticles true;
        }
        
ctx.components.shipEffects = new bkcore.hexgl.ShipEffects(fxParams);

        
// TRACK
        
var track ctx.createMesh(scenethis.lib.get("geometries""track.cityscape"), 0, -50this.materials.track);
        var 
bonusBase ctx.createMesh(scenethis.lib.get("geometries""bonus.base"), 0, -50this.materials.bonusBase);
        var 
bonusSpeed ctx.createMesh(scenethis.lib.get("geometries""track.cityscape.bonus.speed"), 0, -50this.materials.bonusSpeed);
        
bonusSpeed.receiveShadow false;
        var 
scrapers1 ctx.createMesh(scenethis.lib.get("geometries""track.cityscape.scrapers1"), 000this.materials.scrapers1);
        var 
scrapers2 ctx.createMesh(scenethis.lib.get("geometries""track.cityscape.scrapers2"), 000this.materials.scrapers2);
        var 
start ctx.createMesh(scenethis.lib.get("geometries""track.cityscape.start"), 0, -50this.materials.start);
        var 
startbanner ctx.createMesh(scenethis.lib.get("geometries""track.cityscape.start.banner"), 0, -50this.materials.startBanner);
        
startbanner.doubleSided true;

        
// CAMERA
        
ctx.components.cameraChase = new bkcore.hexgl.CameraChase({
            
targetship,
            
cameracamera,
            
cameraCubectx.manager.get("sky").camera,
            
lerp0.5,
            
yoffset8.0,
            
zoffset10.0,
            
viewOffset10.0
        
});

        
ctx.manager.add("game"scenecamera, function(deltarenderer)
        {
            if(
delta 25 && this.objects.lowFPS 1000this.objects.lowFPS++;

            var 
dt delta/16.6;

            
this.objects.components.shipControls.update(dt);

            
this.objects.components.shipEffects.update(dt);

            
this.objects.components.cameraChase.update(dtthis.objects.components.shipControls.getSpeedRatio());
            
/*this.objects.time += 0.002;
            var c = this.objects.components.cameraChase.camera;
            c.position.set(
                Math.cos(this.objects.time)*15+this.objects.components.shipControls.dummy.position.x,
                10+this.objects.components.shipControls.dummy.position.y,
                Math.sin(this.objects.time)*15+this.objects.components.shipControls.dummy.position.z
            );
            c.lookAt(this.objects.components.shipControls.dummy.position);
            this.objects.components.cameraChase.cameraCube.rotation.copy(c.rotation);*/

            
this.objects.composers.game.render(dt);
            if(
this.objects.hudthis.objects.hud.update(
                
this.objects.components.shipControls.getRealSpeed(100),
                
this.objects.components.shipControls.getRealSpeedRatio(),
                
this.objects.components.shipControls.getShield(100),
                
this.objects.components.shipControls.getShieldRatio()
            );
            if(
this.objects.components.shipControls.getShieldRatio() < 0.2)
                
this.objects.extras.vignetteColor.setHex(0x992020);
            else
                
this.objects.extras.vignetteColor.setHex(0x458ab1);
        },
        {
            
componentsctx.components,
            
composersctx.composers,
            
extrasctx.extras,
            
qualityquality,
            
hudctx.hud,
            
time0.0,
            
lowFPS0
        
});
    }
}
?>
Онлайн: 2
Реклама