brick-engine-cli 1.0.12 → 1.0.14
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.
- package/dist/commands/init/package/package.d.ts +1 -0
- package/dist/commands/init/package/package.js +1 -0
- package/dist/commands/publish/index.js +9 -0
- package/package.json +2 -2
- package/src/commands/init/package/package.ts +1 -0
- package/src/commands/publish/index.ts +9 -0
- package/templates/.prettierrc +1 -1
- package/templates/src/index.ts +61 -33
|
@@ -53,6 +53,15 @@ async function publishCommand(options) {
|
|
|
53
53
|
type: "input",
|
|
54
54
|
name: "gameName",
|
|
55
55
|
message: "Enter your game name:",
|
|
56
|
+
validate: (input) => {
|
|
57
|
+
if (!input || input.trim().length === 0) {
|
|
58
|
+
return "Game name is required.";
|
|
59
|
+
}
|
|
60
|
+
if (input.length > 10) {
|
|
61
|
+
return "Game name cannot exceed 10 characters.";
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
},
|
|
56
65
|
});
|
|
57
66
|
prompts.push({
|
|
58
67
|
type: "input",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brick-engine-cli",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.14",
|
|
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.
|
|
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",
|
|
@@ -66,6 +66,15 @@ export async function publishCommand(options: { url?: string; key?: string }) {
|
|
|
66
66
|
type: "input",
|
|
67
67
|
name: "gameName",
|
|
68
68
|
message: "Enter your game name:",
|
|
69
|
+
validate: (input: string) => {
|
|
70
|
+
if (!input || input.trim().length === 0) {
|
|
71
|
+
return "Game name is required.";
|
|
72
|
+
}
|
|
73
|
+
if (input.length > 10) {
|
|
74
|
+
return "Game name cannot exceed 10 characters.";
|
|
75
|
+
}
|
|
76
|
+
return true;
|
|
77
|
+
},
|
|
69
78
|
});
|
|
70
79
|
|
|
71
80
|
prompts.push({
|
package/templates/.prettierrc
CHANGED
package/templates/src/index.ts
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
import {
|
|
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
|
-
|
|
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(
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
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
|
-
|
|
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 =>
|
|
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 (
|
|
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.
|
|
168
|
+
text.writeOnDisplay('DODGE BRICK', { x: 0.5, y: 0.3 });
|
|
142
169
|
|
|
143
170
|
text.setTextSize(FontSize.SMALL);
|
|
144
|
-
text.
|
|
171
|
+
text.writeOnDisplay('USE ARROWS TO MOVE', { x: 0.5, y: 0.5 });
|
|
145
172
|
|
|
146
173
|
text.setTextSize(FontSize.MEDIUM);
|
|
147
|
-
text.
|
|
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.
|
|
186
|
+
text.writeOnDisplay('GAME OVER', { x: 0.5, y: 0.4 });
|
|
159
187
|
|
|
160
188
|
text.setTextSize(FontSize.SMALL);
|
|
161
|
-
text.
|
|
189
|
+
text.writeOnDisplay(`FINAL SCORE: ${score.score}`, { x: 0.5, y: 0.55 });
|
|
162
190
|
|
|
163
191
|
text.setTextSize(FontSize.MEDIUM);
|
|
164
|
-
text.
|
|
192
|
+
text.writePulsingTextOnDisplay('PRESS START', { x: 0.5, y: 0.8 });
|
|
165
193
|
}
|
|
166
194
|
}
|