aboutsummaryrefslogtreecommitdiffstats
path: root/src/enemies/Strange.ts
blob: 2faa1ba1e34d0c36f42d4fc4342016f8b3334578 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import { BULLET_VEL, TOPBAR_HEIGHT } from "../consts";
import { Rectangle } from "../Drawable";
import Bullet from "../drawables/Bullet";
import { random } from "../helpers";
import { getBigDeathAnim, 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;
  si = 0;
  changeSprite = true;
  spriteNum = 1;
  i = 0;
  squares: Rectangle[] = [
    new Rectangle(this, 22, 0, 4, 37),
    new Rectangle(this, 14, 31, 20, 5),
    new Rectangle(this, 0, 8, 48, 8),
    new Rectangle(this, 10, 5, 8, 3),
    new Rectangle(this, 30, 4, 8, 4),
    new Rectangle(this, 8, 16, 32, 2),
    new Rectangle(this, 18, 18, 12, 3),
  ]
  health = 30
  points = 2100

  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;
    }

    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;
    // 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()
  }

  shoot(bullets: Bullet[]): boolean {
    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 / 2, false))
      } else {
        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))
      }

    }
    return true
  }

  deathAnim = getBigDeathAnim(this)
}