unibutton/js/player.js

30 lines
612 B
JavaScript
Raw Normal View History

2024-09-27 21:42:21 -04:00
function Player() {
2024-09-27 22:05:46 -04:00
let pos = { x: Math.random() * 5000 - 50, y: Math.random() * 5000 - 50 };
2024-09-27 21:42:21 -04:00
let camera = { x: -pos.x, y: -pos.y };
let vel = { x: 0, y: 0 };
this.camera = camera;
this.pos = pos;
this.vel = vel;
this.rot = 0;
this.dir = 1;
2024-09-27 22:05:46 -04:00
this.ticks = 0;
2024-09-27 22:21:01 -04:00
this.health = 100;
2024-09-27 22:05:46 -04:00
}
Player.prototype.bump = function () {
let player = this;
if (player.ticks < 10) {
player.dir *= -1;
}
2024-09-27 22:21:01 -04:00
player.vel.x *= 0.9;
player.vel.y *= 0.9;
2024-09-27 22:05:46 -04:00
2024-09-27 22:21:01 -04:00
player.vel.x += Math.sin(player.rot) * 8;
player.vel.y -= Math.cos(player.rot) * 8;
2024-09-27 22:05:46 -04:00
player.ticks = 0;
2024-09-27 21:42:21 -04:00
}