diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2022-05-31 18:11:09 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2022-05-31 18:11:09 +0200 |
| commit | 0010f2de57cfa97106432ea1849c1bb75d3d99a1 (patch) | |
| tree | 41e89ff13aacfc4dc1324a365302a0867e316dc9 /src/enemies/Straight.ts | |
| parent | 344737031e5bbad5f24469aabf45be6535c893f3 (diff) | |
| download | 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.gz 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.zst 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.zip | |
All enemies movement
Diffstat (limited to 'src/enemies/Straight.ts')
| -rw-r--r-- | src/enemies/Straight.ts | 38 |
1 files changed, 30 insertions, 8 deletions
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 } } |
