brick-engine-cli 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,5 +14,6 @@ export default function packageJson(name: string, answers: Answers): {
14
14
  overrides: {
15
15
  ajv: string;
16
16
  minimatch: string;
17
+ "serialize-javascript": string;
17
18
  };
18
19
  };
@@ -38,6 +38,7 @@ function packageJson(name, answers) {
38
38
  overrides: {
39
39
  ajv: "^8.18.0",
40
40
  minimatch: "^10.2.1",
41
+ "serialize-javascript": "^7.0.3",
41
42
  },
42
43
  };
43
44
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brick-engine-cli",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "description": "CLI to scaffold Brick Game projects",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@types/inquirer": "^8.2.12",
16
- "brick-engine-js": "^1.0.22",
16
+ "brick-engine-js": "^1.0.31",
17
17
  "chalk": "^4.1.2",
18
18
  "commander": "^11.1.0",
19
19
  "dotenv": "^17.3.1",
@@ -43,6 +43,7 @@ export default function packageJson(name: string, answers: Answers) {
43
43
  overrides: {
44
44
  ajv: "^8.18.0",
45
45
  minimatch: "^10.2.1",
46
+ "serialize-javascript": "^7.0.3",
46
47
  },
47
48
  };
48
49
  }
@@ -4,5 +4,5 @@
4
4
  "endOfLine": "lf",
5
5
  "tabWidth": 4,
6
6
  "arrowParens": "avoid",
7
- "printWidth": 160
7
+ "printWidth": 80
8
8
  }
@@ -1,4 +1,14 @@
1
- import { Game, FontSize, ControlKey, ControlEventType, Sound, FontAlign, FontVerticalAlign, Color, Coordinate, Cell } from 'brick-engine-js';
1
+ import {
2
+ Game,
3
+ FontSize,
4
+ ControlKey,
5
+ ControlEventType,
6
+ Sound,
7
+ FontAlign,
8
+ FontVerticalAlign,
9
+ Color,
10
+ Cell,
11
+ } from 'brick-engine-js';
2
12
 
