frigame3 3.0.0 → 3.0.1

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.
Files changed (180) hide show
  1. package/dist/Animation.d.ts +42 -0
  2. package/dist/Animation.js +189 -0
  3. package/dist/BaseSprite.d.ts +116 -0
  4. package/dist/BaseSprite.js +518 -0
  5. package/dist/Gradient.d.ts +31 -0
  6. package/dist/Gradient.js +89 -0
  7. package/dist/Playground.d.ts +48 -0
  8. package/dist/Playground.js +167 -0
  9. package/dist/Rect.d.ts +63 -0
  10. package/dist/Rect.js +155 -0
  11. package/dist/Rectangle.d.ts +31 -0
  12. package/dist/Rectangle.js +69 -0
  13. package/dist/Renderer.d.ts +23 -0
  14. package/dist/Renderer.js +1 -0
  15. package/dist/ResourceManager.d.ts +21 -0
  16. package/dist/ResourceManager.js +100 -0
  17. package/dist/Sprite.d.ts +56 -0
  18. package/dist/Sprite.js +437 -0
  19. package/dist/SpriteGroup.d.ts +39 -0
  20. package/dist/SpriteGroup.js +176 -0
  21. package/dist/canvasRenderer/renderGroup.d.ts +15 -0
  22. package/dist/canvasRenderer/renderGroup.js +134 -0
  23. package/dist/canvasRenderer/renderPlayground.d.ts +9 -0
  24. package/dist/canvasRenderer/renderPlayground.js +67 -0
  25. package/dist/canvasRenderer/renderRectangle.d.ts +15 -0
  26. package/dist/canvasRenderer/renderRectangle.js +287 -0
  27. package/dist/canvasRenderer/renderSprite.d.ts +4 -0
  28. package/dist/canvasRenderer/renderSprite.js +93 -0
  29. package/dist/canvasRenderer.d.ts +2 -0
  30. package/dist/canvasRenderer.js +19 -0
  31. package/dist/dummyRenderer.d.ts +2 -0
  32. package/dist/dummyRenderer.js +41 -0
  33. package/dist/plugins/GamepadTracker.d.ts +15 -0
  34. package/dist/plugins/GamepadTracker.js +74 -0
  35. package/dist/plugins/Tilemap.d.ts +26 -0
  36. package/dist/plugins/Tilemap.js +85 -0
  37. package/dist/plugins/Vec2.d.ts +69 -0
  38. package/dist/plugins/Vec2.js +296 -0
  39. package/dist/plugins/fx/Shaker.d.ts +46 -0
  40. package/dist/plugins/fx/Shaker.js +190 -0
  41. package/dist/plugins/fx/Tweener.d.ts +42 -0
  42. package/dist/plugins/fx/Tweener.js +166 -0
  43. package/dist/plugins/fx/easing.d.ts +32 -0
  44. package/dist/plugins/fx/easing.js +192 -0
  45. package/dist/plugins/isometric/ISOMixin.d.ts +138 -0
  46. package/dist/plugins/isometric/ISOMixin.js +322 -0
  47. package/dist/plugins/isometric/ISORectangle.d.ts +151 -0
  48. package/dist/plugins/isometric/ISORectangle.js +127 -0
  49. package/dist/plugins/isometric/ISOSprite.d.ts +157 -0
  50. package/dist/plugins/isometric/ISOSprite.js +176 -0
  51. package/dist/plugins/isometric/ISOSpriteGroup.d.ts +151 -0
  52. package/dist/plugins/isometric/ISOSpriteGroup.js +116 -0
  53. package/dist/plugins/isometric/ISOTilemap.d.ts +24 -0
  54. package/dist/plugins/isometric/ISOTilemap.js +85 -0
  55. package/dist/plugins/isometric/utils.d.ts +2 -0
  56. package/dist/plugins/isometric/utils.js +10 -0
  57. package/dist/plugins/keyTracker.d.ts +3 -0
  58. package/dist/plugins/keyTracker.js +23 -0
  59. package/dist/plugins/mixer.d.ts +72 -0
  60. package/dist/plugins/mixer.js +396 -0
  61. package/dist/plugins/sorted/SortedAnimation.d.ts +13 -0
  62. package/dist/plugins/sorted/SortedAnimation.js +27 -0
  63. package/dist/plugins/sorted/SortedGroup.d.ts +137 -0
  64. package/dist/plugins/sorted/SortedGroup.js +61 -0
  65. package/dist/plugins/sorted/SortedMixin.d.ts +122 -0
  66. package/dist/plugins/sorted/SortedMixin.js +153 -0
  67. package/dist/plugins/sorted/SortedRectangle.d.ts +127 -0
  68. package/dist/plugins/sorted/SortedRectangle.js +17 -0
  69. package/dist/plugins/sorted/SortedSprite.d.ts +130 -0
  70. package/dist/plugins/sorted/SortedSprite.js +35 -0
  71. package/dist/utils.d.ts +11 -0
  72. package/dist/utils.js +33 -0
  73. package/package.json +6 -2
  74. package/CHANGELOG.md +0 -13
  75. package/biome.json +0 -93
  76. package/demo/package-lock.json +0 -515
  77. package/demo/package.json +0 -19
  78. package/demo/snake/index.html +0 -16
  79. package/demo/snake/index.ts +0 -110
  80. package/demo/tetris/index.html +0 -16
  81. package/demo/tetris/index.ts +0 -536
  82. package/demo/tsconfig.json +0 -53
  83. package/src/Animation.ts +0 -266
  84. package/src/BaseSprite.ts +0 -682
  85. package/src/Gradient.ts +0 -120
  86. package/src/Playground.ts +0 -247
  87. package/src/Rect.ts +0 -237
  88. package/src/Rectangle.ts +0 -108
  89. package/src/Renderer.ts +0 -28
  90. package/src/ResourceManager.ts +0 -145
  91. package/src/Sprite.ts +0 -484
  92. package/src/SpriteGroup.ts +0 -258
  93. package/src/canvasRenderer/renderGroup.ts +0 -194
  94. package/src/canvasRenderer/renderPlayground.ts +0 -103
  95. package/src/canvasRenderer/renderRectangle.ts +0 -421
  96. package/src/canvasRenderer/renderSprite.ts +0 -148
  97. package/src/canvasRenderer.ts +0 -38
  98. package/src/dummyRenderer.ts +0 -62
  99. package/src/plugins/GamepadTracker.ts +0 -97
  100. package/src/plugins/Tilemap.ts +0 -123
  101. package/src/plugins/Vec2.ts +0 -420
  102. package/src/plugins/fx/Shaker.ts +0 -293
  103. package/src/plugins/fx/Tweener.ts +0 -252
  104. package/src/plugins/fx/easing.ts +0 -276
  105. package/src/plugins/isometric/ISOMixin.ts +0 -444
  106. package/src/plugins/isometric/ISORectangle.ts +0 -183
  107. package/src/plugins/isometric/ISOSprite.ts +0 -228
  108. package/src/plugins/isometric/ISOSpriteGroup.ts +0 -155
  109. package/src/plugins/isometric/ISOTilemap.ts +0 -122
  110. package/src/plugins/isometric/utils.ts +0 -19
  111. package/src/plugins/keyTracker.ts +0 -31
  112. package/src/plugins/mixer.ts +0 -523
  113. package/src/plugins/sorted/SortedAnimation.ts +0 -53
  114. package/src/plugins/sorted/SortedGroup.ts +0 -94
  115. package/src/plugins/sorted/SortedMixin.ts +0 -203
  116. package/src/plugins/sorted/SortedRectangle.ts +0 -35
  117. package/src/plugins/sorted/SortedSprite.ts +0 -56
  118. package/src/utils.ts +0 -53
  119. package/test/animation/index.html +0 -20
  120. package/test/animation/index.ts +0 -253
  121. package/test/animation/mh.png +0 -0
  122. package/test/animation/moh.png +0 -0
  123. package/test/animation/mov.png +0 -0
  124. package/test/animation/mv.png +0 -0
  125. package/test/animation/rebound.png +0 -0
  126. package/test/animation/reboundm.png +0 -0
  127. package/test/animation/sh.png +0 -0
  128. package/test/animation/soh.png +0 -0
  129. package/test/animation/sov.png +0 -0
  130. package/test/animation/sv.png +0 -0
  131. package/test/isometric1/beach.png +0 -0
  132. package/test/isometric1/foglie.png +0 -0
  133. package/test/isometric1/grass.png +0 -0
  134. package/test/isometric1/index.html +0 -17
  135. package/test/isometric1/index.ts +0 -68
  136. package/test/isometric1/tronco.png +0 -0
  137. package/test/isometric1/untitled.tmx +0 -25
  138. package/test/isometric1/water.png +0 -0
  139. package/test/isometric2/banner.png +0 -0
  140. package/test/isometric2/books.png +0 -0
  141. package/test/isometric2/candlestick.png +0 -0
  142. package/test/isometric2/ice.png +0 -0
  143. package/test/isometric2/index.html +0 -16
  144. package/test/isometric2/index.ts +0 -129
  145. package/test/isometric2/knight_se.png +0 -0
  146. package/test/isometric2/tile.png +0 -0
  147. package/test/isometric2/untitled.tmx +0 -36
  148. package/test/isometric2/wall.png +0 -0
  149. package/test/layers/boy.png +0 -0
  150. package/test/layers/catgirl.png +0 -0
  151. package/test/layers/fri1.svg +0 -8
  152. package/test/layers/grassblock.png +0 -0
  153. package/test/layers/horngirl.png +0 -0
  154. package/test/layers/index.html +0 -17
  155. package/test/layers/index.ts +0 -191
  156. package/test/layers/pinkgirl.png +0 -0
  157. package/test/layers/render_ruler.py +0 -57
  158. package/test/layers/ruler.png +0 -0
  159. package/test/layers/sh.png +0 -0
  160. package/test/mixer/dieci.opus +0 -0
  161. package/test/mixer/dieci.wav +0 -0
  162. package/test/mixer/index.html +0 -33
  163. package/test/mixer/index.ts +0 -206
  164. package/test/mixer/news_intro.mp3 +0 -0
  165. package/test/mixer/news_intro.ogg +0 -0
  166. package/test/mixer/prova.mp3 +0 -0
  167. package/test/mixer/prova.ogg +0 -0
  168. package/test/package-lock.json +0 -515
  169. package/test/package.json +0 -19
  170. package/test/sorted/Brown Block.png +0 -0
  171. package/test/sorted/index.html +0 -16
  172. package/test/sorted/index.ts +0 -38
  173. package/test/transformation1/index.html +0 -17
  174. package/test/transformation1/index.ts +0 -51
  175. package/test/transformation1/sh.png +0 -0
  176. package/test/transformation2/index.html +0 -20
  177. package/test/transformation2/index.ts +0 -71
  178. package/test/transformation2/sh.png +0 -0
  179. package/test/tsconfig.json +0 -53
  180. package/tsconfig.json +0 -51
