aboutsummaryrefslogtreecommitdiffstats
path: root/src/enemies
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2022-06-02 23:13:07 +0200
committerMaksymilian Jopek <maks@jopek.eu>2022-06-02 23:16:33 +0200
commitb4defa324a330217f0139f1240bcf53c0b1f996a (patch)
treedeabb94fd351b10d3d6b38d967424149536b3927 /src/enemies
parentef76266d1a61c02f1721efedc830fab12279d2b9 (diff)
download1942-b4defa324a330217f0139f1240bcf53c0b1f996a.tar.gz
1942-b4defa324a330217f0139f1240bcf53c0b1f996a.tar.zst
1942-b4defa324a330217f0139f1240bcf53c0b1f996a.zip
v1.0.0
Diffstat (limited to 'src/enemies')
-rw-r--r--src/enemies/BigCircle.ts22
-rw-r--r--src/enemies/Enemy.ts7
-rw-r--r--src/enemies/Green1.ts2
-rw-r--r--src/enemies/Green2.ts2
-rw-r--r--src/enemies/Red1.ts4
-rw-r--r--src/enemies/Red2.ts4
-rw-r--r--src/enemies/Straight.ts14
-rw-r--r--src/enemies/Strange.ts30
-rw-r--r--src/enemies/White.ts14
9 files changed, 83 insertions, 16 deletions
diff --git a/src/enemies/BigCircle.ts b/src/enemies/BigCircle.ts
index 1f9f7dd..b7666f5 100644
--- a/src/enemies/BigCircle.ts
+++ b/src/enemies/BigCircle.ts
@@ -11,8 +11,11 @@ export default class BigCircle extends Enemy {
height = 40
sprite: HTMLImageElement | string = IMGS.bigCircleDown;
strSprite = "bigCircleDown"
+ si = 0;
+ changeSprite = true;
vel = 2
- health = 20
+ health = 30
+ points = 1100
phase = 0;
@@ -229,6 +232,23 @@ export default class BigCircle extends Enemy {
break;
}
+ if (this.health < 30 - 20) {
+ if (this.si++ > 3) { this.changeSprite = !this.changeSprite; this.si = 0; }
+ }
+ else if (this.health < 30 - 10) {
+ if (this.si++ > 8) { this.changeSprite = !this.changeSprite; this.si = 0; }
+ }
+ else if (this.health < 30) {
+ if (this.si++ > 30) { this.changeSprite = !this.changeSprite; this.si = 0; }
+ }
+ if (this.changeSprite === true && this.health < 30)
+ //@ts-expect-error
+ this.sprite = IMGS[this.strSprite + "Red"]
+ else
+ //@ts-expect-error
+ this.sprite = IMGS[this.strSprite]
+
+
this.x += xShift;
this.y += yShift;
return this.x2 < 0 || this.y2 < 0 || this.x > canvas.width || this.y > canvas.height
diff --git a/src/enemies/Enemy.ts b/src/enemies/Enemy.ts
index 224e66c..cebc1d2 100644
--- a/src/enemies/Enemy.ts
+++ b/src/enemies/Enemy.ts
@@ -5,13 +5,16 @@ import Anime from "../Animation";
export default abstract class Enemy extends Drawable {
squares: Array<Rectangle> = [new Rectangle(this)]
- points = 5;
+ points = 50;
health = 2
deathAnim!: Anime;
+ constructor(x: number, y: number) {
+ super(x, y)
+ }
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))
+ bullet.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, 0, BULLET_VEL / 1.5, false))
return true
}
}
diff --git a/src/enemies/Green1.ts b/src/enemies/Green1.ts
index 2510f97..42ff712 100644
--- a/src/enemies/Green1.ts
+++ b/src/enemies/Green1.ts
@@ -8,7 +8,7 @@ export default class Green1 extends Enemy {
sprite = IMGS.greenUp;
width = IMGS.greenUp.width;
height = IMGS.greenUp.height;
- vel = 2
+ vel = 2.5
phase = 0;
spriteNum = 1;
i = 0;
diff --git a/src/enemies/Green2.ts b/src/enemies/Green2.ts
index a6adb74..1987499 100644
--- a/src/enemies/Green2.ts
+++ b/src/enemies/Green2.ts
@@ -16,6 +16,8 @@ export default class Green2 extends Enemy {
constructor(x: number, y: number, public left: boolean) {
super(x, y)
+ this.height = IMGS.greenDown.height;
+ this._y = y - this.height
}
move() {
diff --git a/src/enemies/Red1.ts b/src/enemies/Red1.ts
index 9c50820..18fdb6f 100644
--- a/src/enemies/Red1.ts
+++ b/src/enemies/Red1.ts
@@ -6,7 +6,7 @@ export default class Red1 extends Enemy {
sprite = IMGS.redRight;
width = IMGS.redRight.width;
height = IMGS.redRight.height;
- vel = 3
+ vel = 3.5
phase = 0;
spriteNum = 1;
i = 0;
@@ -190,6 +190,6 @@ export default class Red1 extends Enemy {
this.squares = [new Rectangle(this, 2, 2, this.width - 4, this.height - 4)]
return this.isOutsideMap()
}
- shoot(): boolean { return false }
+ shoot() { return false }
deathAnim = getSmallDeathAnim(this)
}
diff --git a/src/enemies/Red2.ts b/src/enemies/Red2.ts
index ced55cd..de79845 100644
--- a/src/enemies/Red2.ts
+++ b/src/enemies/Red2.ts
@@ -6,13 +6,15 @@ export default class Red2 extends Enemy {
sprite = IMGS.redDown;
width = IMGS.redDown.width;
height = IMGS.redDown.height;
- vel = 2;
+ vel = 2.5;
phase = 0;
i = 0;
squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
constructor(x: number, y: number, public left: boolean) {
super(x, y)
+ this.height = IMGS.redDown.height;
+ this._y = y - this.height
}
move() {
diff --git a/src/enemies/Straight.ts b/src/enemies/Straight.ts
index 7bc82f9..f57d6f3 100644
--- a/src/enemies/Straight.ts
+++ b/src/enemies/Straight.ts
@@ -9,11 +9,19 @@ export default class Straight extends Enemy {
sprite = IMGS.simpleDown;
width = IMGS.simpleDown.width;
height = IMGS.simpleDown.height;
- vel = 2
+ vel = 2.5
phase = 0;
spriteNum = 1;
i = 0;
- squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 4, this.height - 4)]
+ drop = false
+
+ constructor(x: number, y: number, drop?: boolean) {
+ super(x, y)
+ if (drop) this.drop = drop
+ this.height = IMGS.simpleDown.height;
+ this._y = y - this.height
+ }
move() {
let dy = 0;
@@ -35,7 +43,7 @@ export default class Straight 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.y + this.height < 0
}
diff --git a/src/enemies/Strange.ts b/src/enemies/Strange.ts
index 036409a..d130326 100644
--- a/src/enemies/Strange.ts
+++ b/src/enemies/Strange.ts
@@ -12,9 +12,13 @@ export default class Strange extends Enemy {
vel = 1
phase = 0;
spriteCounter = 0;
+ si = 0;
+ changeSprite = true;
spriteNum = 1;
i = 0;
squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
+ health = 30
+ points = 2100
move() {
let dx = 0, dy = 0;
@@ -82,10 +86,26 @@ export default class Strange extends Enemy {
break;
}
+ if (this.spriteCounter++ === 3) { this.spriteNum ^= 1; this.spriteCounter = 0; }
+ let strSprite = "bigStrangeUp" + this.spriteNum;
+ if (this.health < 30 - 20) {
+ if (this.si++ > 3) { this.changeSprite = !this.changeSprite; this.si = 0; }
+ }
+ else if (this.health < 30 - 10) {
+ if (this.si++ > 8) { this.changeSprite = !this.changeSprite; this.si = 0; }
+ }
+ else if (this.health < 30) {
+ if (this.si++ > 30) { this.changeSprite = !this.changeSprite; this.si = 0; }
+ }
+ if (this.changeSprite === true && this.health < 30)
+ //@ts-expect-error
+ this.sprite = IMGS[strSprite + "Red"]
+ else
+ //@ts-expect-error
+ this.sprite = IMGS[strSprite]
+
this.x += dx;
this.y += dy;
- //@ts-expect-error
- if (this.spriteCounter++ === 3) { this.spriteNum ^= 1; this.sprite = IMGS["bigStrangeUp" + this.spriteNum]; this.spriteCounter = 0; }
// this.width = this.sprite.width
// this.height = this.sprite.height
// this.squares = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)]
@@ -96,10 +116,10 @@ export default class Strange extends Enemy {
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))
+ bullets.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, 0, BULLET_VEL / 2, 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))
+ if (random(0.5)) bullets.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, BULLET_VEL / 2, BULLET_VEL / 2, false))
+ else bullets.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, -BULLET_VEL / 2, BULLET_VEL / 2, false))
}
}
diff --git a/src/enemies/White.ts b/src/enemies/White.ts
index e5b22ae..768300d 100644
--- a/src/enemies/White.ts
+++ b/src/enemies/White.ts
@@ -1,4 +1,6 @@
import { Rectangle } from "../Drawable";
+import Bullet from "../drawables/Bullet";
+import { random } from "../helpers";
import { getSmallDeathAnim, IMGS } from "../Images";
import Enemy from "./Enemy";
@@ -15,6 +17,8 @@ export default class White extends Enemy {
constructor(x: number, y: number, public left: boolean) {
super(x, y)
+ this.height = IMGS.whiteDown.height;
+ this._y = y - this.height
}
move() {
@@ -65,7 +69,15 @@ export default class White extends Enemy {
return this.isOutsideMap()
}
- shoot(): boolean { return false }
+ hasShooted = false;
+ shoot(bullets: Bullet[]): boolean {
+ if (this.sprite !== IMGS.whiteDown || this.hasShooted) return false;
+ if (random(0.008)) {
+ if (super.shoot(bullets))
+ this.hasShooted = true
+ }
+ return true;
+ }
deathAnim = getSmallDeathAnim(this)
}