123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- function HumanController() {
- this.keyboard = null;
- this.init = function() {
- this.keyboard = new KeyboardInput();
- this.keyboard.attach();
- };
- this.reset = function(ship) {
- };
- this.makeDecisions = function(ship) {
- if(this.keyboard.isDown(Keys.Up) || this.keyboard.isDown(Keys.W)) {
- ship.accelerate();
- }
- if(this.keyboard.isReleased(Keys.Up)) {
- ship.idle();
- }
- if(this.keyboard.isReleased(Keys.W)) {
- ship.idle();
- }
- if(this.keyboard.isPressed(Keys.Down) || this.keyboard.isPressed(Keys.S)) {
- ship.shoot();
- }
- if(this.keyboard.isDown(Keys.Left)|| this.keyboard.isDown(Keys.A)) {
- ship.turnLeft();
- }
- if(this.keyboard.isDown(Keys.Right)|| this.keyboard.isDown(Keys.D)) {
- ship.turnRight();
- }
- if(this.keyboard.isPressed(Keys.Space)) {
- ship.shoot();
- }
- };
- this.getColor = function() {
- return "#DD3333";
- }
- this.mouseSteer = function(ship, camera, x, y) {
- if(ship.touching == null) {
- var angleRadians = Math.atan2(y - (ship.position.y + camera.y), x - (ship.position.x + camera.x));
- ship.targetAngle = angleRadians;
- }
- }
- this.debugDraw = function(ship, context) {
-
- };
- };
|