3
13
  export default class MyGame extends Game {
4
14
  private initialPlayerCell: Cell = {
@@ -12,7 +22,11 @@ export default class MyGame extends Game {
12
22
  private initialTickInterval = 200;
13
23
 
14
24
  private player: Cell = this.initialPlayerCell;
15
- private enemies: Coordinate[] = [];
25
+
26
+ private enemies: Cell[] = [];
27
+ private enemyColor = Color.RED;
28
+ private enemyValue = 2;
29
+
16
30
  private spawnRate = 5; // Ticks between spawns
17
31
 
18
32
  /**
@@ -46,20 +60,22 @@ export default class MyGame extends Game {
46
60
  });
47
61
 
48
62
  // Move Left
49
- control.subscribeForPlayingScreen(ControlKey.LEFT, ControlEventType.PRESSED, () => {
50
- const newCell = grid.moveCellLeft(this.player);
51
- if (newCell) {
52
- this.player = newCell;
53
- }
54
- });
63
+ control.subscribeForPlayingScreen(
64
+ ControlKey.LEFT,
65
+ ControlEventType.PRESSED,
66
+ () => {
67
+ this.player = grid.moveCellLeft(this.player);
68
+ },
69
+ );
55
70
 
56
71
  // Move Right
57
- control.subscribeForPlayingScreen(ControlKey.RIGHT, ControlEventType.PRESSED, () => {
58
- const newCell = grid.moveCellRight(this.player);
59
- if (newCell) {
60
- this.player = newCell;
61
- }
62
- });
72
+ control.subscribeForPlayingScreen(
73
+ ControlKey.RIGHT,
74
+ ControlEventType.PRESSED,
75
+ () => {
76
+ this.player = grid.moveCellRight(this.player);
77
+ },
78
+ );
63
79
  }
64
80
 
65
81
  /**
@@ -69,16 +85,30 @@ export default class MyGame extends Game {
69
85
  const { grid, state, score, sound, time } = this.modules;
70
86
 
71
87
  // 1. Move enemies down
72
- this.enemies = this.enemies.map(enemy => ({ x: enemy.x, y: enemy.y + 1 })).filter(enemy => grid.isCoordinateValid({ x: enemy.x, y: enemy.y }));
88
+ this.enemies = this.enemies
89
+ .filter(enemy => enemy.coordinate.y !== grid.bottomRow)
90
+ .map(enemy => grid.moveCellDown(enemy));
73
91
 
74
92
  // 2. Spawn new enemy
75
93
  if (time.isTickEvery(this.spawnRate)) {
76
94
  const spawnX = Math.floor(Math.random() * grid.width);
77
- this.enemies.push({ x: spawnX, y: grid.topRow });
95
+
96
+ const newEnemy = {
97
+ coordinate: {
98
+ x: spawnX,
99
+ y: grid.topRow,
100
+ },
101
+ color: this.enemyColor,
102
+ value: this.enemyValue,
103
+ };
104
+
105
+ this.enemies.push(newEnemy);
78
106
  }
79
107
 
80
108
  // 3. Check collisions
81
- const collision = this.enemies.find(enemy => enemy.x === this.player.coordinate.x && enemy.y === this.player.coordinate.y);
109
+ const collision = this.enemies.find(enemy =>
110
+ grid.isAreaOccupied([enemy.coordinate]),
111
+ );
82
112
 
83
113
  if (collision) {
84
114
  sound.play(Sound.EXPLOSION);
@@ -95,21 +125,17 @@ export default class MyGame extends Game {
95
125
 
96
126
  // Draw Enemies
97
127
  // Piece is a class that represents a collection of cells in the grid
98
- grid.stampPiece(
99
- this.enemies.map(coordinate => {
100
- return {
101
- coordinate,
102
- color: Color.RED,
103
- value: 2,
104
- };
105
- }),
106
- );
128
+ grid.stampPiece(this.enemies);
107
129
 
108
130
  // 5. Increase score and difficulty
109
131
  score.increaseScore(1);
110
132
 
111
133
  // Increase speed every 50 points, limit to 10 levels
112
- if (score.score > 0 && score.score % 50 === 0 && score.level < score.maxLevel) {
134
+ if (
135
+ score.score > 0 &&
136
+ score.score % 50 === 0 &&
137
+ score.level < score.maxLevel
138
+ ) {
113
139
  // Set tick interval to 200ms minus 15ms per level
114
140
  time.setTickInterval(this.initialTickInterval - 15 * score.level);
115
141
 
@@ -136,15 +162,16 @@ export default class MyGame extends Game {
136
162
  drawTitleScreen(): void {
137
163
  const { text } = this.modules;
138
164
 
165
+ text.setActiveText();
139
166
  text.setTextSize(FontSize.MEDIUM);
140
167
  text.setTextAlign(FontAlign.CENTER, FontVerticalAlign.CENTER);
141
- text.textOnDisplay('DODGE BRICK', { x: 0.5, y: 0.3 });
168
+ text.writeOnDisplay('DODGE BRICK', { x: 0.5, y: 0.3 });
142
169
 
143
170
  text.setTextSize(FontSize.SMALL);
144
- text.textOnDisplay('USE ARROWS TO MOVE', { x: 0.5, y: 0.5 });
171
+ text.writeOnDisplay('USE ARROWS TO MOVE', { x: 0.5, y: 0.5 });
145
172
 
146
173
  text.setTextSize(FontSize.MEDIUM);
147
- text.textOnDisplay('PRESS START', { x: 0.5, y: 0.8 });
174
+ text.writePulsingTextOnDisplay('PRESS START', { x: 0.5, y: 0.8 });
148
175
  }
149
176
 
150
177
  /**
@@ -153,14 +180,15 @@ export default class MyGame extends Game {
153
180
  drawGameOverScreen(): void {
154
181
  const { text, score } = this.modules;
155
182
 
183
+ text.setActiveText();
156
184
  text.setTextAlign(FontAlign.CENTER, FontVerticalAlign.CENTER);
157
185
  text.setTextSize(FontSize.MEDIUM);
158
- text.textOnDisplay('GAME OVER', { x: 0.5, y: 0.4 });
186
+ text.writeOnDisplay('GAME OVER', { x: 0.5, y: 0.4 });
159
187
 
160
188
  text.setTextSize(FontSize.SMALL);
161
- text.textOnDisplay(`FINAL SCORE: ${score.score}`, { x: 0.5, y: 0.55 });
189
+ text.writeOnDisplay(`FINAL SCORE: ${score.score}`, { x: 0.5, y: 0.55 });
162
190
 
163
191
  text.setTextSize(FontSize.MEDIUM);
164
- text.textOnDisplay('PRESS START', { x: 0.5, y: 0.8 });
192
+ text.writePulsingTextOnDisplay('PRESS START', { x: 0.5, y: 0.8 });
165
193
  }
166
194
  }