minor refactoring
This commit is contained in:
parent
e255982fef
commit
8cb80b9cbe
3 changed files with 48 additions and 38 deletions
36
js/index.js
36
js/index.js
|
@ -13,7 +13,7 @@ function Game() {
|
|||
}
|
||||
|
||||
let canvas = document.querySelector("#canvas");
|
||||
let player = new Player();
|
||||
let player = new Player(true);
|
||||
let entities = [player];
|
||||
|
||||
for (let i = 0; i < 50; i++) {
|
||||
|
@ -30,7 +30,6 @@ function Game() {
|
|||
}
|
||||
|
||||
Game.prototype.main = function () {
|
||||
|
||||
let { entities, player } = this;
|
||||
|
||||
if (player.health <= 0) {
|
||||
|
@ -38,38 +37,7 @@ Game.prototype.main = function () {
|
|||
}
|
||||
|
||||
for (let ent of entities) {
|
||||
ent.pos.x += ent.vel.x;
|
||||
ent.pos.y += ent.vel.y;
|
||||
|
||||
ent.vel.x *= 0.9;
|
||||
ent.vel.y *= 0.9;
|
||||
|
||||
ent.rot += 0.03 * ent.dir;
|
||||
ent.rot = ent.rot % (Math.PI * 10);
|
||||
|
||||
ent.camera.x = -ent.pos.x * 0.1 + ent.camera.x * 0.9;
|
||||
ent.camera.y = -ent.pos.y * 0.1 + ent.camera.y * 0.9;
|
||||
|
||||
ent.ticks++;
|
||||
|
||||
let dist = ((ent.pos.x - player.pos.x) ** 2) + ((ent.pos.y - player.pos.y) ** 2);
|
||||
|
||||
let dp = (Math.sin(ent.rot) * (ent.pos.x - player.pos.x))
|
||||
- (Math.cos(ent.rot) * (ent.pos.y - player.pos.y));
|
||||
|
||||
dp /= dist;
|
||||
|
||||
dp *= 10;
|
||||
|
||||
if (ent == player) continue;
|
||||
|
||||
if (Math.random() < -dp && Math.random() > 3 / (ent.ticks+2)) {
|
||||
ent.bump();
|
||||
}
|
||||
|
||||
if (Math.sqrt(dist) < 96 / 2) {
|
||||
player.health --;
|
||||
}
|
||||
ent.handleTick(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue