Player.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. var animationController = node.getComponent("AnimationController");
  8. var soundSource = node.getComponent("SoundSource3D");
  9. animationController.playExclusive("Walk", 0, true);
  10. animationController.setTime("Walk", Math.random() * 2);
  11. self.start = function() {
  12. }
  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. node.translate([0, 0, -MODEL_MOVE_SPEED * timeStep]);
  21. var pos = node.position;
  22. if (pos[0] < -20 || pos[0] > 20 || pos[2] < -20 || pos[2] > 20)
  23. node.yaw(MODEL_ROTATE_SPEED * timeStep);
  24. }
  25. }
  26. exports.component = component;