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