You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
zomburger/public/player.js

51 lines
1.1 KiB
JavaScript

class Player {
constructor(options) {
options = options || {};
5 years ago
this.game = options.game;
this.id = options.id;
this.image = random(Images.players);
this.width = options.width;
this.height = options.height;
5 years ago
this.burgers = 5;
let sprite = createSprite(options.x, options.y, options.width, options.height);
sprite.addImage(this.image);
sprite.setCollider("rectangle", 0, 0, options.width, options.height);
sprite.scale = 1;
sprite.mass = 1;
this.sprite = sprite;
this.joyX = 0;
this.joyY = 0;
}
update() {
this.sprite.velocity.x = this.joyX * 10;
this.sprite.velocity.y = this.joyY * -10;
}
draw() {
tint(Colors.Purple);
image(this.image, this.sprite.position.x, this.sprite.position.y, 64, 64);
5 years ago
strokeWeight(4);
stroke('#FF0000');
point(this.sprite.position.x, this.sprite.position.y);
}
joystickInput(x, y) {
this.joyX = x;
this.joyY = y;
}
5 years ago
buttonInput(val) {
console.log(["player sees button input val", val]);
if (val) {
if (this.burgers > 0) {
this.burgers--;
this.game.addBurger(this.id);
} else {
}
}
}
}