thrunium 0.0.0-stage → 1.2.0-rc.2
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/README.md +198 -2
- package/dist/cli.mjs +1150 -0
- package/dist/thrunium-global.mjs +20 -0
- package/dist/thrunium.js +2241 -0
- package/dist/thrunium.min.js +3 -0
- package/dist/thrunium.min.js.map +7 -0
- package/dist/thrunium.mjs +2 -0
- package/dist/types/ajax.d.ts +47 -0
- package/dist/types/collider.d.ts +130 -0
- package/dist/types/elem.d.ts +241 -0
- package/dist/types/env.d.ts +78 -0
- package/dist/types/game.d.ts +702 -0
- package/dist/types/namespace.d.ts +40 -0
- package/dist/types/reference.d.ts +52 -0
- package/dist/types/sprite.d.ts +348 -0
- package/dist/types/storage-token.d.ts +20 -0
- package/dist/types/storage.d.ts +38 -0
- package/dist/types/vector.d.ts +295 -0
- package/package.json +62 -4
- package/templates/js/game.js +17 -0
- package/templates/js/game.json +1 -0
- package/templates/js/gitignore +2 -0
- package/templates/js/package.json +13 -0
- package/templates/pnpm/pnpm-workspace.yaml +4 -0
- package/templates/ts/game.json +1 -0
- package/templates/ts/game.ts +17 -0
- package/templates/ts/gitignore +2 -0
- package/templates/ts/package.json +14 -0
- package/templates/ts/tsconfig.json +12 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
/** Handler signature shared by the user-assignable event fields without a more specific event type. */
|
|
2
|
+
export type Handler = (evt: Event) => void;
|
|
3
|
+
/** An asset given as an object: the file, the key to store it under and an optional sprite map. */
|
|
4
|
+
export type AssetEntry = {
|
|
5
|
+
src: string;
|
|
6
|
+
index: string;
|
|
7
|
+
spriteMap?: {
|
|
8
|
+
width: number;
|
|
9
|
+
height: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* The core of Thrunium: a game owns a `<canvas>`, a 2d context, a game loop and
|
|
14
|
+
* the standard input events. Construct it with `new THRUNIUM.Game(width, height)`,
|
|
15
|
+
* assign your `assets`, event handlers and `states`, then call `init()` and
|
|
16
|
+
* `start()`. Use it to draw on the canvas, load images and audio, and react to
|
|
17
|
+
* mouse, touch, keyboard and device events.
|
|
18
|
+
*/
|
|
19
|
+
export declare class Game {
|
|
20
|
+
[Symbol.toStringTag]: string;
|
|
21
|
+
/**
|
|
22
|
+
* Width of the game in pixels, as passed to the constructor. Read-only: changing it does not resize the canvas.
|
|
23
|
+
*
|
|
24
|
+
* @category Variables
|
|
25
|
+
* @example
|
|
26
|
+
* ```js
|
|
27
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
28
|
+
* game.width; // 400
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
width: number;
|
|
32
|
+
/**
|
|
33
|
+
* Height of the game in pixels, as passed to the constructor. Read-only: changing it does not resize the canvas.
|
|
34
|
+
*
|
|
35
|
+
* @category Variables
|
|
36
|
+
* @example
|
|
37
|
+
* ```js
|
|
38
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
39
|
+
* game.height; // 400
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
height: number;
|
|
43
|
+
/**
|
|
44
|
+
* Density of real canvas pixels per game pixel (device pixel ratio times `fitScale`). Adjusted automatically to keep the game sharp. Read-only.
|
|
45
|
+
*
|
|
46
|
+
* @category Variables
|
|
47
|
+
* @example
|
|
48
|
+
* ```js
|
|
49
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
50
|
+
* game.scale;
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
scale: number;
|
|
54
|
+
/**
|
|
55
|
+
* How much the game is scaled to fit the browser window. Adjusted automatically when the window is resized. Read-only.
|
|
56
|
+
*
|
|
57
|
+
* @category Variables
|
|
58
|
+
* @example
|
|
59
|
+
* ```js
|
|
60
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
61
|
+
* game.fitScale;
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
fitScale: number;
|
|
65
|
+
/**
|
|
66
|
+
* The game's `<canvas>` element. All normal canvas properties and methods are available on it.
|
|
67
|
+
*
|
|
68
|
+
* @category Variables
|
|
69
|
+
* @example
|
|
70
|
+
* ```js
|
|
71
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
72
|
+
* game.canvas.style.cursor = 'pointer';
|
|
73
|
+
* ```
|
|
74
|
+
*/
|
|
75
|
+
canvas: HTMLCanvasElement;
|
|
76
|
+
/**
|
|
77
|
+
* The canvas's 2d rendering context. All normal context methods are available on it. Canvas state such as `lineWidth` persists between draw calls until changed.
|
|
78
|
+
*
|
|
79
|
+
* @category Variables
|
|
80
|
+
* @example
|
|
81
|
+
* ```js
|
|
82
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
83
|
+
* game.ctx.globalAlpha = 0.5;
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
ctx: CanvasRenderingContext2D;
|
|
87
|
+
/**
|
|
88
|
+
* Seconds elapsed since the previous frame. Updated every game loop; multiply movement by it to keep speed independent of frame rate.
|
|
89
|
+
*
|
|
90
|
+
* @category Variables
|
|
91
|
+
* @example
|
|
92
|
+
* ```js
|
|
93
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
94
|
+
* game.states['game'] = function() {
|
|
95
|
+
* playerX += 100 * game.delta; // 100 pixels per second
|
|
96
|
+
* };
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
delta: number;
|
|
100
|
+
/**
|
|
101
|
+
* Frames per second of the game loop. Updated every frame. Read-only: an overwritten value is replaced on the next frame.
|
|
102
|
+
*
|
|
103
|
+
* @category Variables
|
|
104
|
+
* @example
|
|
105
|
+
* ```js
|
|
106
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
107
|
+
* game.fps;
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
fps: number;
|
|
111
|
+
/**
|
|
112
|
+
* Current frames per second divided by 60, as a number with two decimals (for example `1`). Use it to correct game speed on devices that run below 60 fps. Updated every frame. Read-only.
|
|
113
|
+
*
|
|
114
|
+
* @category Variables
|
|
115
|
+
* @example
|
|
116
|
+
* ```js
|
|
117
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
118
|
+
* game.runSpeed;
|
|
119
|
+
* ```
|
|
120
|
+
*/
|
|
121
|
+
runSpeed: number;
|
|
122
|
+
/**
|
|
123
|
+
* Unix timestamp in milliseconds of the last time the game loop ran, or `null` before the first frame. Updated every frame. Read-only.
|
|
124
|
+
*
|
|
125
|
+
* @category Variables
|
|
126
|
+
* @example
|
|
127
|
+
* ```js
|
|
128
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
129
|
+
* game.lastRun;
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
lastRun: number | null;
|
|
133
|
+
/**
|
|
134
|
+
* Whether the game loop is running. `start()` sets it to `true` and `stop()` to `false`; setting it to `false` yourself ends the loop after the current frame.
|
|
135
|
+
*
|
|
136
|
+
* @category Variables
|
|
137
|
+
* @example
|
|
138
|
+
* ```js
|
|
139
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
140
|
+
* game.gameRunning = false; // the loop stops
|
|
141
|
+
* ```
|
|
142
|
+
*/
|
|
143
|
+
gameRunning: boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Set to `true` to draw an FPS meter in the top-left corner. Default is `false`.
|
|
146
|
+
*
|
|
147
|
+
* @category Variables
|
|
148
|
+
* @example
|
|
149
|
+
* ```js
|
|
150
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
151
|
+
* game.showFPS = true;
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
showFPS: boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Free-form name for the game. The engine does not use it, so it is available for your own bookkeeping, for example to prefix saved data. Default is an empty string.
|
|
157
|
+
*
|
|
158
|
+
* @category Variables
|
|
159
|
+
* @example
|
|
160
|
+
* ```js
|
|
161
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
162
|
+
* game.namespace = 'my-game';
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
namespace: string;
|
|
166
|
+
/**
|
|
167
|
+
* X coordinate of the pointer in game coordinates. Updated when the mouse moves or the screen is touched or clicked. Read-only.
|
|
168
|
+
*
|
|
169
|
+
* @category Variables
|
|
170
|
+
* @example
|
|
171
|
+
* ```js
|
|
172
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
173
|
+
* game.mouseX;
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
mouseX: number;
|
|
177
|
+
/**
|
|
178
|
+
* Y coordinate of the pointer in game coordinates. Updated when the mouse moves or the screen is touched or clicked. Read-only.
|
|
179
|
+
*
|
|
180
|
+
* @category Variables
|
|
181
|
+
* @example
|
|
182
|
+
* ```js
|
|
183
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
184
|
+
* game.mouseY;
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
mouseY: number;
|
|
188
|
+
/**
|
|
189
|
+
* Name of the state the game loop is currently running (a key of `states`). It starts as the built-in loading screen, `"startup"`, and switches to `startState` once everything has loaded. Assign a new name to change state.
|
|
190
|
+
*
|
|
191
|
+
* @category Variables
|
|
192
|
+
* @example
|
|
193
|
+
* ```js
|
|
194
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
195
|
+
* game.state = 'game'; // run game.states['game'] each frame
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
state: string;
|
|
199
|
+
/**
|
|
200
|
+
* Name of the state to run after the loading screen. Used once, so set it before `init()`. Default is `null`, so you have to set it.
|
|
201
|
+
*
|
|
202
|
+
* @category Variables
|
|
203
|
+
* @example
|
|
204
|
+
* ```js
|
|
205
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
206
|
+
* game.startState = 'menu';
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
startState: string | null;
|
|
210
|
+
/**
|
|
211
|
+
* Your game states: an object of functions keyed by name. The function named by `state` is called every frame. Change `state` to switch between them.
|
|
212
|
+
*
|
|
213
|
+
* @category Variables
|
|
214
|
+
* @example
|
|
215
|
+
* ```js
|
|
216
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
217
|
+
* game.states['game'] = function() {
|
|
218
|
+
* // your code, run every frame
|
|
219
|
+
* };
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
states: Record<string, () => void>;
|
|
223
|
+
/**
|
|
224
|
+
* Background color drawn behind every frame. Accepts any CSS color (hex, rgb, rgba, hsl, hsla). Default is `"#fff"`.
|
|
225
|
+
*
|
|
226
|
+
* @category Variables
|
|
227
|
+
* @example
|
|
228
|
+
* ```js
|
|
229
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
230
|
+
* game.backgroundColor = '#eee';
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
backgroundColor: string;
|
|
234
|
+
/**
|
|
235
|
+
* Assets to load on startup. Set it before `init()`. Each entry is either the path of an image or audio file, which is also the key the loaded asset is stored under, or an object `{ src, index, spriteMap? }` with the file path, the key to store it under, and an optional `spriteMap` of `{ width, height }` that loads an image as a `Sprite` sprite map. Supported images are jpg, jpeg, png, gif and xbm; audio is mp3, wav, ogg and aac. After `init()` the array is replaced by an object-like array keyed by each entry's index, holding the loaded element (or `Sprite` for sprite maps).
|
|
236
|
+
*
|
|
237
|
+
* @category Assets
|
|
238
|
+
* @example
|
|
239
|
+
* ```js
|
|
240
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
241
|
+
* // as a string: the path is also the key
|
|
242
|
+
* game.assets = ['images/sprite.png'];
|
|
243
|
+
* // the loading screen runs until every asset has loaded, then switches to startState
|
|
244
|
+
* game.startState = 'game';
|
|
245
|
+
* game.states['game'] = function() {
|
|
246
|
+
* game.drawImage(game.assets['images/sprite.png'], 0, 0);
|
|
247
|
+
* };
|
|
248
|
+
* game.init();
|
|
249
|
+
* game.start();
|
|
250
|
+
* ```
|
|
251
|
+
* @example
|
|
252
|
+
* ```js
|
|
253
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
254
|
+
* // as an object: choose the key, optionally load a sprite map
|
|
255
|
+
* game.assets = [{
|
|
256
|
+
* src: 'images/spritemap.png',
|
|
257
|
+
* index: 'tiles',
|
|
258
|
+
* spriteMap: { width: 40, height: 40 }
|
|
259
|
+
* }];
|
|
260
|
+
* game.startState = 'game';
|
|
261
|
+
* game.states['game'] = function() {
|
|
262
|
+
* // Sprite.draw(frame, x, y): frame 0 centred at (50, 50)
|
|
263
|
+
* game.assets['tiles'].draw(0, 50, 50);
|
|
264
|
+
* };
|
|
265
|
+
* game.init();
|
|
266
|
+
* game.start();
|
|
267
|
+
* ```
|
|
268
|
+
*/
|
|
269
|
+
assets: Array<string | AssetEntry> & Record<string, any>;
|
|
270
|
+
/**
|
|
271
|
+
* Whether `loadAssets()` has run, so the entries of `assets` have been turned into loadable elements. Use `loadedAssets` to see how many have actually finished loading.
|
|
272
|
+
*
|
|
273
|
+
* @category Variables
|
|
274
|
+
* @example
|
|
275
|
+
* ```js
|
|
276
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
277
|
+
* game.assetsLoaded; // false until init()
|
|
278
|
+
* ```
|
|
279
|
+
*/
|
|
280
|
+
assetsLoaded: boolean;
|
|
281
|
+
/**
|
|
282
|
+
* Number of requested assets that have finished loading.
|
|
283
|
+
*
|
|
284
|
+
* @category Variables
|
|
285
|
+
* @example
|
|
286
|
+
* ```js
|
|
287
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
288
|
+
* game.loadedAssets;
|
|
289
|
+
* ```
|
|
290
|
+
*/
|
|
291
|
+
loadedAssets: number;
|
|
292
|
+
/**
|
|
293
|
+
* Number of assets requested for loading. Set when `loadAssets()` runs; the loading screen is done when `loadedAssets` reaches it.
|
|
294
|
+
*
|
|
295
|
+
* @category Variables
|
|
296
|
+
* @example
|
|
297
|
+
* ```js
|
|
298
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
299
|
+
* game.assetsToLoad;
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
assetsToLoad: number;
|
|
303
|
+
/**
|
|
304
|
+
* Font family used by `drawText`. Default is `"Arial"`.
|
|
305
|
+
*
|
|
306
|
+
* @category Variables
|
|
307
|
+
* @example
|
|
308
|
+
* ```js
|
|
309
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
310
|
+
* game.font = 'Courier New';
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
font: string;
|
|
314
|
+
/**
|
|
315
|
+
* Font size used by `drawText`, as a CSS size. Default is `"30px"`.
|
|
316
|
+
*
|
|
317
|
+
* @category Variables
|
|
318
|
+
* @example
|
|
319
|
+
* ```js
|
|
320
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
321
|
+
* game.textSize = '32px';
|
|
322
|
+
* ```
|
|
323
|
+
*/
|
|
324
|
+
textSize: string;
|
|
325
|
+
/**
|
|
326
|
+
* Called when the user clicks the game, and when a touch ends on it (`touchend` calls `click` just before its own handler). It updates `mouseX` and `mouseY` first. Assign a function to handle it. Handlers are attached by `init()`, so assign them before calling it.
|
|
327
|
+
* @param evt The mouse click, or the touch event when a touch ended.
|
|
328
|
+
*
|
|
329
|
+
* @category Events
|
|
330
|
+
* @example
|
|
331
|
+
* ```js
|
|
332
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
333
|
+
* game.click = function(e) {
|
|
334
|
+
* // your code here
|
|
335
|
+
* };
|
|
336
|
+
* ```
|
|
337
|
+
*/
|
|
338
|
+
click: (evt: MouseEvent | TouchEvent) => void;
|
|
339
|
+
/**
|
|
340
|
+
* Called when the user presses a mouse button in the game. It updates `mouseX` and `mouseY` first. Assign a function to handle it. Handlers are attached by `init()`, so assign them before calling it.
|
|
341
|
+
* @param evt The mouse event.
|
|
342
|
+
*
|
|
343
|
+
* @category Events
|
|
344
|
+
* @example
|
|
345
|
+
* ```js
|
|
346
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
347
|
+
* game.mousedown = function(e) {
|
|
348
|
+
* // your code here
|
|
349
|
+
* };
|
|
350
|
+
* ```
|
|
351
|
+
*/
|
|
352
|
+
mousedown: (evt: MouseEvent) => void;
|
|
353
|
+
/**
|
|
354
|
+
* Called when the user releases a mouse button in the game. It updates `mouseX` and `mouseY` first. Assign a function to handle it. Handlers are attached by `init()`, so assign them before calling it.
|
|
355
|
+
* @param evt The mouse event.
|
|
356
|
+
*
|
|
357
|
+
* @category Events
|
|
358
|
+
* @example
|
|
359
|
+
* ```js
|
|
360
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
361
|
+
* game.mouseup = function(e) {
|
|
362
|
+
* // your code here
|
|
363
|
+
* };
|
|
364
|
+
* ```
|
|
365
|
+
*/
|
|
366
|
+
mouseup: (evt: MouseEvent) => void;
|
|
367
|
+
/**
|
|
368
|
+
* Called when the pointer moves over the game. It updates `mouseX` and `mouseY` first. Assign a function to handle it.
|
|
369
|
+
*
|
|
370
|
+
* @category Events
|
|
371
|
+
* @example
|
|
372
|
+
* ```js
|
|
373
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
374
|
+
* game.mousemove = function(e) {
|
|
375
|
+
* // your code here
|
|
376
|
+
* };
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
mousemove: Handler;
|
|
380
|
+
/**
|
|
381
|
+
* Called when the user touches the game with a touchscreen. It updates `mouseX` and `mouseY` first. Assign a function to handle it. The handler is looked up when the event fires, so it can be assigned or changed at any time.
|
|
382
|
+
* @param evt The touch event.
|
|
383
|
+
*
|
|
384
|
+
* @category Events
|
|
385
|
+
* @example
|
|
386
|
+
* ```js
|
|
387
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
388
|
+
* game.touch = function(e) {
|
|
389
|
+
* // your code here
|
|
390
|
+
* };
|
|
391
|
+
* ```
|
|
392
|
+
*/
|
|
393
|
+
touch: (evt: TouchEvent) => void;
|
|
394
|
+
/**
|
|
395
|
+
* Called when the user first touches the game with a touchscreen, after `touch`. It updates `mouseX` and `mouseY` first. Assign a function to handle it. The handler is looked up when the event fires, so it can be assigned or changed at any time.
|
|
396
|
+
* @param evt The touch event.
|
|
397
|
+
*
|
|
398
|
+
* @category Events
|
|
399
|
+
* @example
|
|
400
|
+
* ```js
|
|
401
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
402
|
+
* game.touchstart = function(e) {
|
|
403
|
+
* // your code here
|
|
404
|
+
* };
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
touchstart: (evt: TouchEvent) => void;
|
|
408
|
+
/**
|
|
409
|
+
* Called when the user lifts the touch from a touchscreen, after `click`. It updates `mouseX` and `mouseY` first. Assign a function to handle it. The handler is looked up when the event fires, so it can be assigned or changed at any time.
|
|
410
|
+
* @param evt The touch event.
|
|
411
|
+
*
|
|
412
|
+
* @category Events
|
|
413
|
+
* @example
|
|
414
|
+
* ```js
|
|
415
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
416
|
+
* game.touchend = function(e) {
|
|
417
|
+
* // your code here
|
|
418
|
+
* };
|
|
419
|
+
* ```
|
|
420
|
+
*/
|
|
421
|
+
touchend: (evt: TouchEvent) => void;
|
|
422
|
+
/**
|
|
423
|
+
* Called when the user presses a key. Assign a function to handle it; find key codes at keycode.info. Attached by `init()`, so assign it first.
|
|
424
|
+
* @param evt The keyboard event; `evt.key` holds the key.
|
|
425
|
+
*
|
|
426
|
+
* @category Events
|
|
427
|
+
* @example
|
|
428
|
+
* ```js
|
|
429
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
430
|
+
* game.keydown = function(e) {
|
|
431
|
+
* // your code here
|
|
432
|
+
* console.log(e.keyCode, e.key);
|
|
433
|
+
* };
|
|
434
|
+
* ```
|
|
435
|
+
*/
|
|
436
|
+
keydown: (evt: KeyboardEvent) => void;
|
|
437
|
+
/**
|
|
438
|
+
* Called when the user releases a key. Assign a function to handle it. Attached by `init()`, so assign it first.
|
|
439
|
+
* @param evt The keyboard event; `evt.key` holds the key.
|
|
440
|
+
*
|
|
441
|
+
* @category Events
|
|
442
|
+
* @example
|
|
443
|
+
* ```js
|
|
444
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
445
|
+
* game.keyup = function(e) {
|
|
446
|
+
* // your code here
|
|
447
|
+
* console.log(e.keyCode, e.key);
|
|
448
|
+
* };
|
|
449
|
+
* ```
|
|
450
|
+
*/
|
|
451
|
+
keyup: (evt: KeyboardEvent) => void;
|
|
452
|
+
/**
|
|
453
|
+
* Called when the orientation of the device changes. Usually only available on phones.
|
|
454
|
+
*
|
|
455
|
+
* @category Events
|
|
456
|
+
* @example
|
|
457
|
+
* ```js
|
|
458
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
459
|
+
* game.deviceorientation = function(e) {
|
|
460
|
+
* // your code here
|
|
461
|
+
* };
|
|
462
|
+
* ```
|
|
463
|
+
*/
|
|
464
|
+
deviceorientation: Handler;
|
|
465
|
+
/**
|
|
466
|
+
* Called when the device reports motion (acceleration or rotation). Usually only available on phones. Since 1.1.0 this handler is actually attached; 1.0.0 never called it.
|
|
467
|
+
*
|
|
468
|
+
* @category Events
|
|
469
|
+
* @example
|
|
470
|
+
* ```js
|
|
471
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
472
|
+
* game.devicemotion = function(e) {
|
|
473
|
+
* // your code here
|
|
474
|
+
* };
|
|
475
|
+
* ```
|
|
476
|
+
*/
|
|
477
|
+
devicemotion: Handler;
|
|
478
|
+
/**
|
|
479
|
+
* Called after the game has refitted itself when the window is resized. The name is misspelled on purpose and is kept for compatibility.
|
|
480
|
+
*
|
|
481
|
+
* @category Events
|
|
482
|
+
* @example
|
|
483
|
+
* ```js
|
|
484
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
485
|
+
* game.rezise = function(e) {
|
|
486
|
+
* // your code here
|
|
487
|
+
* };
|
|
488
|
+
* ```
|
|
489
|
+
*/
|
|
490
|
+
rezise: Handler;
|
|
491
|
+
/**
|
|
492
|
+
* Creates a game: a `<canvas>` with its 2d context inside a container, the game loop and the standard events. The canvas is appended to the page and scaled to fit the window. Call `init()` and `start()` afterwards. Must be called with `new`.
|
|
493
|
+
* @param width Width of the game in pixels.
|
|
494
|
+
* @param height Height of the game in pixels.
|
|
495
|
+
* @example
|
|
496
|
+
* ```js
|
|
497
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
498
|
+
* ```
|
|
499
|
+
*/
|
|
500
|
+
constructor(width: number, height: number);
|
|
501
|
+
/**
|
|
502
|
+
* Updates `mouseX` and `mouseY` (in game coordinates) from a mouse or touch event. The engine calls it for you before the mouse and touch handlers run, so you only need it to read the position of an event you handle yourself. Since 1.1.0 it uses this game instead of a global variable named `game`, and handles touch-end events that have no `touches`.
|
|
503
|
+
* @param evt The mouse or touch event to read the position from.
|
|
504
|
+
* @example
|
|
505
|
+
* ```js
|
|
506
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
507
|
+
* game.canvas.addEventListener('pointerdown', function(e) {
|
|
508
|
+
* game.getMouseCords(e);
|
|
509
|
+
* console.log(game.mouseX, game.mouseY);
|
|
510
|
+
* });
|
|
511
|
+
* ```
|
|
512
|
+
*/
|
|
513
|
+
getMouseCords(evt: Event): void;
|
|
514
|
+
/**
|
|
515
|
+
* Creates the container and canvas and hooks the window resize event. The constructor calls it, so you do not need to. The name is misspelled on purpose and is kept for compatibility.
|
|
516
|
+
* @example
|
|
517
|
+
* ```js
|
|
518
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
519
|
+
* // the constructor has already called game.contruct()
|
|
520
|
+
* ```
|
|
521
|
+
*/
|
|
522
|
+
contruct(): void;
|
|
523
|
+
/**
|
|
524
|
+
* Initializes the game: loads `assets`, fits the canvas to the window and attaches the event handlers as they are at this moment. Assign your handlers and `assets` before calling it, and call it before `start()`.
|
|
525
|
+
* @example
|
|
526
|
+
* ```js
|
|
527
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
528
|
+
* game.startState = 'menu';
|
|
529
|
+
* game.init();
|
|
530
|
+
* ```
|
|
531
|
+
*/
|
|
532
|
+
init(): void;
|
|
533
|
+
/**
|
|
534
|
+
* Creates an `Image` or `Audio` element for every entry of `assets` and starts loading it, then replaces `assets` with an object-like array keyed by each entry's index. `init()` calls it for you, so you rarely need it directly. Unknown entries and file types are logged to the console and skipped.
|
|
535
|
+
*
|
|
536
|
+
* @category Assets
|
|
537
|
+
* @example
|
|
538
|
+
* ```js
|
|
539
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
540
|
+
* game.assets = ['sounds/jump.wav'];
|
|
541
|
+
* game.loadAssets();
|
|
542
|
+
* game.assets['sounds/jump.wav'].play();
|
|
543
|
+
* ```
|
|
544
|
+
*/
|
|
545
|
+
loadAssets(): void;
|
|
546
|
+
/**
|
|
547
|
+
* Sets the fill color used by `fill()` and `drawText`.
|
|
548
|
+
*
|
|
549
|
+
* @category Drawing
|
|
550
|
+
* @param color Any CSS color: hex, rgb, rgba, hsl, hsla or a name.
|
|
551
|
+
* @example
|
|
552
|
+
* ```js
|
|
553
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
554
|
+
* game.setFillColor('#f00');
|
|
555
|
+
* game.drawRect(10, 10, 50, 50);
|
|
556
|
+
* game.fill();
|
|
557
|
+
* ```
|
|
558
|
+
*/
|
|
559
|
+
setFillColor(color: string): void;
|
|
560
|
+
/**
|
|
561
|
+
* Fills the current path (for example from `drawRect` or `drawCircle`) with the fill color.
|
|
562
|
+
*
|
|
563
|
+
* @category Drawing
|
|
564
|
+
* @example
|
|
565
|
+
* ```js
|
|
566
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
567
|
+
* game.setFillColor('#0a0');
|
|
568
|
+
* game.drawCircle(100, 100, 20);
|
|
569
|
+
* game.fill();
|
|
570
|
+
* ```
|
|
571
|
+
*/
|
|
572
|
+
fill(): void;
|
|
573
|
+
/**
|
|
574
|
+
* Sets the stroke color used by `stroke()` and `drawLine`.
|
|
575
|
+
*
|
|
576
|
+
* @category Drawing
|
|
577
|
+
* @param color Any CSS color: hex, rgb, rgba, hsl, hsla or a name.
|
|
578
|
+
* @example
|
|
579
|
+
* ```js
|
|
580
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
581
|
+
* game.setStrokeColor('#00f');
|
|
582
|
+
* game.drawLine(0, 0, 100, 100);
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
setStrokeColor(color: string): void;
|
|
586
|
+
/**
|
|
587
|
+
* Strokes the outline of the current path with the stroke color.
|
|
588
|
+
*
|
|
589
|
+
* @category Drawing
|
|
590
|
+
* @example
|
|
591
|
+
* ```js
|
|
592
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
593
|
+
* game.setStrokeColor('#000');
|
|
594
|
+
* game.drawRect(10, 10, 50, 50);
|
|
595
|
+
* game.stroke();
|
|
596
|
+
* ```
|
|
597
|
+
*/
|
|
598
|
+
stroke(): void;
|
|
599
|
+
/**
|
|
600
|
+
* Draws a line from (x1, y1) to (x2, y2) with the stroke color. When `width` is given it sets the canvas `lineWidth`; like all canvas state it then persists for later strokes until changed (since 1.1.0; 1.0.0 ignored `width`).
|
|
601
|
+
*
|
|
602
|
+
* @category Drawing
|
|
603
|
+
* @param x1 X coordinate of the start.
|
|
604
|
+
* @param y1 Y coordinate of the start.
|
|
605
|
+
* @param x2 X coordinate of the end.
|
|
606
|
+
* @param y2 Y coordinate of the end.
|
|
607
|
+
* @param width Line width in pixels. Leave out to keep the current width.
|
|
608
|
+
* @example
|
|
609
|
+
* ```js
|
|
610
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
611
|
+
* game.drawLine(100, 100, 200, 200);
|
|
612
|
+
* game.drawLine(100, 200, 200, 100, 4); // 4 pixels wide, and later lines stay 4 wide
|
|
613
|
+
* ```
|
|
614
|
+
*/
|
|
615
|
+
drawLine(x1: number, y1: number, x2: number, y2: number, width?: number): void;
|
|
616
|
+
/**
|
|
617
|
+
* Draws text at (x, y) using `font` and `textSize` and the fill color.
|
|
618
|
+
*
|
|
619
|
+
* @category Drawing
|
|
620
|
+
* @param text The text to draw.
|
|
621
|
+
* @param x X coordinate of the text.
|
|
622
|
+
* @param y Y coordinate of the text.
|
|
623
|
+
* @example
|
|
624
|
+
* ```js
|
|
625
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
626
|
+
* game.drawText('Hello World!', 100, 100);
|
|
627
|
+
* ```
|
|
628
|
+
*/
|
|
629
|
+
drawText(text: string, x: number, y: number): void;
|
|
630
|
+
/**
|
|
631
|
+
* Traces a rectangle path, with rounded corners if `radius` is given. It only builds the path: call `fill()` or `stroke()` afterwards to draw it.
|
|
632
|
+
*
|
|
633
|
+
* @category Drawing
|
|
634
|
+
* @param x X coordinate of the left edge.
|
|
635
|
+
* @param y Y coordinate of the top edge.
|
|
636
|
+
* @param width Width of the rectangle.
|
|
637
|
+
* @param height Height of the rectangle.
|
|
638
|
+
* @param radius Corner radius. Leave out for square corners.
|
|
639
|
+
* @example
|
|
640
|
+
* ```js
|
|
641
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
642
|
+
* game.drawRect(100, 100, 20, 20);
|
|
643
|
+
* game.fill();
|
|
644
|
+
* ```
|
|
645
|
+
*/
|
|
646
|
+
drawRect(x: number, y: number, width: number, height: number, radius?: number): void;
|
|
647
|
+
/**
|
|
648
|
+
* Traces a circle path. It only builds the path: call `fill()` or `stroke()` afterwards to draw it.
|
|
649
|
+
*
|
|
650
|
+
* @category Drawing
|
|
651
|
+
* @param x X coordinate of the center.
|
|
652
|
+
* @param y Y coordinate of the center.
|
|
653
|
+
* @param radius Radius of the circle.
|
|
654
|
+
* @example
|
|
655
|
+
* ```js
|
|
656
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
657
|
+
* game.drawCircle(100, 100, 20);
|
|
658
|
+
* game.fill();
|
|
659
|
+
* ```
|
|
660
|
+
*/
|
|
661
|
+
drawCircle(x: number, y: number, radius: number): void;
|
|
662
|
+
/**
|
|
663
|
+
* Draws an image at (x, y), scaled to `width` by `height` when both are given.
|
|
664
|
+
*
|
|
665
|
+
* @category Drawing
|
|
666
|
+
* @param img The image to draw, for example a loaded entry of `assets`.
|
|
667
|
+
* @param x X coordinate of the left edge.
|
|
668
|
+
* @param y Y coordinate of the top edge.
|
|
669
|
+
* @param width Width to draw at. Needs `height` as well; leave out for the natural size.
|
|
670
|
+
* @param height Height to draw at. Needs `width` as well; leave out for the natural size.
|
|
671
|
+
* @example
|
|
672
|
+
* ```js
|
|
673
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
674
|
+
* game.assets = ['image.png'];
|
|
675
|
+
* game.init();
|
|
676
|
+
* game.drawImage(game.assets['image.png'], 100, 100);
|
|
677
|
+
* game.drawImage(game.assets['image.png'], 100, 100, 200, 200);
|
|
678
|
+
* ```
|
|
679
|
+
*/
|
|
680
|
+
drawImage(img: CanvasImageSource, x: number, y: number, width?: number | null, height?: number | null): void;
|
|
681
|
+
/**
|
|
682
|
+
* Starts the game loop. Each frame it clears the canvas, fills the background and runs the current state.
|
|
683
|
+
* @example
|
|
684
|
+
* ```js
|
|
685
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
686
|
+
* game.init();
|
|
687
|
+
* game.start();
|
|
688
|
+
* ```
|
|
689
|
+
*/
|
|
690
|
+
start(): void;
|
|
691
|
+
/**
|
|
692
|
+
* Stops the game loop. Call `start()` to run it again.
|
|
693
|
+
* @example
|
|
694
|
+
* ```js
|
|
695
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
696
|
+
* game.stop();
|
|
697
|
+
* ```
|
|
698
|
+
*/
|
|
699
|
+
stop(): void;
|
|
700
|
+
/** Prefers the legacy window.requestAnimFrame alias, else requestAnimationFrame. */
|
|
701
|
+
private requestFrame;
|
|
702
|
+
}
|