frigame3 0.0.0-stage → 3.0.0
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/CHANGELOG.md +13 -0
- package/LICENSE +373 -0
- package/README.md +80 -2
- package/biome.json +93 -0
- package/demo/package-lock.json +515 -0
- package/demo/package.json +19 -0
- package/demo/snake/index.html +16 -0
- package/demo/snake/index.ts +110 -0
- package/demo/tetris/index.html +16 -0
- package/demo/tetris/index.ts +536 -0
- package/demo/tsconfig.json +53 -0
- package/frigame.css +12 -0
- package/package.json +50 -4
- package/src/Animation.ts +266 -0
- package/src/BaseSprite.ts +682 -0
- package/src/Gradient.ts +120 -0
- package/src/Playground.ts +247 -0
- package/src/Rect.ts +237 -0
- package/src/Rectangle.ts +108 -0
- package/src/Renderer.ts +28 -0
- package/src/ResourceManager.ts +145 -0
- package/src/Sprite.ts +484 -0
- package/src/SpriteGroup.ts +258 -0
- package/src/canvasRenderer/renderGroup.ts +194 -0
- package/src/canvasRenderer/renderPlayground.ts +103 -0
- package/src/canvasRenderer/renderRectangle.ts +421 -0
- package/src/canvasRenderer/renderSprite.ts +148 -0
- package/src/canvasRenderer.ts +38 -0
- package/src/dummyRenderer.ts +62 -0
- package/src/plugins/GamepadTracker.ts +97 -0
- package/src/plugins/Tilemap.ts +123 -0
- package/src/plugins/Vec2.ts +420 -0
- package/src/plugins/fx/Shaker.ts +293 -0
- package/src/plugins/fx/Tweener.ts +252 -0
- package/src/plugins/fx/easing.ts +276 -0
- package/src/plugins/isometric/ISOMixin.ts +444 -0
- package/src/plugins/isometric/ISORectangle.ts +183 -0
- package/src/plugins/isometric/ISOSprite.ts +228 -0
- package/src/plugins/isometric/ISOSpriteGroup.ts +155 -0
- package/src/plugins/isometric/ISOTilemap.ts +122 -0
- package/src/plugins/isometric/utils.ts +19 -0
- package/src/plugins/keyTracker.ts +31 -0
- package/src/plugins/mixer.ts +523 -0
- package/src/plugins/sorted/SortedAnimation.ts +53 -0
- package/src/plugins/sorted/SortedGroup.ts +94 -0
- package/src/plugins/sorted/SortedMixin.ts +203 -0
- package/src/plugins/sorted/SortedRectangle.ts +35 -0
- package/src/plugins/sorted/SortedSprite.ts +56 -0
- package/src/utils.ts +53 -0
- package/test/animation/index.html +20 -0
- package/test/animation/index.ts +253 -0
- package/test/animation/mh.png +0 -0
- package/test/animation/moh.png +0 -0
- package/test/animation/mov.png +0 -0
- package/test/animation/mv.png +0 -0
- package/test/animation/rebound.png +0 -0
- package/test/animation/reboundm.png +0 -0
- package/test/animation/sh.png +0 -0
- package/test/animation/soh.png +0 -0
- package/test/animation/sov.png +0 -0
- package/test/animation/sv.png +0 -0
- package/test/isometric1/beach.png +0 -0
- package/test/isometric1/foglie.png +0 -0
- package/test/isometric1/grass.png +0 -0
- package/test/isometric1/index.html +17 -0
- package/test/isometric1/index.ts +68 -0
- package/test/isometric1/tronco.png +0 -0
- package/test/isometric1/untitled.tmx +25 -0
- package/test/isometric1/water.png +0 -0
- package/test/isometric2/banner.png +0 -0
- package/test/isometric2/books.png +0 -0
- package/test/isometric2/candlestick.png +0 -0
- package/test/isometric2/ice.png +0 -0
- package/test/isometric2/index.html +16 -0
- package/test/isometric2/index.ts +129 -0
- package/test/isometric2/knight_se.png +0 -0
- package/test/isometric2/tile.png +0 -0
- package/test/isometric2/untitled.tmx +36 -0
- package/test/isometric2/wall.png +0 -0
- package/test/layers/boy.png +0 -0
- package/test/layers/catgirl.png +0 -0
- package/test/layers/fri1.svg +8 -0
- package/test/layers/grassblock.png +0 -0
- package/test/layers/horngirl.png +0 -0
- package/test/layers/index.html +17 -0
- package/test/layers/index.ts +191 -0
- package/test/layers/pinkgirl.png +0 -0
- package/test/layers/render_ruler.py +57 -0
- package/test/layers/ruler.png +0 -0
- package/test/layers/sh.png +0 -0
- package/test/mixer/dieci.opus +0 -0
- package/test/mixer/dieci.wav +0 -0
- package/test/mixer/index.html +33 -0
- package/test/mixer/index.ts +206 -0
- package/test/mixer/news_intro.mp3 +0 -0
- package/test/mixer/news_intro.ogg +0 -0
- package/test/mixer/prova.mp3 +0 -0
- package/test/mixer/prova.ogg +0 -0
- package/test/package-lock.json +515 -0
- package/test/package.json +19 -0
- package/test/sorted/Brown Block.png +0 -0
- package/test/sorted/index.html +16 -0
- package/test/sorted/index.ts +38 -0
- package/test/transformation1/index.html +17 -0
- package/test/transformation1/index.ts +51 -0
- package/test/transformation1/sh.png +0 -0
- package/test/transformation2/index.html +20 -0
- package/test/transformation2/index.ts +71 -0
- package/test/transformation2/sh.png +0 -0
- package/test/tsconfig.json +53 -0
- package/tsconfig.json +51 -0
|
@@ -0,0 +1,536 @@
|
|
|
1
|
+
import { canvasRenderer } from "frigame3/dist/canvasRenderer.js";
|
|
2
|
+
import { Gradient } from "frigame3/dist/Gradient.js";
|
|
3
|
+
import { Playground } from "frigame3/dist/Playground.js";
|
|
4
|
+
import { keyTracker } from "frigame3/dist/plugins/keyTracker.js";
|
|
5
|
+
import { Tilemap } from "frigame3/dist/plugins/Tilemap.js";
|
|
6
|
+
import { Rectangle } from "frigame3/dist/Rectangle.js";
|
|
7
|
+
|
|
8
|
+
const GAME_SPEED = 24;
|
|
9
|
+
const TYPEMATIC_SPEED = 12;
|
|
10
|
+
const TYPEMATIC_DOWN_SPEED = 3;
|
|
11
|
+
|
|
12
|
+
type Piece = "I" | "O" | "J" | "L" | "S" | "Z" | "T" | " ";
|
|
13
|
+
|
|
14
|
+
// tgm3Randomizer function taken from: https://simon.lc/the-history-of-tetris-randomizers
|
|
15
|
+
function* tgm3Randomizer(): Generator<Piece> {
|
|
16
|
+
const pieces: Piece[] = ["I", "J", "L", "O", "S", "T", "Z"];
|
|
17
|
+
const order: Piece[] = [];
|
|
18
|
+
|
|
19
|
+
// Create 35 pool.
|
|
20
|
+
const pool = pieces.concat(pieces, pieces, pieces, pieces);
|
|
21
|
+
|
|
22
|
+
// First piece special conditions
|
|
23
|
+
let piece: Piece = (["I", "J", "L", "T"] as const)[
|
|
24
|
+
Math.floor(Math.random() * 4)
|
|
25
|
+
]!;
|
|
26
|
+
yield piece;
|
|
27
|
+
|
|
28
|
+
const history: Piece[] = ["S", "Z", "S", piece];
|
|
29
|
+
|
|
30
|
+
let i = 0;
|
|
31
|
+
while (true) {
|
|
32
|
+
// Roll For piece
|
|
33
|
+
for (let roll = 0; roll < 6; roll += 1) {
|
|
34
|
+
i = Math.floor(Math.random() * 35);
|
|
35
|
+
piece = pool[i]!;
|
|
36
|
+
|
|
37
|
+
if (history.includes(piece) === false || roll === 5) {
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (order.length !== 0) {
|
|
42
|
+
pool[i] = order[0]!;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Update piece order
|
|
47
|
+
if (order.includes(piece)) {
|
|
48
|
+
order.splice(order.indexOf(piece), 1);
|
|
49
|
+
}
|
|
50
|
+
order.push(piece);
|
|
51
|
+
|
|
52
|
+
pool[i] = order[0]!;
|
|
53
|
+
|
|
54
|
+
// Update history
|
|
55
|
+
history.shift();
|
|
56
|
+
history.push(piece);
|
|
57
|
+
|
|
58
|
+
yield piece;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function clearPiece(
|
|
63
|
+
level: Piece[][],
|
|
64
|
+
block: Piece[][],
|
|
65
|
+
pos_x: number,
|
|
66
|
+
pos_y: number,
|
|
67
|
+
): void {
|
|
68
|
+
for (let y = 0; y < block.length; y += 1) {
|
|
69
|
+
for (let x = 0; x < block.length; x += 1) {
|
|
70
|
+
if (block[y]![x]! !== " ") {
|
|
71
|
+
if (
|
|
72
|
+
pos_y + y >= 0 &&
|
|
73
|
+
pos_y + y < level.length &&
|
|
74
|
+
pos_x + x >= 0 &&
|
|
75
|
+
pos_x + x < level[pos_y + y]!.length
|
|
76
|
+
) {
|
|
77
|
+
level[pos_y + y]![pos_x + x] = " ";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function drawPiece(
|
|
85
|
+
level: Piece[][],
|
|
86
|
+
block: Piece[][],
|
|
87
|
+
pos_x: number,
|
|
88
|
+
pos_y: number,
|
|
89
|
+
): void {
|
|
90
|
+
for (let y = 0; y < block.length; y += 1) {
|
|
91
|
+
for (let x = 0; x < block.length; x += 1) {
|
|
92
|
+
if (block[y]![x]! !== " ") {
|
|
93
|
+
if (
|
|
94
|
+
pos_y + y >= 0 &&
|
|
95
|
+
pos_y + y < level.length &&
|
|
96
|
+
pos_x + x >= 0 &&
|
|
97
|
+
pos_x + x < level[pos_y + y]!.length
|
|
98
|
+
) {
|
|
99
|
+
level[pos_y + y]![pos_x + x] = block[y]![x]!;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
function fitsPiece(
|
|
107
|
+
level: Piece[][],
|
|
108
|
+
block: Piece[][],
|
|
109
|
+
pos_x: number,
|
|
110
|
+
pos_y: number,
|
|
111
|
+
): boolean {
|
|
112
|
+
for (let y = 0; y < block.length; y += 1) {
|
|
113
|
+
for (let x = 0; x < block.length; x += 1) {
|
|
114
|
+
if (block[y]![x]! !== " ") {
|
|
115
|
+
// Out of bounds check
|
|
116
|
+
if (
|
|
117
|
+
pos_y + y < 0 ||
|
|
118
|
+
pos_y + y >= level.length ||
|
|
119
|
+
pos_x + x < 0 ||
|
|
120
|
+
pos_x + x >= level[pos_y + y]!.length
|
|
121
|
+
) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Occupied check
|
|
126
|
+
if (level[pos_y + y]![pos_x + x]! !== " ") {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
return true;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
((): void => {
|
|
137
|
+
const BLOCK_SIZE = 40;
|
|
138
|
+
|
|
139
|
+
const BLOCK_I: Piece[][][] = [
|
|
140
|
+
[
|
|
141
|
+
[" ", " ", " ", " "],
|
|
142
|
+
["I", "I", "I", "I"],
|
|
143
|
+
[" ", " ", " ", " "],
|
|
144
|
+
[" ", " ", " ", " "],
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
[" ", " ", "I", " "],
|
|
148
|
+
[" ", " ", "I", " "],
|
|
149
|
+
[" ", " ", "I", " "],
|
|
150
|
+
[" ", " ", "I", " "],
|
|
151
|
+
],
|
|
152
|
+
];
|
|
153
|
+
|
|
154
|
+
const BLOCK_O: Piece[][][] = [
|
|
155
|
+
[
|
|
156
|
+
["O", "O"],
|
|
157
|
+
["O", "O"],
|
|
158
|
+
],
|
|
159
|
+
];
|
|
160
|
+
|
|
161
|
+
const BLOCK_J: Piece[][][] = [
|
|
162
|
+
[
|
|
163
|
+
[" ", " ", " "],
|
|
164
|
+
["J", "J", "J"],
|
|
165
|
+
[" ", " ", "J"],
|
|
166
|
+
],
|
|
167
|
+
[
|
|
168
|
+
[" ", "J", "J"],
|
|
169
|
+
[" ", "J", " "],
|
|
170
|
+
[" ", "J", " "],
|
|
171
|
+
],
|
|
172
|
+
[
|
|
173
|
+
["J", " ", " "],
|
|
174
|
+
["J", "J", "J"],
|
|
175
|
+
[" ", " ", " "],
|
|
176
|
+
],
|
|
177
|
+
[
|
|
178
|
+
[" ", "J", " "],
|
|
179
|
+
[" ", "J", " "],
|
|
180
|
+
["J", "J", " "],
|
|
181
|
+
],
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
const BLOCK_L: Piece[][][] = [
|
|
185
|
+
[
|
|
186
|
+
[" ", " ", " "],
|
|
187
|
+
["L", "L", "L"],
|
|
188
|
+
["L", " ", " "],
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
[" ", "L", " "],
|
|
192
|
+
[" ", "L", " "],
|
|
193
|
+
[" ", "L", "L"],
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
[" ", " ", "L"],
|
|
197
|
+
["L", "L", "L"],
|
|
198
|
+
[" ", " ", " "],
|
|
199
|
+
],
|
|
200
|
+
[
|
|
201
|
+
["L", "L", " "],
|
|
202
|
+
[" ", "L", " "],
|
|
203
|
+
[" ", "L", " "],
|
|
204
|
+
],
|
|
205
|
+
];
|
|
206
|
+
|
|
207
|
+
const BLOCK_S: Piece[][][] = [
|
|
208
|
+
[
|
|
209
|
+
[" ", " ", " "],
|
|
210
|
+
[" ", "S", "S"],
|
|
211
|
+
["S", "S", " "],
|
|
212
|
+
],
|
|
213
|
+
[
|
|
214
|
+
[" ", "S", " "],
|
|
215
|
+
[" ", "S", "S"],
|
|
216
|
+
[" ", " ", "S"],
|
|
217
|
+
],
|
|
218
|
+
];
|
|
219
|
+
|
|
220
|
+
const BLOCK_Z: Piece[][][] = [
|
|
221
|
+
[
|
|
222
|
+
[" ", " ", " "],
|
|
223
|
+
["Z", "Z", " "],
|
|
224
|
+
[" ", "Z", "Z"],
|
|
225
|
+
],
|
|
226
|
+
[
|
|
227
|
+
[" ", "Z", " "],
|
|
228
|
+
["Z", "Z", " "],
|
|
229
|
+
["Z", " ", " "],
|
|
230
|
+
],
|
|
231
|
+
];
|
|
232
|
+
|
|
233
|
+
const BLOCK_T: Piece[][][] = [
|
|
234
|
+
[
|
|
235
|
+
[" ", " ", " "],
|
|
236
|
+
["T", "T", "T"],
|
|
237
|
+
[" ", "T", " "],
|
|
238
|
+
],
|
|
239
|
+
[
|
|
240
|
+
[" ", "T", " "],
|
|
241
|
+
[" ", "T", "T"],
|
|
242
|
+
[" ", "T", " "],
|
|
243
|
+
],
|
|
244
|
+
[
|
|
245
|
+
[" ", "T", " "],
|
|
246
|
+
["T", "T", "T"],
|
|
247
|
+
[" ", " ", " "],
|
|
248
|
+
],
|
|
249
|
+
[
|
|
250
|
+
[" ", "T", " "],
|
|
251
|
+
["T", "T", " "],
|
|
252
|
+
[" ", "T", " "],
|
|
253
|
+
],
|
|
254
|
+
];
|
|
255
|
+
|
|
256
|
+
const BLOCKS: Record<Piece, Piece[][][]> = {
|
|
257
|
+
I: BLOCK_I,
|
|
258
|
+
O: BLOCK_O,
|
|
259
|
+
J: BLOCK_J,
|
|
260
|
+
L: BLOCK_L,
|
|
261
|
+
S: BLOCK_S,
|
|
262
|
+
Z: BLOCK_Z,
|
|
263
|
+
T: BLOCK_T,
|
|
264
|
+
" ": [[[]]],
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const COLOURS: Record<Piece, Gradient> = {
|
|
268
|
+
I: new Gradient([0, 176, 220]),
|
|
269
|
+
O: new Gradient([253, 214, 49]),
|
|
270
|
+
J: new Gradient([0, 116, 197]),
|
|
271
|
+
L: new Gradient([255, 161, 18]),
|
|
272
|
+
S: new Gradient([113, 209, 37]),
|
|
273
|
+
Z: new Gradient([240, 65, 72]),
|
|
274
|
+
T: new Gradient([148, 45, 154]),
|
|
275
|
+
" ": new Gradient([28, 28, 28]),
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
// NES Tetris is 10x20 blocks
|
|
279
|
+
const level: Piece[][] = [
|
|
280
|
+
Array(10).fill(" "),
|
|
281
|
+
Array(10).fill(" "),
|
|
282
|
+
Array(10).fill(" "),
|
|
283
|
+
Array(10).fill(" "),
|
|
284
|
+
Array(10).fill(" "),
|
|
285
|
+
Array(10).fill(" "),
|
|
286
|
+
Array(10).fill(" "),
|
|
287
|
+
Array(10).fill(" "),
|
|
288
|
+
Array(10).fill(" "),
|
|
289
|
+
Array(10).fill(" "),
|
|
290
|
+
Array(10).fill(" "),
|
|
291
|
+
Array(10).fill(" "),
|
|
292
|
+
Array(10).fill(" "),
|
|
293
|
+
Array(10).fill(" "),
|
|
294
|
+
Array(10).fill(" "),
|
|
295
|
+
Array(10).fill(" "),
|
|
296
|
+
Array(10).fill(" "),
|
|
297
|
+
Array(10).fill(" "),
|
|
298
|
+
Array(10).fill(" "),
|
|
299
|
+
Array(10).fill(" "),
|
|
300
|
+
];
|
|
301
|
+
|
|
302
|
+
const playground = new Playground(canvasRenderer);
|
|
303
|
+
const sg = playground.scenegraph;
|
|
304
|
+
|
|
305
|
+
// box
|
|
306
|
+
sg.addChild(
|
|
307
|
+
new Rectangle({
|
|
308
|
+
centerx: sg.width / 2,
|
|
309
|
+
centery: sg.centery,
|
|
310
|
+
width: 10 * BLOCK_SIZE,
|
|
311
|
+
height: 20 * BLOCK_SIZE,
|
|
312
|
+
borderWidth: BLOCK_SIZE,
|
|
313
|
+
borderColor: [128, 128, 128],
|
|
314
|
+
}),
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
const content = sg.addChild(
|
|
318
|
+
new Tilemap({
|
|
319
|
+
centerx: sg.width / 2,
|
|
320
|
+
centery: sg.centery,
|
|
321
|
+
sizex: 10,
|
|
322
|
+
sizey: 20,
|
|
323
|
+
tileWidth: BLOCK_SIZE,
|
|
324
|
+
tileHeight: BLOCK_SIZE,
|
|
325
|
+
data: Array(10 * 20).fill(1),
|
|
326
|
+
animationList: { 1: { background: COLOURS[" "] } },
|
|
327
|
+
}),
|
|
328
|
+
);
|
|
329
|
+
|
|
330
|
+
// preview_box
|
|
331
|
+
sg.addChild(
|
|
332
|
+
new Rectangle({
|
|
333
|
+
centerx: (sg.width * 3) / 4,
|
|
334
|
+
centery: sg.height / 3,
|
|
335
|
+
width: 6 * BLOCK_SIZE,
|
|
336
|
+
height: 6 * BLOCK_SIZE,
|
|
337
|
+
borderWidth: BLOCK_SIZE,
|
|
338
|
+
borderColor: [128, 128, 128],
|
|
339
|
+
}),
|
|
340
|
+
);
|
|
341
|
+
|
|
342
|
+
const preview = sg.addChild(
|
|
343
|
+
new Tilemap({
|
|
344
|
+
centerx: (sg.width * 3) / 4,
|
|
345
|
+
centery: sg.height / 3,
|
|
346
|
+
sizex: 6,
|
|
347
|
+
sizey: 6,
|
|
348
|
+
tileWidth: BLOCK_SIZE,
|
|
349
|
+
tileHeight: BLOCK_SIZE,
|
|
350
|
+
data: Array(6 * 6).fill(1),
|
|
351
|
+
animationList: { 1: { background: COLOURS[" "] } },
|
|
352
|
+
}),
|
|
353
|
+
);
|
|
354
|
+
|
|
355
|
+
const preview_pieces: Piece[][] = [
|
|
356
|
+
Array(6).fill(" "),
|
|
357
|
+
Array(6).fill(" "),
|
|
358
|
+
Array(6).fill(" "),
|
|
359
|
+
Array(6).fill(" "),
|
|
360
|
+
Array(6).fill(" "),
|
|
361
|
+
Array(6).fill(" "),
|
|
362
|
+
];
|
|
363
|
+
|
|
364
|
+
let delay_counter = GAME_SPEED;
|
|
365
|
+
const gen = tgm3Randomizer();
|
|
366
|
+
let piece: Piece = gen.next().value;
|
|
367
|
+
let next_piece: Piece = gen.next().value;
|
|
368
|
+
let rotation = 0;
|
|
369
|
+
let block = BLOCKS[piece]![rotation]!;
|
|
370
|
+
let next_block = BLOCKS[next_piece]![0]!;
|
|
371
|
+
let pos_x = Math.floor(5 - block.length / 2);
|
|
372
|
+
let pos_y = 0;
|
|
373
|
+
|
|
374
|
+
drawPiece(preview_pieces, next_block, 1, 1);
|
|
375
|
+
|
|
376
|
+
for (let y = 0; y < block.length; y += 1) {
|
|
377
|
+
for (let x = 0; x < block.length; x += 1) {
|
|
378
|
+
if (block[y]![x]! !== " ") {
|
|
379
|
+
if (
|
|
380
|
+
pos_y + y >= 0 &&
|
|
381
|
+
pos_y + y < level.length &&
|
|
382
|
+
pos_x + x >= 0 &&
|
|
383
|
+
pos_x + x < level[pos_y + y]!.length
|
|
384
|
+
) {
|
|
385
|
+
level[pos_y + y]![pos_x + x] = block[y]![x]!;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
let typematic_left = 0;
|
|
392
|
+
let typematic_right = 0;
|
|
393
|
+
let old_up = true;
|
|
394
|
+
let typematic_down = 0;
|
|
395
|
+
let paused = false;
|
|
396
|
+
let old_p = false;
|
|
397
|
+
playground.registerCallback(() => {
|
|
398
|
+
if (keyTracker["KeyP"] === true && !old_p) {
|
|
399
|
+
paused = !paused;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
old_p = keyTracker["KeyP"] ?? false;
|
|
403
|
+
|
|
404
|
+
if (paused) {
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Process inputs at every frame to be responsive
|
|
409
|
+
if (keyTracker["ArrowLeft"] === true) {
|
|
410
|
+
if (typematic_left === 0) {
|
|
411
|
+
typematic_left = TYPEMATIC_SPEED;
|
|
412
|
+
clearPiece(level, block, pos_x, pos_y);
|
|
413
|
+
|
|
414
|
+
if (fitsPiece(level, block, pos_x - 1, pos_y)) {
|
|
415
|
+
pos_x -= 1;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
drawPiece(level, block, pos_x, pos_y);
|
|
419
|
+
} else {
|
|
420
|
+
if (typematic_left > 0) {
|
|
421
|
+
typematic_left -= 1;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
} else {
|
|
425
|
+
typematic_left = 0;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
if (keyTracker["ArrowRight"] === true) {
|
|
429
|
+
if (typematic_right === 0) {
|
|
430
|
+
typematic_right = TYPEMATIC_SPEED;
|
|
431
|
+
clearPiece(level, block, pos_x, pos_y);
|
|
432
|
+
|
|
433
|
+
if (fitsPiece(level, block, pos_x + 1, pos_y)) {
|
|
434
|
+
pos_x += 1;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
drawPiece(level, block, pos_x, pos_y);
|
|
438
|
+
} else {
|
|
439
|
+
if (typematic_right > 0) {
|
|
440
|
+
typematic_right -= 1;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
} else {
|
|
444
|
+
typematic_right = 0;
|
|
445
|
+
}
|
|
446
|
+
if (keyTracker["ArrowUp"] === true && !old_up) {
|
|
447
|
+
clearPiece(level, block, pos_x, pos_y);
|
|
448
|
+
|
|
449
|
+
const new_rotation = (rotation + 1) % BLOCKS[piece].length;
|
|
450
|
+
const new_block = BLOCKS[piece]![new_rotation]!;
|
|
451
|
+
if (fitsPiece(level, new_block, pos_x, pos_y)) {
|
|
452
|
+
rotation = new_rotation;
|
|
453
|
+
block = new_block;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
drawPiece(level, block, pos_x, pos_y);
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
old_up = keyTracker["ArrowUp"] ?? false;
|
|
460
|
+
|
|
461
|
+
if (keyTracker["ArrowDown"] === true) {
|
|
462
|
+
if (typematic_down === 0) {
|
|
463
|
+
typematic_down = TYPEMATIC_DOWN_SPEED;
|
|
464
|
+
delay_counter = 0;
|
|
465
|
+
} else {
|
|
466
|
+
if (typematic_down > 0) {
|
|
467
|
+
typematic_down -= 1;
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
} else {
|
|
471
|
+
typematic_down = 0;
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
delay_counter -= 1;
|
|
475
|
+
if (delay_counter <= 0) {
|
|
476
|
+
delay_counter = GAME_SPEED;
|
|
477
|
+
|
|
478
|
+
clearPiece(level, block, pos_x, pos_y);
|
|
479
|
+
|
|
480
|
+
if (fitsPiece(level, block, pos_x, pos_y + 1)) {
|
|
481
|
+
pos_y += 1;
|
|
482
|
+
} else {
|
|
483
|
+
drawPiece(level, block, pos_x, pos_y);
|
|
484
|
+
|
|
485
|
+
// Delete cleared lines
|
|
486
|
+
for (let y = level.length - 1; y >= 0; y -= 1) {
|
|
487
|
+
if (!level[y]!.includes(" ")) {
|
|
488
|
+
level.splice(y, 1);
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const lines_to_add = 20 - level.length;
|
|
492
|
+
for (let i = 0; i < lines_to_add; i += 1) {
|
|
493
|
+
level.unshift(Array(10).fill(" "));
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Next piece
|
|
497
|
+
clearPiece(preview_pieces, next_block, 1, 1);
|
|
498
|
+
piece = next_piece;
|
|
499
|
+
next_piece = gen.next().value;
|
|
500
|
+
rotation = 0;
|
|
501
|
+
block = BLOCKS[piece]![rotation]!;
|
|
502
|
+
next_block = BLOCKS[next_piece]![0]!;
|
|
503
|
+
pos_x = Math.floor(5 - block.length / 2);
|
|
504
|
+
pos_y = 0;
|
|
505
|
+
if (!fitsPiece(level, block, pos_x, pos_y)) {
|
|
506
|
+
// TODO: GAME OVER
|
|
507
|
+
playground.stopGame();
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
drawPiece(preview_pieces, next_block, 1, 1);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
drawPiece(level, block, pos_x, pos_y);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// Draw the level
|
|
517
|
+
for (let y = 0; y < 20; y += 1) {
|
|
518
|
+
for (let x = 0; x < 10; x += 1) {
|
|
519
|
+
const tile = content.getAt(y, x)!;
|
|
520
|
+
if ("background" in tile) {
|
|
521
|
+
tile.background = COLOURS[level[y]![x]!]!;
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// Draw the preview
|
|
527
|
+
for (let y = 0; y < 6; y += 1) {
|
|
528
|
+
for (let x = 0; x < 6; x += 1) {
|
|
529
|
+
const tile = preview.getAt(y, x)!;
|
|
530
|
+
if ("background" in tile) {
|
|
531
|
+
tile.background = COLOURS[preview_pieces[y]![x]!]!;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
})();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
// "rootDir": "./src",
|
|
6
|
+
// "outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
"types": [],
|
|
13
|
+
// For nodejs:
|
|
14
|
+
// "lib": ["esnext"],
|
|
15
|
+
// "types": ["node"],
|
|
16
|
+
// and npm install -D @types/node
|
|
17
|
+
|
|
18
|
+
// Other Outputs
|
|
19
|
+
// "sourceMap": true,
|
|
20
|
+
// "declaration": true,
|
|
21
|
+
// "declarationMap": true,
|
|
22
|
+
"noEmit": true,
|
|
23
|
+
|
|
24
|
+
// Stricter Typechecking Options
|
|
25
|
+
"noUncheckedIndexedAccess": true,
|
|
26
|
+
"exactOptionalPropertyTypes": true,
|
|
27
|
+
|
|
28
|
+
// Style Options
|
|
29
|
+
"noImplicitReturns": true,
|
|
30
|
+
"noImplicitOverride": true,
|
|
31
|
+
"noUnusedLocals": true,
|
|
32
|
+
"noUnusedParameters": true,
|
|
33
|
+
"noFallthroughCasesInSwitch": true,
|
|
34
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
35
|
+
|
|
36
|
+
// Recommended Options
|
|
37
|
+
"strict": true,
|
|
38
|
+
"jsx": "react-jsx",
|
|
39
|
+
"verbatimModuleSyntax": true,
|
|
40
|
+
"isolatedModules": true,
|
|
41
|
+
"noUncheckedSideEffectImports": true,
|
|
42
|
+
"moduleDetection": "force",
|
|
43
|
+
"skipLibCheck": true,
|
|
44
|
+
|
|
45
|
+
// Customizations
|
|
46
|
+
"allowUnreachableCode": false,
|
|
47
|
+
"allowUnusedLabels": false,
|
|
48
|
+
"erasableSyntaxOnly": true,
|
|
49
|
+
// "isolatedDeclarations": true,
|
|
50
|
+
},
|
|
51
|
+
"include": ["./**/*"],
|
|
52
|
+
"exclude": ["node_modules"]
|
|
53
|
+
}
|
package/frigame.css
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "frigame3",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"description": "A blazingly fast 2D game development library",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "biome format --write src && tsc && biome check src",
|
|
9
|
+
"prepare": "tsc",
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/bugnano/frigame3.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"2d",
|
|
18
|
+
"canvas",
|
|
19
|
+
"game",
|
|
20
|
+
"gamedev",
|
|
21
|
+
"animation",
|
|
22
|
+
"sprite",
|
|
23
|
+
"sound",
|
|
24
|
+
"sfx",
|
|
25
|
+
"music",
|
|
26
|
+
"mixer",
|
|
27
|
+
"keyboard",
|
|
28
|
+
"gamepad",
|
|
29
|
+
"vector",
|
|
30
|
+
"math",
|
|
31
|
+
"vec2",
|
|
32
|
+
"vec2d",
|
|
33
|
+
"isometric",
|
|
34
|
+
"tile",
|
|
35
|
+
"tilemap",
|
|
36
|
+
"map",
|
|
37
|
+
"easing",
|
|
38
|
+
"tween",
|
|
39
|
+
"shake",
|
|
40
|
+
"shaker"
|
|
41
|
+
],
|
|
42
|
+
"author": "Franco Bugnano",
|
|
43
|
+
"license": "MPL-2.0",
|
|
44
|
+
"bugs": {
|
|
45
|
+
"url": "https://github.com/bugnano/frigame3/issues"
|
|
46
|
+
},
|
|
47
|
+
"homepage": "https://frigame.org/",
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@biomejs/biome": "2.6.9",
|
|
50
|
+
"typescript": "^7.0.2"
|
|
51
|
+
}
|
|
52
|
+
}
|