Skip to content

Commit afe1a3f

Browse files
committed
Level refinement
1 parent d871118 commit afe1a3f

File tree

6 files changed

+55
-40
lines changed

6 files changed

+55
-40
lines changed

src/scripts/bomber.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { GameState } from './gameState.js';
1010

1111
export class Bomber extends Enemy {
1212
static HEALTH = 2;
13-
static SPEED = 0.7;
13+
static SPEED = 0.8;
1414
static RECOVERY_TIME_MS = 2000;
1515

1616
constructor(game, x, y, spriteIdle) {

src/scripts/level.js

+34-30
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,30 @@ export class Level {
114114
}
115115
}
116116

117-
// Poppers
118-
const popperLevels = [3, 4, 5, 6, 7, 8, 9, 10];
119-
if (popperLevels.indexOf(this.number) >= 0) {
120-
const popperCount = Math.max(1, Math.min(2, this.number - 5));
121-
for (let i = 0; i < popperCount; i++) {
122-
initialEnemies.push(
123-
this.popperSpawner.spawnWithoutIntersecting(initialEnemies)
124-
);
117+
// Towers
118+
const towerLevels = [3, 4, 5, 6, 7, 8, 9, 10];
119+
if (towerLevels.indexOf(this.number) >= 0) {
120+
const towerCount = Math.max(1, Math.min(3, this.number - 6));
121+
for (let i = 0; i < towerCount; i++) {
122+
initialEnemies.push(this.towerSpawner.spawnWithoutIntersecting(initialEnemies));
125123
}
126124
}
127125

128-
// Dumper
129-
const dumperLevels = [4, 5, 6, 7, 8, 9, 10];
130-
if (dumperLevels.indexOf(this.number) >= 0) {
131-
const dumperCount = Math.max(1, Math.min(3, this.number - 6));
132-
for (let i = 0; i < dumperCount; i++) {
126+
// Pounder
127+
const pounderLevels = [4, 5, 6, 7, 8, 9, 10];
128+
if (pounderLevels.indexOf(this.number) >= 0) {
129+
const pounderCount = Math.max(1, Math.min(3, this.number - 6));
130+
for (let i = 0; i < pounderCount; i++) {
133131
initialEnemies.push(
134-
this.dumperSpawner.spawnWithoutIntersecting(initialEnemies)
132+
this.pounderSpawner.spawnWithoutIntersecting(initialEnemies)
135133
);
136134
}
137135
}
136+
138137
}
139138

140139
if (this.world.number === 2) {
140+
141141
// Tanks
142142
const tankLevels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
143143
if (tankLevels.indexOf(this.number) >= 0) {
@@ -158,21 +158,22 @@ export class Level {
158158
}
159159
}
160160

161-
// Pounder
162-
const pounderLevels = [4, 5, 6, 7, 8, 9, 10];
163-
if (pounderLevels.indexOf(this.number) >= 0) {
164-
const pounderCount = Math.max(1, Math.min(3, this.number - 6));
165-
for (let i = 0; i < pounderCount; i++) {
161+
// Dumper
162+
const dumperLevels = [4, 5, 6, 7, 8, 9, 10];
163+
if (dumperLevels.indexOf(this.number) >= 0) {
164+
const dumperCount = Math.max(1, Math.min(3, this.number - 6));
165+
for (let i = 0; i < dumperCount; i++) {
166166
initialEnemies.push(
167-
this.pounderSpawner.spawnWithoutIntersecting(initialEnemies)
167+
this.dumperSpawner.spawnWithoutIntersecting(initialEnemies)
168168
);
169169
}
170170
}
171171
}
172172

173173
if (this.world.number === 3) {
174+
174175
// Zamboney
175-
const zamboneyLevels = [1, 2, 4, 5, 6, 7, 8, 9, 10];
176+
const zamboneyLevels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
176177
if (zamboneyLevels.indexOf(this.number) >= 0) {
177178
const zamboneyCount = Math.max(1, Math.min(4, this.number - 6));
178179
for (let i = 0; i < zamboneyCount; i++) {
@@ -182,12 +183,14 @@ export class Level {
182183
}
183184
}
184185

185-
// Towers
186-
const towerLevels = [3, 4, 5, 6, 7, 8, 9, 10];
187-
if (towerLevels.indexOf(this.number) >= 0) {
188-
const towerCount = Math.max(1, Math.min(3, this.number - 6));
189-
for (let i = 0; i < towerCount; i++) {
190-
initialEnemies.push(this.towerSpawner.spawnWithoutIntersecting(initialEnemies));
186+
// Poppers
187+
const popperLevels = [3, 4, 5, 6, 7, 8, 9, 10];
188+
if (popperLevels.indexOf(this.number) >= 0) {
189+
const popperCount = Math.max(1, Math.min(2, this.number - 5));
190+
for (let i = 0; i < popperCount; i++) {
191+
initialEnemies.push(
192+
this.popperSpawner.spawnWithoutIntersecting(initialEnemies)
193+
);
191194
}
192195
}
193196

@@ -204,6 +207,7 @@ export class Level {
204207
}
205208

206209
if (this.world.number === 4) {
210+
207211
// Chasers
208212
const chaserLevels = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
209213
if (chaserLevels.indexOf(this.number) >= 0) {
@@ -238,7 +242,7 @@ export class Level {
238242

239243
if (this.world.number === 5) {
240244
if (this.number === 1) {
241-
const chaserCount = 6;
245+
const chaserCount = 7;
242246
for (let i = 0; i < chaserCount; i++) {
243247
initialEnemies.push(
244248
this.chaserSpawner.spawnWithoutIntersecting(initialEnemies)
@@ -278,7 +282,7 @@ export class Level {
278282
if (this.number === 4) {
279283
initialEnemies.push(this.turrentSpawner.spawnWithoutIntersecting(initialEnemies));
280284
initialEnemies.push(this.zamboneySpawner.spawnWithoutIntersecting(initialEnemies));
281-
const pounderCount = 2;
285+
const pounderCount = 3;
282286
for (let i = 0; i < pounderCount; i++) {
283287
initialEnemies.push(
284288
this.pounderSpawner.spawnWithoutIntersecting(initialEnemies)
@@ -396,7 +400,7 @@ export class Level {
396400
const collectables = [];
397401

398402
// Gems
399-
const gemCount = Math.min(Level.MAX_GEMS, Math.ceil(this.world.number + this.number * 0.5));
403+
const gemCount = Math.min(Level.MAX_GEMS, Math.ceil(this.world.number + this.number * 0.7));
400404
const entitiesToAvoid = [this.game.player, ...this.game.enemies];
401405
for (let i = 0; i < gemCount; i++) {
402406
const gem = this.gemSpawner.spawnWithoutIntersecting(entitiesToAvoid);

src/scripts/pounder.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { GameState } from './gameState.js';
1010

1111
export class Pounder extends Enemy {
1212
constructor(game, x, y, width, height, currentSprite) {
13-
super(game, x, y, width, height, 25, EnemyTypes.POUNDER, currentSprite, true);
13+
super(game, x, y, width, height, 20, EnemyTypes.POUNDER, currentSprite, true);
1414

1515
this.spriteIdle = currentSprite;
1616
this.spritePound = SpriteLibrary.pounderPound();

src/scripts/sentry.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export class Sentry extends Enemy {
1313
SHOOTING_LEFT: 1,
1414
SHOOTING_RIGHT: 2,
1515
};
16-
static SHOOT_INTERVAL_MS = 800;
17-
static SHOOT_DISTANCE = 290;
16+
static SHOOT_INTERVAL_MS = 1000;
17+
static SHOOT_DISTANCE = 280;
1818

1919
constructor(game, x, y, spriteIdle) {
2020
super(

src/scripts/tower.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Tower extends Enemy {
1515
y,
1616
SpriteLibrary.SIZES.TOWER.width,
1717
SpriteLibrary.SIZES.TOWER.height,
18-
35,
18+
25,
1919
EnemyTypes.TOWER,
2020
x < game.canvas.width * 0.5
2121
? SpriteLibrary.towerRightIdle()

src/scripts/zamboney.js

+16-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { GameState } from './gameState.js';
88
import { Rocket } from './rocket.js';
99

1010
export class Zamboney extends Enemy {
11-
static SPEED = 2;
11+
static SPEED = 2.5;
1212

1313
constructor(game, x, y, spriteLeft) {
1414
super(
@@ -23,7 +23,6 @@ export class Zamboney extends Enemy {
2323
true
2424
);
2525

26-
2726
this.spriteLeft = spriteLeft;
2827
this.spriteRight = SpriteLibrary.zamboneyRight();
2928
this.sprites = [this.spriteLeft, this.spriteRight];
@@ -33,7 +32,7 @@ export class Zamboney extends Enemy {
3332

3433
this.mover = new Mover(game, this);
3534
this.mover.pace(Zamboney.SPEED);
36-
this.lastShootTime = 0;
35+
this.lastShootTime = 0;
3736
}
3837

3938
update() {
@@ -53,16 +52,28 @@ export class Zamboney extends Enemy {
5352
}
5453

5554
if (this.game.state === GameState.PLAYING) {
56-
// Fire at player
5755
const player = this.game.player;
5856
const yDistanceFromPlayer = Math.abs(player.y + player.height - (this.y + this.height));
5957
const shouldBeShooting = !player.recovering && yDistanceFromPlayer <= 15;
58+
// Face the player when shooting
59+
if (shouldBeShooting) {
60+
if (player.x >= this.x && this.facingLeft) {
61+
this.facingLeft = false;
62+
this.currentSprite = this.spriteRight;
63+
this.mover.pace(Zamboney.SPEED);
64+
} else if (player.x < this.x && !this.facingLeft) {
65+
this.facingLeft = true;
66+
this.currentSprite = this.spriteLeft;
67+
this.mover.pace(-Zamboney.SPEED);
68+
}
69+
}
70+
// Fire at player
6071
if (shouldBeShooting && this.game.gameTime - this.lastShootTime >= 2000) {
6172
Rocket.spawn(
6273
this.game,
6374
this.facingLeft ? this.x : this.x + this.width,
6475
this.y + this.height * 0.5 - SpriteLibrary.SIZES.BOMB.height * 0.5,
65-
this.facingLeft ? -1 : 1,
76+
this.facingLeft ? -1 : 1
6677
);
6778
this.lastShootTime = this.game.gameTime;
6879
}

0 commit comments

Comments
 (0)