aboutsummaryrefslogtreecommitdiffstats
path: root/src/Player.ts
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-06-02 08:54:02 +0200
committerMaksymilian Jopek <maks@jopek.eu>2022-06-02 08:54:02 +0200
commit6c37585ef4ef2535aff8c45c64850be0a6c26eab (patch)
treec53e07505182735fbd23687a0c731d4bb2f10e14 /src/Player.ts
parent7a494b148dd03d6346a63641fc479015e7450a26 (diff)
download1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.tar.gz
1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.tar.zst
1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.zip
Death animations
Diffstat (limited to 'src/Player.ts')
-rw-r--r--src/Player.ts11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/Player.ts b/src/Player.ts
index eb76fbe..f79211f 100644
--- a/src/Player.ts
+++ b/src/Player.ts
@@ -1,9 +1,8 @@
-import Anime from "./Animation";
import Bullet from "./drawables/Bullet";
import { BULLET_VEL, canvas, ctx, FIRE_DELAY, PLAYER_VEL } from "./consts";
import Drawable, { Rectangle } from "./Drawable";
import { keys } from "./Events";
-import { IMGS } from "./Images";
+import { getPlayerDeathAnim, IMGS } from "./Images";
export default class Player extends Drawable {
static startx = 175;
@@ -19,8 +18,8 @@ export default class Player extends Drawable {
// squares: Rectangle[] = [new Rectangle(this)]
squares: Rectangle[] = []
- lifes = 3;
power = 2;
+ alive = true;
constructor() {
super(Player.startx, Player.starty)
@@ -30,10 +29,11 @@ export default class Player extends Drawable {
if (!keys.fire || keys.repeat) return;
if (Date.now() - this.lastShoot < FIRE_DELAY) return;
this.lastShoot = Date.now()
- bullet.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y - Bullet.height, 0, -BULLET_VEL, true))
+ bullet.push(new Bullet(this.x + 2, this.y + 7, 0, -BULLET_VEL, true, this.power))
}
move() {
+ if (!this.alive) return false
if (+keys.right ^ +keys.left) {
keys.right ? this.xvel = PLAYER_VEL : this.xvel = -PLAYER_VEL;
} else {
@@ -62,6 +62,7 @@ export default class Player extends Drawable {
return true;
}
draw() {
+ if (!this.alive) return
this.sprite = this.sprite ?? IMGS.playerUp;
try {
ctx.drawImage(this.sprite, this.x, this.y)
@@ -70,5 +71,5 @@ export default class Player extends Drawable {
}
}
- get deathAnimation() { return new Anime(this, ["red", "green", "blue"]) }
+ deathAnimation = getPlayerDeathAnim(this)
}