From c85499ab57d6d497ddb01ba6e92b9adef8d5dd46 Mon Sep 17 00:00:00 2001 From: Raymond Hulha Date: Thu, 21 Nov 2013 18:10:45 +0100 Subject: [PATCH] prepare for more than 1 zombie. --- js/loadScene.js | 36 ++++++++++++++++++++++-------------- lib/FPSCamComponent.js | 4 ++-- lib/ShotgunComponent.js | 3 ++- 3 files changed, 26 insertions(+), 17 deletions(-) diff --git a/js/loadScene.js b/js/loadScene.js index 0e43d6a..8edbda9 100644 --- a/js/loadScene.js +++ b/js/loadScene.js @@ -83,10 +83,15 @@ require([ //var point; // The Loader takes care of loading data from a URL... var loader = new DynamicLoader({world: goo.world, rootPath: 'res'}); + //var loader2 = new DynamicLoader({world: goo.world, rootPath: 'res'}); + //var loader3 = new DynamicLoader({world: goo.world, rootPath: 'res'}); + var promises = []; promises.push(loader.loadFromBundle('project.project', 'root.bundle')); - promises.push(loader.loadFromBundle('project.project', 'zombie.bundle')); promises.push(loader.loadFromBundle('project.project', 'Point.bundle')); + promises.push(loader.loadFromBundle('project.project', 'zombie.bundle')); + //promises.push(loader2.loadFromBundle('project.project', 'zombie.bundle')); + //promises.push(loader3.loadFromBundle('project.project', 'zombie.bundle')); RSVP.all(promises) .then(function(){ initGoobers(goo); @@ -128,17 +133,20 @@ require([ Game.userEntity.setComponent(new FlashlightComponent()); - var zombie = loader.getCachedObjectForRef("zombie_idle/entities/Zombie_Geo_0.entity"); - //zombie.removeFromWorld(); // this breaks the parent child relationship, the parent has the animation that I need... - var z2 = zombie; // EntityUtils.clone(goo.world, zombie); - z2.transformComponent.setTranslation(-2,0,2); - z2.setComponent(new AIComponent(z2)); - z2.aIComponent.addBehavior({name:"Zombie-Idle", update:ZombieIdle}, 0); - z2.aIComponent.addBehavior({name:"Zombie-PathFind", update:ZombiePathFind}, 1); - // z2.addToWorld(); - Game.zombie = zombie; - Game.zombieRoot = zombie.transformComponent.parent.entity; - + function addZombie( loader, x, y, z ) { + var z = loader.getCachedObjectForRef("zombie_idle/entities/Zombie_Geo_0.entity"); + //zombie.removeFromWorld(); EntityUtils.clone(goo.world, zombie); // this breaks the parent child relationship, the parent has the animation that I need... + z.transformComponent.setTranslation( x, y, z); + z.setComponent(new AIComponent(z)); + z.aIComponent.addBehavior({name:"Zombie-Idle", update:ZombieIdle}, 0); + z.aIComponent.addBehavior({name:"Zombie-PathFind", update:ZombiePathFind}, 1); + } + // var z3 = EntityUtils.clone(goo.world, zombie.transformComponent.parent.entity); z3.addToWorld(); // shares animation... this sucks... + + addZombie( loader, 7, 0, -50); + //addZombie( loader2, 50, 0, -50); + //addZombie( loader3, -50, 0, -50); + //console.log(navRef); goo.renderer.domElement.id = 'goo'; @@ -179,7 +187,7 @@ require([ (v1.x * v2.y) - (v1.y * v2.x)); c.normalize(); var dp = (this.pickRay.direction.x*c.x)+(this.pickRay.direction.y*c.y)+(this.pickRay.direction.z*c.z); - console.log(dp); + //console.log(dp); // if(dp >= 0){ if(result[i].intersection.distances[j] < distance){ distance = result[i].intersection.distances[j]; @@ -376,7 +384,7 @@ require([ node.doorPos = navMesh.room[entity.room].door[node.curNode.door].center; entity.aIComponent.setActiveByName("Zombie-Idle", false); node.state = 1; - var eac = Game.zombieRoot.animationComponent; + var eac = entity.transformComponent.parent.entity.animationComponent; eac.transitionTo( eac.getStates()[1]); } } diff --git a/lib/FPSCamComponent.js b/lib/FPSCamComponent.js index 2e235a5..6ad39d7 100644 --- a/lib/FPSCamComponent.js +++ b/lib/FPSCamComponent.js @@ -29,7 +29,7 @@ define([ var entityTransform; var cam; var camTransform; - var speed = 5; + var speed = 10; var tmpVec = new Vector3(); var fwdBase = new Vector3(0,0,-1); var leftBase = new Vector3(-1,0,0); @@ -52,7 +52,7 @@ define([ this.type = "FPSCamComponent"; //entity = entityRef; entityTransform = Game.userEntity.transformComponent.transform; - cam = EntityUtils.createTypicalEntity(Game.goo.world, new Camera(45, 1.0, 0.01, 100)); + cam = EntityUtils.createTypicalEntity(Game.goo.world, new Camera(45, 1.0, 0.01, 130)); Game.viewCam = cam; camTransform = cam.transformComponent.transform; cam.addToWorld(); diff --git a/lib/ShotgunComponent.js b/lib/ShotgunComponent.js index 652e0b4..e720df9 100644 --- a/lib/ShotgunComponent.js +++ b/lib/ShotgunComponent.js @@ -102,7 +102,7 @@ define([ if( entity.dmg && entity.dmg > 100) { eac.layers[0]._steadyStates['mixamo_com__']._sourceTree._clipInstance._loopCount=1; eac.transitionTo( eac.getStates()[3]); // idle, injured_walk, uppercut_jab, dying - Game.zombie.aIComponent.setActiveByName("Zombie-PathFind", false); + entity.aIComponent.setActiveByName("Zombie-PathFind", false); } } @@ -118,6 +118,7 @@ define([ if(true == bool0){ //console.log("bam"); if(document.pointerLockElement) { + console.log( Game.userEntity.transformComponent.transform.translation.data ); sound.play(); shotgun.transformComponent.setRotation( 0.35, 0.1, 0); setTimeout( resetSSG, 250);