123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- class HumanController {
- constructor() {
- this.keyboard = null;
- this.player = null;
- this.mousePosition = { x: 0, y: 0 };
- }
- init(systemObject, player) {
- this.system = systemObject;
- this.player = player;
- }
- reset() {
- }
- makeDecisions(player) {
- if (this.system.keyboard.isDown(Keys.Up) || this.system.keyboard.isDown(Keys.W)) {
- this.player.walkUp();
- }
- if (this.system.keyboard.isDown(Keys.Down) || this.system.keyboard.isDown(Keys.S)) {
- this.player.walkDown();
- }
- if (this.system.keyboard.isDown(Keys.Left) || this.system.keyboard.isDown(Keys.A)) {
- this.player.walkLeft();
- }
- if (this.system.keyboard.isDown(Keys.Right) || this.system.keyboard.isDown(Keys.D)) {
- this.player.walkRight();
- }
- if (this.system.keyboard.isPressed(Keys.Space)) {
- this.player.jump();
- }
- }
- mouseMove(camera, x, y) {
- this.mousePosition.x = x - camera.position.x;
- this.mousePosition.y = y - camera.position.y;
- this.player.targetAngle = this.system.angleTo(this.player.position, this.mousePosition);
- }
- mouseDown(camera, button, x, y) {
- this.mousePosition.x = x - camera.position.x;
- this.mousePosition.y = y - camera.position.y;
- this.player.targetAngle = this.system.angleTo(this.player.position, this.mousePosition);
- if (button == 2) {
- this.player.walkTowards(this.mousePosition);
- }
- }
- mouseUp(camera, button, x, y) {
- }
- touchStart(camera, x, y) {
- this.mousePosition.x = x - camera.position.x;
- this.mousePosition.y = y - camera.position.y;
- this.player.targetAngle = this.system.angleTo(this.player.position, this.mousePosition);
- this.player.walkTowards(this.mousePosition);
- }
- touchMove(camera, x, y) {
- this.mousePosition.x = x - camera.position.x;
- this.mousePosition.y = y - camera.position.y;
- this.player.targetAngle = this.system.angleTo(this.player.position, this.mousePosition);
- }
- touchEnd(camera, x, y) {
- }
- contextMenu() {
- }
- debugDraw(context) {
- /*
- context.save();
- context.translate(this.player.position.x, this.player.position.y);
- context.font = "16px sans-serif";
- context.textAlign = "center";
- context.textBaseline = "middle";
- context.fillStyle = "#DDDDDD";
- context.strokeStyle = "#333333";
- context.lineWidth = 2;
- var message = parseInt(this.player.position.x) + ", " + parseInt(this.player.position.y);
- var textMetrics = context.measureText(message);
- var textWidth = textMetrics.width;
- context.fillText(message, 0, 0);
-
- context.restore();
- */
- /*context.strokeStyle = "crimson";
- context.save();
- context.translate(this.mousePosition.x, this.mousePosition.y);
- context.beginPath();
- context.arc(0, 0, 10, 0, 2 * Math.PI);
- context.stroke();
- context.restore(); */
- }
- }
|