diff options
Diffstat (limited to 'src/enemies')
| -rw-r--r-- | src/enemies/BigCircle.ts | 101 | ||||
| -rw-r--r-- | src/enemies/Enemy.ts | 4 | ||||
| -rw-r--r-- | src/enemies/Green1.ts | 59 | ||||
| -rw-r--r-- | src/enemies/Green2.ts | 113 | ||||
| -rw-r--r-- | src/enemies/Red1.ts | 193 | ||||
| -rw-r--r-- | src/enemies/Red2.ts | 114 | ||||
| -rw-r--r-- | src/enemies/Straight.ts | 38 | ||||
| -rw-r--r-- | src/enemies/Strange.ts | 92 | ||||
| -rw-r--r-- | src/enemies/White.ts | 68 |
9 files changed, 744 insertions, 38 deletions
diff --git a/src/enemies/BigCircle.ts b/src/enemies/BigCircle.ts index 233491d..5525b13 100644 --- a/src/enemies/BigCircle.ts +++ b/src/enemies/BigCircle.ts @@ -1,6 +1,6 @@ import { canvas } from "../consts"; import { Rectangle } from "../Drawable"; -import { keys } from "../Events"; +// import { keys } from "../Events"; import { IMGS } from "../Images"; import Enemy from "./Enemy"; @@ -8,7 +8,9 @@ export default class BigCircle extends Enemy { width = 48 height = 40 sprite: HTMLImageElement | string = IMGS.bigCircleDown; + strSprite = "bigCircleDown" vel = 2 + health = 20 phase = 0; @@ -28,8 +30,9 @@ export default class BigCircle extends Enemy { if (this.y2 > 124) this.phase++ break; case 1: - keys.fps = 1 - this.sprite = IMGS.bigCircleDownToRight1; + // keys.fps = 1 + // this.sprite = IMGS.bigCircleDownToRight1; + this.strSprite = "bigCircleDownToRight1" this.squares = this.allSqaures.bigCircleDownToRight1; this.counter = 0; this.phase++; @@ -40,7 +43,8 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 3: - this.sprite = IMGS.bigCircleDownToRight2; + // this.sprite = IMGS.bigCircleDownToRight2; + this.strSprite = "bigCircleDownToRight2"; this.squares = this.allSqaures.bigCircleDownToRight2; this.counter = 0; this.phase++; @@ -51,7 +55,8 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 5: - this.sprite = IMGS.bigCircleDownToRight3; + // this.sprite = IMGS.bigCircleDownToRight3; + this.strSprite = "bigCircleDownToRight3"; this.squares = this.allSqaures.bigCircleDownToRight3; this.counter = 0; this.phase++; @@ -62,18 +67,21 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 7: - this.sprite = IMGS.bigCircleRight; + // this.sprite = IMGS.bigCircleRight; + this.strSprite = "bigCircleRight"; this.squares = this.allSqaures.bigCircleRight; this.phase++; break; case 8: - keys.fps = 50 + // keys.fps = 50 xShift = this.vel; - if(this.x2 > 184) this.phase++; + if (this.x2 > 184) this.phase++; break; case 9: - keys.fps = 1 - this.sprite = IMGS.bigCircleRightToUp1; + // keys.fps = 1 + // this.sprite = IMGS.bigCircleRightToUp1; + this.strSprite = "bigCircleRightToUp1"; + this.squares = this.allSqaures.bigCircleRightToUp1; this.phase++; this.counter = 0; break; @@ -83,7 +91,9 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 11: - this.sprite = IMGS.bigCircleRightToUp2; + // this.sprite = IMGS.bigCircleRightToUp2; + this.strSprite = "bigCircleRightToUp2"; + this.squares = this.allSqaures.bigCircleRightToUp2; this.phase++; this.counter = 0; break; @@ -93,7 +103,9 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 13: - this.sprite = IMGS.bigCircleRightToUp3; + // this.sprite = IMGS.bigCircleRightToUp3; + this.strSprite = "bigCircleRightToUp3"; + this.squares = this.allSqaures.bigCircleRightToUp3; this.phase++; this.counter = 0; break; @@ -103,17 +115,21 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 15: - this.sprite = IMGS.bigCircleUp; + // this.sprite = IMGS.bigCircleUp; + this.strSprite = "bigCircleUp"; + this.squares = this.allSqaures.bigCircleUp; this.phase++; break; case 16: yShift = -this.vel; - if(this.y < 50) this.phase++; + if (this.y < 50) this.phase++; break; - // uptoleft at 77 + 24 + ~8 - // leftToDown at 268 + // uptoleft at 77 + 24 + ~8 + // leftToDown at 268 case 17: - this.sprite = IMGS.bigCircleUpToLeft1; + // this.sprite = IMGS.bigCircleUpToLeft1; + this.strSprite = "bigCircleUpToLeft1"; + this.squares = this.allSqaures.bigCircleUpToLeft1; this.phase++; this.counter = 0; break; @@ -123,7 +139,9 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 19: - this.sprite = IMGS.bigCircleUpToLeft2; + // this.sprite = IMGS.bigCircleUpToLeft2; + this.strSprite = "bigCircleUpToLeft2"; + this.squares = this.allSqaures.bigCircleUpToLeft2; this.phase++; this.counter = 0; break; @@ -133,7 +151,9 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 21: - this.sprite = IMGS.bigCircleUpToLeft3; + // this.sprite = IMGS.bigCircleUpToLeft3; + this.strSprite = "bigCircleUpToLeft3"; + this.squares = this.allSqaures.bigCircleUpToLeft3; this.phase++; this.counter = 0; break; @@ -143,7 +163,9 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 23: - this.sprite = IMGS.bigCircleLeft; + // this.sprite = IMGS.bigCircleLeft; + this.strSprite = "bigCircleLeft"; + this.squares = this.allSqaures.bigCircleLeft; this.phase++; this.counter = 0; break; @@ -152,7 +174,9 @@ export default class BigCircle extends Enemy { if (this.x < 49) this.phase++; break; case 25: - this.sprite = IMGS.bigCircleLeftToDown1; + // this.sprite = IMGS.bigCircleLeftToDown1; + this.strSprite = "bigCircleLeftToDown1"; + this.squares = this.allSqaures.bigCircleLeftToDown1; this.phase++; this.counter = 0; break; @@ -162,7 +186,9 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 27: - this.sprite = IMGS.bigCircleLeftToDown2; + // this.sprite = IMGS.bigCircleLeftToDown2; + this.strSprite = "bigCircleLeftToDown2"; + this.squares = this.allSqaures.bigCircleLeftToDown2; this.phase++; this.counter = 0; break; @@ -172,17 +198,23 @@ export default class BigCircle extends Enemy { if (this.counter++ === 3) this.phase++; break; case 29: - this.sprite = IMGS.bigCircleLeftToDown3; + // this.sprite = IMGS.bigCircleLeftToDown3; + this.strSprite = "bigCircleLeftToDown3"; + this.squares = this.allSqaures.bigCircleLeftToDown3; this.phase++; this.counter = 0; break; case 30: + // debugger xShift = -this.vel yShift = this.vel if (this.counter++ === 3) this.phase++; break; case 31: - this.sprite = IMGS.bigCircleDown; + // this.sprite = IMGS.bigCircleDown; + // TODO: IMPORANT, set sprite by strSprite and get red spites + this.strSprite = "bigCircleDown"; + this.squares = this.allSqaures.bigCircleDown; this.phase++; this.counter = 0; break; @@ -201,11 +233,22 @@ export default class BigCircle extends Enemy { } 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)], - bigCircleDownToRight2: [new Rectangle(this, 0, 0, 14, 14), new Rectangle(this, 14, 14, 22, 22), new Rectangle(this, 28, 6, 14, 14), new Rectangle(this, 8, 28, 12, 14)], - bigCircleDownToRight3: [new Rectangle(this, 0, 2, 10, 22), new Rectangle(this, 10, 12, 30, 8), new Rectangle(this, 26, 0, 16, 12), new Rectangle(this, 18, 20, 24, 10), new Rectangle(this, 14, 30, 16, 12)], - bigCircleRight: [ new Rectangle(this, 0, 14, 8, 16), new Rectangle(this, 0, 18, 44, 8), new Rectangle(this, 22, 0, 14, 43), ], + 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)], + bigCircleDownToRight2: [new Rectangle(this, 0, 0, 14, 14), new Rectangle(this, 14, 14, 22, 22), new Rectangle(this, 28, 6, 14, 14), new Rectangle(this, 8, 28, 12, 14)], + bigCircleDownToRight3: [new Rectangle(this, 0, 2, 10, 22), new Rectangle(this, 10, 12, 30, 8), new Rectangle(this, 26, 0, 16, 12), new Rectangle(this, 18, 20, 24, 10), new Rectangle(this, 14, 30, 16, 12)], + bigCircleRight: [new Rectangle(this, 0, 14, 8, 16), new Rectangle(this, 8, 18, 36, 8), new Rectangle(this, 22, 0, 16, 43)], + bigCircleRightToUp1: [new Rectangle(this, 0, 18, 10, 22), new Rectangle(this, 10, 20, 30, 10), new Rectangle(this, 28, 30, 14, 12), new Rectangle(this, 16, 0, 14, 20), new Rectangle(this, 30, 12, 12, 8)], + bigCircleRightToUp2: [new Rectangle(this, 0, 28, 12, 14), new Rectangle(this, 12, 6, 22, 22), new Rectangle(this, 6, 0, 12, 12), new Rectangle(this, 28, 24, 12, 12)], + bigCircleRightToUp3: [new Rectangle(this, 6, 28, 12, 12), new Rectangle(this, 0, 2, 24, 14), new Rectangle(this, 12, 16, 26, 10), new Rectangle(this, 24, 10, 10, 6), new Rectangle(this, 26, 26, 10, 4)], + bigCircleUp: [new Rectangle(this, 14, 32, 20, 8), new Rectangle(this, 20, 0, 8, 32), new Rectangle(this, 0, 6, 48, 12)], + bigCircleUpToLeft1: [new Rectangle(this, 20, 28, 14, 10), new Rectangle(this, 14, 2, 12, 24), new Rectangle(this, 26, 0, 12, 16), new Rectangle(this, 0, 10, 12, 20)], + bigCircleUpToLeft2: [new Rectangle(this, 28, 28, 12, 12), new Rectangle(this, 6, 6, 22, 22), new Rectangle(this, 22, 0, 12, 12), new Rectangle(this, 0, 22, 12, 14)], + bigCircleUpToLeft3: [new Rectangle(this, 32, 24, 10, 22), new Rectangle(this, 24, 28, 8, 8), new Rectangle(this, 0, 18, 26, 16), new Rectangle(this, 18, 0, 12, 16), new Rectangle(this, 12, 8, 6, 10), new Rectangle(this, 0, 32, 14, 17)], + bigCircleLeft: [new Rectangle(this, 36, 12, 8, 16), new Rectangle(this, 0, 16, 36, 8), new Rectangle(this, 8, 0, 14, 41)], + bigCircleLeftToDown1: [new Rectangle(this, 32, 5, 10, 21), new Rectangle(this, 2, 16, 30, 6), new Rectangle(this, 0, 0, 14, 16), new Rectangle(this, 0, 22, 24, 10), new Rectangle(this, 12, 32, 16, 10)], + bigCircleLeftToDown2: [new Rectangle(this, 28, 0, 12, 14), new Rectangle(this, 6, 14, 22, 22), new Rectangle(this, 22, 30, 12, 12), new Rectangle(this, 0, 6, 10, 12)], + 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)], }; } diff --git a/src/enemies/Enemy.ts b/src/enemies/Enemy.ts index 607a612..d85b11e 100644 --- a/src/enemies/Enemy.ts +++ b/src/enemies/Enemy.ts @@ -5,8 +5,10 @@ import Drawable, { Rectangle } from "../Drawable"; export default abstract class Enemy extends Drawable { squares: Array<Rectangle> = [new Rectangle(this)] points = 5; + health = 2 + deathAnim: (string | HTMLImageElement)[] = ["red"] shoot(bullet: Bullet[]) { - bullet.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, 0, BULLET_VEL, true)) + bullet.push(new Bullet(this.x + (this.width / 2) - Bullet.width / 2, this.y2, 0, BULLET_VEL, false)) } } diff --git a/src/enemies/Green1.ts b/src/enemies/Green1.ts new file mode 100644 index 0000000..034ab15 --- /dev/null +++ b/src/enemies/Green1.ts @@ -0,0 +1,59 @@ +import { Rectangle } from "../Drawable"; +import { IMGS } from "../Images"; +import Enemy from "./Enemy"; + +export default class Green1 extends Enemy { + sprite = IMGS.greenUp; + width = IMGS.greenUp.width; + height = IMGS.greenUp.height; + vel = 2 + phase = 0; + spriteNum = 1; + 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) + } + + move() { + let dx = 0, dy = 0; + + switch (this.phase) { + case 0: + dy = -this.vel + if (this.y < 110) this.phase++; + break; + case 1: + dx = this.left ? -this.vel : this.vel + dy = -this.vel + if (this.y < 58) this.phase++ + break; + case 2: + this.sprite = this.left ? IMGS.greenUpToLeft : IMGS.greenUpToRight; + this.phase++; + break; + case 3: + dx = this.left ? -this.vel : this.vel + dy = -this.vel + if (this.y < 31) this.phase++ + break; + case 4: + this.sprite = IMGS.greenDown + this.phase++; + break; + case 5: + dy = this.vel + break; + default: + break; + } + + this.x += dx; + 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)] + return this.isOutsideMap() + } +} diff --git a/src/enemies/Green2.ts b/src/enemies/Green2.ts new file mode 100644 index 0000000..b4d9ddc --- /dev/null +++ b/src/enemies/Green2.ts @@ -0,0 +1,113 @@ +import { Rectangle } from "../Drawable"; +import { IMGS } from "../Images"; +import Enemy from "./Enemy"; + +export default class Green2 extends Enemy { + sprite = IMGS.greenDown; + width = IMGS.greenDown.width; + height = IMGS.greenDown.height; + vel = 2 + phase = 0; + spriteNum = 1; + 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) + } + + move() { + let dx = 0, dy = 0; + + switch (this.phase) { + case 0: + dy = this.vel + if (this.y > 163) this.phase++ + break; + case 1: + this.sprite = IMGS.greenDownToLeft + this.phase++ + this.i = 0 + break; + case 2: + dx = -this.vel + dy = this.vel + if (this.i++ === 7) this.phase++ + break; + case 3: + this.sprite = IMGS.greenLeft + this.phase++ + this.i = 0 + break; + case 4: + dx = -this.vel + if (this.x < (this.left ? 10 : 10 + 80)) this.phase++ + break; + case 5: + this.sprite = IMGS.greenLeftToUp + this.phase++ + this.i = 0 + break; + case 6: + dx = -this.vel + dy = -this.vel + if (this.i++ === 7) this.phase++ + break; + case 7: + this.sprite = IMGS.greenUp + this.phase++ + this.i = 0 + break; + case 8: + dy = -this.vel + if (this.y < 88) this.phase++ + break; + case 9: + this.sprite = IMGS.greenUpToRight + this.phase++ + this.i = 0 + break; + case 10: + dx = this.vel + dy = -this.vel + if (this.i++ === 7) this.phase++ + break; + case 11: + this.sprite = IMGS.greenRight + this.phase++ + this.i = 0 + break; + case 12: + dx = this.vel + if (this.x > (this.left ? 176 : 176 + 80)) this.phase++ + break; + case 13: + this.sprite = IMGS.greenRightToDown + this.phase++ + this.i = 0 + break; + case 14: + dx = this.vel + dy = this.vel + if (this.i++ === 7) this.phase++ + break; + case 15: + this.sprite = IMGS.greenDown + this.phase++ + this.i = 0 + break; + case 16: + dy = this.vel + break; + default: + break; + } + + this.x += dx; + 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)] + return this.isOutsideMap() + } +} diff --git a/src/enemies/Red1.ts b/src/enemies/Red1.ts new file mode 100644 index 0000000..67a8729 --- /dev/null +++ b/src/enemies/Red1.ts @@ -0,0 +1,193 @@ +import { Rectangle } from "../Drawable"; +import { IMGS } from "../Images"; +import Enemy from "./Enemy"; + +export default class Red1 extends Enemy { + sprite = IMGS.redRight; + width = IMGS.redRight.width; + height = IMGS.redRight.height; + vel = 3 + phase = 0; + spriteNum = 1; + i = 0; + squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)] + + move() { + let dx = 0, dy = 0; + + switch (this.phase) { + case 0: + dx = this.vel; + if (this.x2 > 145) this.phase++; + // if (this.i++ === 19) this.phase++; + break; + case 1: + this.sprite = IMGS.redRightToDown; + this.phase++; + this.i = 0; + break; + case 2: + dx = this.vel; + dy = this.vel; + if (this.i++ === 7) this.phase++; + break; + case 3: + this.sprite = IMGS.redDown; + this.phase++; + this.i = 0; + break; + case 4: + dy = this.vel; + // if (this.y > 125) this.phase++; + if (this.i++ === 19) this.phase++; + break; + case 5: + this.sprite = IMGS.redDownToLeft; + this.phase++; + this.i = 0; + break; + case 6: + dx = -this.vel; + dy = this.vel; + if (this.i++ === 7) this.phase++; + break; + case 7: + this.sprite = IMGS.redLeft; + this.phase++; + this.i = 0; + break; + case 8: + dx = -this.vel; + // if (this.x < 60) this.phase++; + if (this.i++ === 19) this.phase++; + break; + case 9: + this.sprite = IMGS.redLeftToUp; + this.phase++; + this.i = 0; + break; + case 10: + dx = -this.vel + dy = -this.vel + if (this.i++ === 7) this.phase++; + break; + case 11: + this.sprite = IMGS.redUp; + this.phase++; + this.i = 0; + break; + case 12: + dy = -this.vel + // if (this.y < 80) this.phase++; + if (this.i++ === 19) this.phase++; + break; + case 13: + this.sprite = IMGS.redUpToRight; + this.phase++; + this.i = 0; + break; + case 14: + dx = this.vel + dy = -this.vel + if (this.i++ === 7) this.phase++; + break; + case 15: + this.sprite = IMGS.redRight; + this.phase++; + this.i = 0; + break; + case 16: + dx = this.vel + if (this.x2 > 263) this.phase++; + // if (this.i++ === 19) this.phase++; + break; + case 17: + this.sprite = IMGS.redRightToDown; + this.phase++; + this.i = 0; + break; + case 18: + dx = this.vel + dy = this.vel + if (this.i++ === 7) this.phase++; + break; + case 19: + this.sprite = IMGS.redDown; + this.phase++; + this.i = 0; + break; + case 20: + dy = this.vel; + // if (this.y2 > 150) this.phase++; + if (this.i++ === 19) this.phase++; + break; + case 21: + this.sprite = IMGS.redDownToLeft; + this.phase++; + this.i = 0; + break; + case 22: + dx = -this.vel + dy = this.vel + if (this.i++ === 7) this.phase++; + break; + case 23: + this.sprite = IMGS.redLeft; + this.phase++; + this.i = 0; + break; + case 24: + dx = -this.vel + // if (this.x < 175) this.phase++; + if (this.i++ === 19) this.phase++; + break; + case 25: + this.sprite = IMGS.redLeftToUp; + this.phase++; + this.i = 0; + break; + case 26: + dx = -this.vel + dy = -this.vel + if (this.i++ === 7) this.phase++; + break; + case 27: + this.sprite = IMGS.redUp; + this.phase++; + this.i = 0; + break; + case 28: + dy = -this.vel + // if (this.y < 70) this.phase++ + if (this.i++ === 19) this.phase++; + break; + case 29: + this.sprite = IMGS.redUpToRight; + this.phase++; + this.i = 0; + break; + case 30: + dx = this.vel + dy = -this.vel + if (this.i++ === 7) this.phase++; + break; + case 31: + this.sprite = IMGS.redRight; + this.phase++; + this.i = 0; + break; + case 32: + dx = this.vel + break; + default: + break; + } + + this.x += dx; + 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)] + return this.isOutsideMap() + } +} diff --git a/src/enemies/Red2.ts b/src/enemies/Red2.ts new file mode 100644 index 0000000..6cfa672 --- /dev/null +++ b/src/enemies/Red2.ts @@ -0,0 +1,114 @@ +import { Rectangle } from "../Drawable"; +import { IMGS } from "../Images"; +import Enemy from "./Enemy"; + +export default class Red2 extends Enemy { + sprite = IMGS.redDown; + width = IMGS.redDown.width; + height = IMGS.redDown.height; + vel = 2; + 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) + } + + move() { + let dx = 0, dy = 0; + + switch (this.phase) { + case 0: + dy = this.vel; + if (this.y > 163) this.phase++; + break; + case 1: + this.sprite = IMGS.redDownToRight + this.phase++ + this.i = 0; + break; + case 2: + dx = this.vel + dy = this.vel + if (this.i++ === 9) this.phase++; + break; + case 3: + this.sprite = IMGS.redRight + this.phase++ + this.i = 0; + break; + case 4: + dx = this.vel + if (this.x > (this.left ? 285 : 285 + 80)) this.phase++; + break; + case 5: + this.sprite = IMGS.redRightToUp + this.phase++ + this.i = 0; + break; + case 6: + dx = this.vel + dy = -this.vel + if (this.i++ === 13) this.phase++; + break; + case 7: + this.sprite = IMGS.redUp + this.phase++; + break; + case 8: + dy = -this.vel + if (this.y < 98) this.phase++ + break; + case 9: + this.sprite = IMGS.redUpToLeft + this.phase++ + this.i = 0; + break; + case 10: + dx = -this.vel + dy = -this.vel + if (this.i++ === 7) this.phase++; + break; + case 11: + this.sprite = IMGS.redLeft + this.phase++ + this.i = 0; + break; + case 12: + dx = -this.vel + if (this.x < (this.left ? 210 : 210 + 80)) this.phase++ + break; + case 13: + this.sprite = IMGS.redLeftToDown + this.phase++ + this.i = 0 + break; + case 14: + dx = -this.vel + dy = this.vel + if (this.i++ === 7) this.phase++; + break; + case 15: + this.sprite = IMGS.redDown + this.phase++ + this.i = 0 + break; + case 16: + dy = this.vel + console.log(this.x); + + break; + default: + break; + } + + this.x += dx; + 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)] + return this.isOutsideMap() && this.phase > 12 + } +} + diff --git a/src/enemies/Straight.ts b/src/enemies/Straight.ts index c397332..895ec01 100644 --- a/src/enemies/Straight.ts +++ b/src/enemies/Straight.ts @@ -1,17 +1,39 @@ -import { canvas, PLAYER_VEL } from "../consts"; +import { canvas } from "../consts"; +import { Rectangle } from "../Drawable"; +import { IMGS } from "../Images"; import Enemy from "./Enemy"; export default class Straight extends Enemy { - width = 20; - height = 20; - sprite = "blue"; - vel = PLAYER_VEL * 0.8 + sprite = IMGS.simpleDown; + width = IMGS.simpleDown.width; + height = IMGS.simpleDown.height; + vel = 2 + phase = 0; + spriteNum = 1; + i = 0; + squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)] move() { - if (this.y + this.height > canvas.height) { this.y = canvas.height - this.height; } - else if (this.y === canvas.height - this.height) { this.vel *= -1; this.y += this.vel; } - else { this.y += this.vel; } + let dy = 0; + if (this.phase === 0) { + dy = this.vel; + if (this.y2 > canvas.height - 15) this.phase++; + } + if (this.phase === 1) { + //@ts-expect-error + this.sprite = IMGS["simpleRot" + this.spriteNum] + if (this.i++ === 4) { this.i = 0; this.spriteNum++; } + if (this.spriteNum === 5) { this.sprite = IMGS.simpleUp; this.phase++; } + } + if (this.phase === 2) { + dy = -this.vel; + } + + 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)] return this.y + this.height < 0 } } diff --git a/src/enemies/Strange.ts b/src/enemies/Strange.ts new file mode 100644 index 0000000..69fd9c0 --- /dev/null +++ b/src/enemies/Strange.ts @@ -0,0 +1,92 @@ +import { Rectangle } from "../Drawable"; +import { IMGS } from "../Images"; +import Enemy from "./Enemy"; + +export default class Strange extends Enemy { + sprite = IMGS.bigStrangeUp1; + width = IMGS.bigStrangeUp1.width; + height = IMGS.bigStrangeUp1.height; + vel = 1 + phase = 0; + spriteCounter = 0; + spriteNum = 1; + i = 0; + squares: Rectangle[] = [new Rectangle(this, 2, 2, this.width - 2, this.height - 2)] + + move() { + let dx = 0, dy = 0; + + switch (this.phase) { + case 0: + dy = -this.vel + if (this.y < 105) this.phase++; + break; + case 1: + this.phase++; + break; + case 2: + dx = this.vel + dy = -this.vel + if (this.x > 182) this.phase++; + break; + case 3: + this.vel = 3 + dx = this.vel + if (this.x > 210) this.phase++; + // if (this.x > 210) debugger + break; + case 4: + this.vel = 2; + dx = this.vel + dy = -this.vel + if (this.y < 70) this.phase++; + break; + case 5: + dx = -this.vel + if (this.x < 175) this.phase++; + break; + case 6: + dx = -this.vel + dy = -this.vel + if (this.y < 45) this.phase++; + break; + case 7: + dx = -this.vel + if (this.x < 60) this.phase++; + break; + case 8: + dx = -this.vel + dy = this.vel + if (this.x < 20) this.phase++; + break; + case 9: + dx = this.vel + if (this.x > 40) this.phase++; + break; + case 10: + dx = this.vel + dy = -this.vel + if (this.x > 60) this.phase++; + break; + case 11: + this.vel = 1; + this.phase++; + break; + case 12: + dy = -this.vel + break; + default: + break; + } + + 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)] + return this.isOutsideMap() + } +} + diff --git a/src/enemies/White.ts b/src/enemies/White.ts new file mode 100644 index 0000000..2987985 --- /dev/null +++ b/src/enemies/White.ts @@ -0,0 +1,68 @@ +import { Rectangle } from "../Drawable"; +import { IMGS } from "../Images"; +import Enemy from "./Enemy"; + +export default class White extends Enemy { + sprite = IMGS.whiteDown; + width = IMGS.whiteDown.width; + height = IMGS.whiteDown.height; + velx = 1 + vely = 3 + phase = 0; + spriteNum = 1; + 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) + } + + move() { + let dx = 0, dy = 0; + + switch (this.phase) { + case 0: + dy = this.vely + if (this.y > 40) this.phase++; + break; + case 1: + dx = this.left ? this.velx : -this.velx + dy = this.vely + if (this.y > 78) this.phase++ + break; + case 2: + this.velx = 3 + this.sprite = this.left ? IMGS.whiteTurnLeft : IMGS.whiteTurnRight; + dx = this.left ? this.velx : -this.velx + dy = this.vely + if (this.y > 145) this.phase++ + break; + case 3: + this.velx = 6 + this.sprite = this.left ? IMGS.whiteStrangeLeft : IMGS.whiteStrangeRight; + dx = this.left ? this.velx : -this.velx + dy = this.vely + // if (this.y > 145) this.phase++ + break; + // case 1: + // dx = this.left ? -this.vel : this.vel + // dy = -this.vel + // if (this.y < 58) this.phase++ + // break; + // case 2: + // this.sprite = this.left ? IMGS.greenUpToLeft : IMGS.greenUpToRight; + // this.phase++; + // break; + default: + break; + } + + this.x += dx; + 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)] + return this.isOutsideMap() + } +} + |
