Skip to content

Commit

Permalink
Fixed the pathing bug I created by moving script to Zombie.js
Browse files Browse the repository at this point in the history
  • Loading branch information
BunZaga committed Nov 28, 2013
1 parent 3b2aaec commit a71c879
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions js/loadScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,13 @@ require([
var z1 = Zombie.getRef();
z1.transformComponent.setTranslation(4,0,4);
z1.transformComponent.setUpdated();
z1.aIComponent.getBehaviorByName("Idle").state = 0;
z1.skip = false;

var z2 = Zombie.getRef();
z2.transformComponent.setTranslation(-4,0,-4);
z2.transformComponent.setUpdated();
z2.aIComponent.getBehaviorByName("Idle").state = 0;
z2.skip = false;

goo.renderer.setClearColor(0, 0, 0, 1);
Expand Down
17 changes: 10 additions & 7 deletions lib/Zombie.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ define([
Zombie.getRef = function(){
if(zRef.length > 0){
var z = zRef.shift();

z.healthComponent.resetHealth();
return z;
}
}
Expand Down Expand Up @@ -71,7 +71,7 @@ define([
z.setComponent(new AIComponent(z));
z.setComponent(new HealthComponent(z, health));
z.aIComponent.addBehavior({name:"Death", update:Zombie.Death, blocking:true, active:false}, 0);
z.aIComponent.addBehavior({name:"Idle", update:Zombie.Idle, blocking:true, active:false}, 10);
z.aIComponent.addBehavior({name:"Idle", update:Zombie.Idle, blocking:true, active:true}, 10);
z.aIComponent.addBehavior({name:"PathFind", update:Zombie.PathFind, blocking:true, active:false}, 20);
z.skip = true;
zRef.push(z);
Expand All @@ -98,10 +98,12 @@ define([
entity.aIComponent.getBehaviorByName("Idle").state = -1;
entity.aIComponent.getBehaviorByName("Idle").active = true;
entity.aIComponent.getBehaviorByName("PathFind").active = false;
entity.healthComponent.resetHealth();
node.state = null;

node.state = -1;
zRef.push(entity);

var z = Zombie.getRef();
z.aIComponent.getBehaviorByName("Idle").active = true;
z.aIComponent.getBehaviorByName("Idle").state = 0;
z.transformComponent.setTranslation((Math.random()*10)-5,0,(Math.random()*10)-5);
z.transformComponent.setUpdated();
Expand Down Expand Up @@ -136,9 +138,10 @@ define([
// if player near...
node.active = false;
entity.aIComponent.getBehaviorByName("PathFind").active = true;
console.log("pathfinding");
break;
default:
node.state = 0;
node.state = -1;
break;
}
};
Expand Down Expand Up @@ -228,7 +231,7 @@ define([
break;
case 2:
if(entity.transformComponent.transform.translation.distance(Game.userEntity.transformComponent.transform.translation) <= 1.0){
console.log("at player position...");
//console.log("at player position...");
node.state = 3;
}

Expand All @@ -242,7 +245,7 @@ define([
entity.transformComponent.setUpdated();
break;
case 3:
entity.aIComponent.setActiveByName("Zombie-Idle", true);
entity.aIComponent.getBehaviorByName("Idle").active = true;
break;
case 4:
node.goalRoom = Game.userEntity.room;
Expand Down

0 comments on commit a71c879

Please sign in to comment.