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/Green2.ts | |
| parent | 344737031e5bbad5f24469aabf45be6535c893f3 (diff) | |
| download | 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.gz 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.tar.zst 1942-0010f2de57cfa97106432ea1849c1bb75d3d99a1.zip | |
All enemies movement
Diffstat (limited to 'src/enemies/Green2.ts')
| -rw-r--r-- | src/enemies/Green2.ts | 113 |
1 files changed, 113 insertions, 0 deletions
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() + } +} |
