Player.js 1018 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "atomic component";
  2. var MODEL_MOVE_SPEED = .75;
  3. var MODEL_ROTATE_SPEED = 100.0;
  4. var component = function(self) {
  5. var node = self.node;
  6. var cluckDelta = Math.random() * 30;
  7. //Get components
  8. var animationController = node.getComponent("AnimationController");
  9. var soundSource = node.getComponent("SoundSource3D");
  10. //play Walk animation
  11. animationController.playExclusive("Walk", 0, true);
  12. animationController.setTime("Walk", Math.random() * 2);
  13. self.update = function(timeStep) {
  14. if (cluckDelta > 0.0) {
  15. cluckDelta -= timeStep;
  16. } else {
  17. soundSource.play(soundSource.sound);
  18. cluckDelta = Math.random() * 30 + 2;
  19. }
  20. //translate position of node
  21. node.translate([0, 0, -MODEL_MOVE_SPEED * timeStep]);
  22. var pos = node.position;
  23. if (pos[0] < -20 || pos[0] > 20 || pos[2] < -20 || pos[2] > 20)
  24. node.yaw(MODEL_ROTATE_SPEED * timeStep);
  25. };
  26. };
  27. exports.component = component;