@@ -1,110 +0,0 @@
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 { Tweener } from "frigame3/dist/plugins/fx/Tweener.js";
5
- import { keyTracker } from "frigame3/dist/plugins/keyTracker.js";
6
- import { Rectangle } from "frigame3/dist/Rectangle.js";
7
-
8
- ((): void => {
9
- const green = new Gradient({ g: 128 });
10
- const red = new Gradient({ r: 240 });
11
- const playground = new Playground(canvasRenderer);
12
- const sg = playground.scenegraph;
13
-
14
- const fx = new Tweener(playground);
15
- const endTween = (): void => {
16
- fx.tween(
17
- green.startColor,
18
- {
19
- r: Math.random() * 256,
20
- g: 128 + Math.random() * 128,
21
- b: Math.random() * 256,
22
- },
23
- { callback: endTween },
24
- );
25
- };
26
- endTween();
27
-
28
- const rect_size = 40;
29
- const max_x = Math.trunc(playground.width / rect_size);
30
- const max_y = Math.trunc(playground.height / rect_size);
31
- const snake: Rectangle[] = [];
32
- const apple = sg.addChild(
33
- new Rectangle({
34
- left: (1 + Math.trunc(Math.random() * (max_x - 2))) * rect_size,
35
- top: (1 + Math.trunc(Math.random() * (max_y - 2))) * rect_size,
36
- width: rect_size,
37
- height: rect_size,
38
- background: red,
39
- }),
40
- );
41
- let x = Math.trunc(max_x / 2);
42
- let y = Math.trunc(max_y / 2);
43
- let snake_length = 3;
44
- let add_x = 1;
45
- let add_y = 0;
46
-
47
- playground.registerCallback(() => {
48
- // Process inputs at every frame to be responsive
49
- if (keyTracker["ArrowLeft"] === true && add_x === 0) {
50
- add_x = -1;
51
- add_y = 0;
52
- }
53
- if (keyTracker["ArrowRight"] === true && add_x === 0) {
54
- add_x = 1;
55
- add_y = 0;
56
- }
57
- if (keyTracker["ArrowUp"] === true && add_y === 0) {
58
- add_x = 0;
59
- add_y = -1;
60
- }
61
- if (keyTracker["ArrowDown"] === true && add_y === 0) {
62
- add_x = 0;
63
- add_y = 1;
64
- }
65
- });
66
-
67
- playground.registerCallback(() => {
68
- // Process game logic at 100ms intervals
69
- x += add_x;
70
- y += add_y;
71
-
72
- if (x < 0 || x >= max_x || y < 0 || y >= max_y) {
73
- console.log("Out of bounds");
74
- playground.stopGame();
75
- playground.clearCallbacks();
76
- }
77
-
78
- let r: Rectangle;
79
- if (snake.length < snake_length) {
80
- r = sg.insertChild(
81
- new Rectangle({
82
- left: x * rect_size,
83
- top: y * rect_size,
84
- width: rect_size,
85
- height: rect_size,
86
- background: green,
87
- }),
88
- );
89
- } else {
90
- r = snake.shift()!;
91
- r.left = x * rect_size;
92
- r.top = y * rect_size;
93
- r.teleport();
94
- }
95
- for (const s of snake) {
96
- if (r.collideRect(s)) {
97
- console.log("Snake crashed into itself");
98
- playground.stopGame();
99
- playground.clearCallbacks();
100
- }
101
- }
102
- if (r.collideRect(apple)) {
103
- snake_length += 3;
104
- apple.left = (1 + Math.trunc(Math.random() * (max_x - 2))) * rect_size;
105
- apple.top = (1 + Math.trunc(Math.random() * (max_y - 2))) * rect_size;
106
- apple.teleport();
107
- }
108
- snake.push(r);
109
- }, 100);
110
- })();
@@ -1,16 +0,0 @@
1
- <!doctype html>
2
- <html lang="en">
3
- <head>
4
- <meta charset="UTF-8">
5
-
6
- <link rel="stylesheet" type="text/css" href="../../frigame.css">
7
- </head>
8
- <body style="position: relative;">
9
- <div
10
- id="playground"
11
- style="position: relative; width: 1920px; height: 1080px; background: black;"
12
- ></div>
13
-
14
- <script src="bundle.js"></script>
15
- </body>
16
- </html>
@@ -1,536 +0,0 @@
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
- })();
@@ -1,53 +0,0 @@
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
- }