humancontroller.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. function HumanController() {
  2. this.keyboard = null;
  3. this.init = function() {
  4. this.keyboard = new KeyboardInput();
  5. this.keyboard.attach();
  6. };
  7. this.reset = function(ship) {
  8. };
  9. this.makeDecisions = function(ship) {
  10. if(this.keyboard.isDown(Keys.Up) || this.keyboard.isDown(Keys.W)) {
  11. ship.accelerate();
  12. }
  13. if(this.keyboard.isReleased(Keys.Up)) {
  14. ship.idle();
  15. }
  16. if(this.keyboard.isReleased(Keys.W)) {
  17. ship.idle();
  18. }
  19. if(this.keyboard.isPressed(Keys.Down) || this.keyboard.isPressed(Keys.S)) {
  20. ship.shoot();
  21. }
  22. if(this.keyboard.isDown(Keys.Left)|| this.keyboard.isDown(Keys.A)) {
  23. ship.turnLeft();
  24. }
  25. if(this.keyboard.isDown(Keys.Right)|| this.keyboard.isDown(Keys.D)) {
  26. ship.turnRight();
  27. }
  28. if(this.keyboard.isPressed(Keys.Space)) {
  29. ship.shoot();
  30. }
  31. };
  32. this.getColor = function() {
  33. return "#DD3333";
  34. }
  35. this.mouseSteer = function(ship, camera, x, y) {
  36. if(ship.touching == null) {
  37. var angleRadians = Math.atan2(y - (ship.position.y + camera.y), x - (ship.position.x + camera.x));
  38. ship.targetAngle = angleRadians;
  39. }
  40. }
  41. this.debugDraw = function(ship, context) {
  42. };
  43. };