aboutsummaryrefslogtreecommitdiffstats
path: root/src/enemies
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/enemies
parent7a494b148dd03d6346a63641fc479015e7450a26 (diff)
download1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.tar.gz
1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.tar.zst
1942-6c37585ef4ef2535aff8c45c64850be0a6c26eab.zip
Death animations
Diffstat (limited to 'src/enemies')
-rw-r--r--src/enemies/BigCircle.ts20
-rw-r--r--src/enemies/Enemy.ts9
-rw-r--r--src/enemies/Green1.ts18
-rw-r--r--src/enemies/Green2.ts17
-rw-r--r--src/enemies/Red1.ts6
-rw-r--r--src/enemies/Red2.ts8
-rw-r--r--src/enemies/Straight.ts17
-rw-r--r--src/enemies/Strange.ts21
-rw-r--r--src/enemies/White.ts9
9 files changed, 107 insertions, 18 deletions
diff --git a/src/enemies/BigCircle.ts b/src/enemies/BigCircle.ts
index 5525b13..1f9f7dd 100644
--- a/src/enemies/BigCircle.ts
+++ b/src/enemies/BigCircle.ts
@@ -1,7 +1,9 @@
import { canvas } from "../consts";
import { Rectangle } from "../Drawable";
+import Bullet from "../drawables/Bullet";
+import { random } from "../helpers";
// import { keys } from "../Events";
-import { IMGS } from "../Images";
+import { getBigDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class BigCircle extends Enemy {
@@ -232,6 +234,21 @@ export default class BigCircle extends Enemy {
return this.x2 < 0 || this.y2 < 0 || this.x > canvas.width || this.y > canvas.height
}
+ hasShooted0 = false
+ hasShooted32 = false
+ shoot(bullets: Bullet[]): boolean {
+ if (this.phase !== 0 && this.phase !== 32) return false
+ if (this.phase === 0 && this.hasShooted0) return false
+ if (this.phase === 32 && this.hasShooted32) return false
+ if (random(0.05)) {
+ if (super.shoot(bullets))
+ //@ts-expect-error
+ this["hasShooted" + this.phase] = true
+ }
+ return true;
+ // (new Bullet(this.width / 2, this.y2, 0, 2, false))
+ }
+
readonly allSqaures = {
bigCircleDown: [new Rectangle(this, 14, 0, 20, 8), new Rectangle(this, 20, 0, 8, 40), new Rectangle(this, 0, 22, 48, 12)],
bigCircleDownToRight1: [new Rectangle(this, 4, 0, 14, 16), new Rectangle(this, 14, 10, 24, 20), new Rectangle(this, 0, 20, 24, 20)],
@@ -251,5 +268,6 @@ export default class BigCircle extends Enemy {
bigCircleLeftToDown3: [new Rectangle(this, 20, 2, 14, 10), new Rectangle(this, 18, 12, 8, 26), new Rectangle(this, 26, 24, 12, 14), new Rectangle(this, 0, 12, 14, 12), new Rectangle(this, 14, 24, 4, 14), new Rectangle(this, 4, 24, 10, 6), new Rectangle(this, 12, 14, 8, 14)],
};
+ deathAnim = getBigDeathAnim(this)
}
diff --git a/src/enemies/Enemy.ts b/src/enemies/Enemy.ts
index d85b11e..224e66c 100644
--- a/src/enemies/Enemy.ts
+++ b/src/enemies/Enemy.ts
@@ -1,14 +1,17 @@
import Bullet from "../drawables/Bullet";
-import { BULLET_VEL } from "../consts";
+import { BULLET_VEL, TOPBAR_HEIGHT } from "../consts";
import Drawable, { Rectangle } from "../Drawable";
+import Anime from "../Animation";
export default abstract class Enemy extends Drawable {
squares: Array<Rectangle> = [new Rectangle(this)]
points = 5;
health = 2
- deathAnim: (string | HTMLImageElement)[] = ["red"]
+ deathAnim!: Anime;
- shoot(bullet: Bullet[]) {
+ shoot(bullet: Bullet[]): boolean {
+ if (this.y2 < TOPBAR_HEIGHT) return false
bullet.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, 0, BULLET_VEL, false))
+ return true
}
}
diff --git a/src/enemies/Green1.ts b/src/enemies/Green1.ts
index 034ab15..2510f97 100644
--- a/src/enemies/Green1.ts
+++ b/src/enemies/Green1.ts
@@ -1,5 +1,7 @@
import { Rectangle } from "../Drawable";
-import { IMGS } from "../Images";
+import Bullet from "../drawables/Bullet";
+import { random } from "../helpers";
+import { getSmallDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class Green1 extends Enemy {
@@ -53,7 +55,19 @@ export default class Green1 extends Enemy {
this.y += dy;
this.width = this.sprite.width
this.height = this.sprite.height
- this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ this.squares = [new Rectangle(this, 2, 2, this.width - 4, this.height - 4)]
return this.isOutsideMap()
}
+
+ hasShooted = false;
+ shoot(bullets: Bullet[]): boolean {
+ if (this.sprite !== IMGS.greenDown || this.hasShooted) return false;
+ if (random(0.008)) {
+ if (super.shoot(bullets))
+ this.hasShooted = true
+ }
+ return true;
+ }
+
+ deathAnim = getSmallDeathAnim(this)
}
diff --git a/src/enemies/Green2.ts b/src/enemies/Green2.ts
index b4d9ddc..a6adb74 100644
--- a/src/enemies/Green2.ts
+++ b/src/enemies/Green2.ts
@@ -1,5 +1,7 @@
import { Rectangle } from "../Drawable";
-import { IMGS } from "../Images";
+import Bullet from "../drawables/Bullet";
+import { random } from "../helpers";
+import { getSmallDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class Green2 extends Enemy {
@@ -107,7 +109,18 @@ export default class Green2 extends Enemy {
this.y += dy;
this.width = this.sprite.width
this.height = this.sprite.height
- this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ this.squares = [new Rectangle(this, 2, 2, this.width - 4, this.height - 4)]
return this.isOutsideMap()
}
+
+ hasShooted = false;
+ shoot(bullets: Bullet[]): boolean {
+ if (this.sprite !== IMGS.greenDown || this.hasShooted) return false;
+ if (random(0.008)) {
+ if (super.shoot(bullets))
+ this.hasShooted = true
+ }
+ return true;
+ }
+ deathAnim = getSmallDeathAnim(this)
}
diff --git a/src/enemies/Red1.ts b/src/enemies/Red1.ts
index 67a8729..9c50820 100644
--- a/src/enemies/Red1.ts
+++ b/src/enemies/Red1.ts
@@ -1,5 +1,5 @@
import { Rectangle } from "../Drawable";
-import { IMGS } from "../Images";
+import { getSmallDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class Red1 extends Enemy {
@@ -187,7 +187,9 @@ export default class Red1 extends Enemy {
this.y += dy;
this.width = this.sprite.width
this.height = this.sprite.height
- this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ this.squares = [new Rectangle(this, 2, 2, this.width - 4, this.height - 4)]
return this.isOutsideMap()
}
+ shoot(): boolean { return false }
+ deathAnim = getSmallDeathAnim(this)
}
diff --git a/src/enemies/Red2.ts b/src/enemies/Red2.ts
index 6cfa672..ced55cd 100644
--- a/src/enemies/Red2.ts
+++ b/src/enemies/Red2.ts
@@ -1,5 +1,5 @@
import { Rectangle } from "../Drawable";
-import { IMGS } from "../Images";
+import { getSmallDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class Red2 extends Enemy {
@@ -96,7 +96,6 @@ export default class Red2 extends Enemy {
break;
case 16:
dy = this.vel
- console.log(this.x);
break;
default:
@@ -107,8 +106,11 @@ export default class Red2 extends Enemy {
this.y += dy;
this.width = this.sprite.width
this.height = this.sprite.height
- this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ this.squares = [new Rectangle(this, 2, 2, this.width - 4, this.height - 4)]
return this.isOutsideMap() && this.phase > 12
}
+ shoot(): boolean { return false }
+
+ deathAnim = getSmallDeathAnim(this)
}
diff --git a/src/enemies/Straight.ts b/src/enemies/Straight.ts
index 895ec01..7bc82f9 100644
--- a/src/enemies/Straight.ts
+++ b/src/enemies/Straight.ts
@@ -1,6 +1,8 @@
import { canvas } from "../consts";
import { Rectangle } from "../Drawable";
-import { IMGS } from "../Images";
+import Bullet from "../drawables/Bullet";
+import { random } from "../helpers";
+import { getSmallDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class Straight extends Enemy {
@@ -36,4 +38,17 @@ export default class Straight extends Enemy {
this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
return this.y + this.height < 0
}
+
+ hasShooted = false
+ shoot(bullets: Bullet[]): boolean {
+ if (this.hasShooted || this.phase !== 0) return false
+ if (random(0.008)) {
+ if (super.shoot(bullets))
+ this.hasShooted = true
+ }
+ return true;
+ // (new Bullet(this.width / 2, this.y2, 0, 2, false))
+ }
+
+ deathAnim = getSmallDeathAnim(this)
}
diff --git a/src/enemies/Strange.ts b/src/enemies/Strange.ts
index 69fd9c0..036409a 100644
--- a/src/enemies/Strange.ts
+++ b/src/enemies/Strange.ts
@@ -1,5 +1,8 @@
+import { BULLET_VEL, TOPBAR_HEIGHT } from "../consts";
import { Rectangle } from "../Drawable";
-import { IMGS } from "../Images";
+import Bullet from "../drawables/Bullet";
+import { random } from "../helpers";
+import { getBigDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class Strange extends Enemy {
@@ -88,5 +91,21 @@ export default class Strange extends Enemy {
// this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
return this.isOutsideMap()
}
+
+ shoot(bullets: Bullet[]): boolean {
+ if (this.y2 < TOPBAR_HEIGHT) return false
+ if (random(0.01)) {
+ if (random(0.5)) {
+ bullets.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, 0, BULLET_VEL, false))
+ } else {
+ if (random(0.5)) bullets.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, BULLET_VEL - 1, BULLET_VEL - 1, false))
+ else bullets.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, -BULLET_VEL + 1, BULLET_VEL - 1, false))
+ }
+
+ }
+ return true
+ }
+
+ deathAnim = getBigDeathAnim(this)
}
diff --git a/src/enemies/White.ts b/src/enemies/White.ts
index 2987985..e5b22ae 100644
--- a/src/enemies/White.ts
+++ b/src/enemies/White.ts
@@ -1,5 +1,5 @@
import { Rectangle } from "../Drawable";
-import { IMGS } from "../Images";
+import { getSmallDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
export default class White extends Enemy {
@@ -11,7 +11,7 @@ export default class White extends Enemy {
phase = 0;
spriteNum = 1;
i = 0;
- squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ squares: Rectangle[] = [new Rectangle(this)]
constructor(x: number, y: number, public left: boolean) {
super(x, y)
@@ -61,8 +61,11 @@ export default class White extends Enemy {
this.y += dy;
this.width = this.sprite.width
this.height = this.sprite.height
- this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ this.squares = [new Rectangle(this)]
return this.isOutsideMap()
}
+
+ shoot(): boolean { return false }
+ deathAnim = getSmallDeathAnim(this)
}