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,40 @@
|
|
|
1
|
+
import type { Game } from './game';
|
|
2
|
+
import type { Sprite } from './sprite';
|
|
3
|
+
import type { elemApi } from './elem';
|
|
4
|
+
import type { Vector } from './vector';
|
|
5
|
+
import type { Collider } from './collider';
|
|
6
|
+
import type { AjaxOptions } from './ajax';
|
|
7
|
+
import type { storage } from './storage';
|
|
8
|
+
import type * as tokenFlow from './storage-token';
|
|
9
|
+
/**
|
|
10
|
+
* The shared THRUNIUM namespace. Each module attaches its members to `T`;
|
|
11
|
+
* index.ts wires the modules together.
|
|
12
|
+
*/
|
|
13
|
+
export interface Thrunium {
|
|
14
|
+
/** The version of Thrunium that is loaded, such as `"{{version}}"`. */
|
|
15
|
+
version: string;
|
|
16
|
+
pageLoad: () => void;
|
|
17
|
+
ready: (fn: () => void) => void;
|
|
18
|
+
throwError: (txt: string) => void;
|
|
19
|
+
mobileAndTabletcheck: () => boolean;
|
|
20
|
+
iOScheck: () => boolean;
|
|
21
|
+
getRandom: (min: number, max: number, float?: boolean) => number;
|
|
22
|
+
Game: typeof Game;
|
|
23
|
+
Elem?: typeof elemApi;
|
|
24
|
+
Sprite?: typeof Sprite;
|
|
25
|
+
Vector: typeof Vector;
|
|
26
|
+
Collider: typeof Collider;
|
|
27
|
+
ajax: (data: AjaxOptions) => XMLHttpRequest;
|
|
28
|
+
/** Cookie storage plus the (WIP) user-token members; the latter are mutable at runtime. */
|
|
29
|
+
Storage: typeof storage & {
|
|
30
|
+
reqToken: string | null;
|
|
31
|
+
userToken: string | null;
|
|
32
|
+
timeout: ReturnType<typeof setTimeout> | null;
|
|
33
|
+
loginPopup: Window | null;
|
|
34
|
+
accessRequested: boolean;
|
|
35
|
+
_options: tokenFlow.StorageOptions;
|
|
36
|
+
setReqToken: typeof tokenFlow.setReqToken;
|
|
37
|
+
reqUserToken: typeof tokenFlow.reqUserToken;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export declare const T: Thrunium;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The TypeDoc entry for the reference docs (`npm run docs`), never bundled:
|
|
3
|
+
* nothing imports it, and esbuild only follows imports from src/index.ts.
|
|
4
|
+
*
|
|
5
|
+
* It exports exactly what src/index.ts attaches to the THRUNIUM global, under
|
|
6
|
+
* the names used there (plus, at the bottom, the types the pages need).
|
|
7
|
+
* scripts/docs-reference.mjs maps these names to pages.
|
|
8
|
+
* The doc comments themselves live in the modules, so this file has none of
|
|
9
|
+
* its own beyond the Storage summary and the `version` pointer.
|
|
10
|
+
*/
|
|
11
|
+
import type { Thrunium } from './namespace';
|
|
12
|
+
import * as tokenFlow from './storage-token';
|
|
13
|
+
export { Game } from './game';
|
|
14
|
+
export { Vector } from './vector';
|
|
15
|
+
export { Sprite } from './sprite';
|
|
16
|
+
export { Collider } from './collider';
|
|
17
|
+
export { elemApi as Elem } from './elem';
|
|
18
|
+
export { ajax } from './ajax';
|
|
19
|
+
export { pageLoad, ready, throwError, mobileAndTabletcheck, iOScheck, getRandom } from './env';
|
|
20
|
+
/**
|
|
21
|
+
* Save data such as high scores and game progress on the player's device, in
|
|
22
|
+
* cookies. It also holds the Thrun db user-token flow for saving in
|
|
23
|
+
* Thrungames' cloud, which is a work in progress and does not work yet.
|
|
24
|
+
*/
|
|
25
|
+
export declare const Storage: {
|
|
26
|
+
set: (name: string, value: unknown) => true;
|
|
27
|
+
get: (name: string) => string | null;
|
|
28
|
+
timeout: ReturnType<typeof setTimeout> | null;
|
|
29
|
+
setReqToken: typeof tokenFlow.setReqToken;
|
|
30
|
+
reqUserToken: typeof tokenFlow.reqUserToken;
|
|
31
|
+
reqToken: string | null;
|
|
32
|
+
userToken: string | null;
|
|
33
|
+
loginPopup: Window | null;
|
|
34
|
+
accessRequested: false;
|
|
35
|
+
_options: tokenFlow.StorageOptions;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* {@inheritDoc Thrunium.version}
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```js
|
|
42
|
+
* console.log(THRUNIUM.version); // '{{version}}'
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const version: string;
|
|
46
|
+
/** The THRUNIUM global; docs-reference.mjs checks each public key has a page. */
|
|
47
|
+
export type { Thrunium };
|
|
48
|
+
export { ElemElem } from './elem';
|
|
49
|
+
export type { AjaxOptions } from './ajax';
|
|
50
|
+
export type { StorageOptions } from './storage-token';
|
|
51
|
+
export type { AssetEntry, Handler } from './game';
|
|
52
|
+
export type { StyleMap } from './elem';
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An image to draw on the game canvas, rotated around its centre. It can also be
|
|
3
|
+
* a sprite map: one image holding several equally sized frames, laid out left to
|
|
4
|
+
* right and wrapping to the next row, which `draw()` picks from and `drawAnim()`
|
|
5
|
+
* plays as an animation. Sprites draw on the current `THRUNIUM.Game`, so create
|
|
6
|
+
* the game first.
|
|
7
|
+
*
|
|
8
|
+
* The easiest way to get one is to load the image as a sprite-map asset: an
|
|
9
|
+
* `assets` entry with a `spriteMap` of `{ width, height }` is replaced by a ready
|
|
10
|
+
* `Sprite` once it has loaded. You can also construct one yourself from a loaded image.
|
|
11
|
+
*/
|
|
12
|
+
export declare class Sprite {
|
|
13
|
+
[Symbol.toStringTag]: string;
|
|
14
|
+
/**
|
|
15
|
+
* The image the sprite draws from, as passed to the constructor.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```js
|
|
19
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
20
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
21
|
+
* game.startState = 'game';
|
|
22
|
+
* game.states['game'] = function() {
|
|
23
|
+
* game.assets['hero'].image; // the loaded <img> element
|
|
24
|
+
* };
|
|
25
|
+
* game.init();
|
|
26
|
+
* game.start();
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
image: HTMLImageElement;
|
|
30
|
+
/**
|
|
31
|
+
* Rotation in degrees, clockwise, around the centre of the drawn frame. Default is `0`. Set it with `setAngle()`.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```js
|
|
35
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
36
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
37
|
+
* game.startState = 'game';
|
|
38
|
+
* game.states['game'] = function() {
|
|
39
|
+
* game.assets['hero'].angle; // 0
|
|
40
|
+
* };
|
|
41
|
+
* game.init();
|
|
42
|
+
* game.start();
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
angle: number;
|
|
46
|
+
/**
|
|
47
|
+
* Width of the whole image in pixels, read from the image when the sprite is created.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```js
|
|
51
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
52
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
53
|
+
* game.startState = 'game';
|
|
54
|
+
* game.states['game'] = function() {
|
|
55
|
+
* game.assets['hero'].fullWidth; // e.g. 128 for a 128 x 64 image
|
|
56
|
+
* };
|
|
57
|
+
* game.init();
|
|
58
|
+
* game.start();
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
fullWidth: number;
|
|
62
|
+
/**
|
|
63
|
+
* Height of the whole image in pixels, read from the image when the sprite is created. Since 1.1.0 this is the image's height; 1.0.0 used its width.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```js
|
|
67
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
68
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
69
|
+
* game.startState = 'game';
|
|
70
|
+
* game.states['game'] = function() {
|
|
71
|
+
* game.assets['hero'].fullHeight; // e.g. 64 for a 128 x 64 image
|
|
72
|
+
* };
|
|
73
|
+
* game.init();
|
|
74
|
+
* game.start();
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
fullHeight: number;
|
|
78
|
+
/**
|
|
79
|
+
* Width of one frame in pixels. It starts as the full image width (one frame) and is set by `setSpriteMap()`.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```js
|
|
83
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
84
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
85
|
+
* game.startState = 'game';
|
|
86
|
+
* game.states['game'] = function() {
|
|
87
|
+
* game.assets['hero'].spriteWidth; // 32
|
|
88
|
+
* };
|
|
89
|
+
* game.init();
|
|
90
|
+
* game.start();
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
spriteWidth: number;
|
|
94
|
+
/**
|
|
95
|
+
* Height of one frame in pixels. It starts as the full image height (one frame) and is set by `setSpriteMap()`.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```js
|
|
99
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
100
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
101
|
+
* game.startState = 'game';
|
|
102
|
+
* game.states['game'] = function() {
|
|
103
|
+
* game.assets['hero'].spriteHeight; // 32
|
|
104
|
+
* };
|
|
105
|
+
* game.init();
|
|
106
|
+
* game.start();
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
spriteHeight: number;
|
|
110
|
+
/**
|
|
111
|
+
* The frame `drawAnim()` is showing, or `null` when no animation is running. `drawAnim()` updates it; set it to `null` to restart an animation from its first frame.
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```js
|
|
115
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
116
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
117
|
+
* game.startState = 'game';
|
|
118
|
+
* game.states['game'] = function() {
|
|
119
|
+
* var hero = game.assets['hero'];
|
|
120
|
+
* hero.setLoop(true);
|
|
121
|
+
* hero.drawAnim(0, 3, 200, 200);
|
|
122
|
+
* hero.currentSprite; // 0, 1, 2 or 3
|
|
123
|
+
* };
|
|
124
|
+
* game.init();
|
|
125
|
+
* game.start();
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
128
|
+
currentSprite: number | null;
|
|
129
|
+
/**
|
|
130
|
+
* How long one run of an animation takes, in milliseconds, split evenly over its frames. Default is `100`. Set it with `setAnimTime()`.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```js
|
|
134
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
135
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
136
|
+
* game.startState = 'game';
|
|
137
|
+
* game.states['game'] = function() {
|
|
138
|
+
* game.assets['hero'].animTimeDur; // 100
|
|
139
|
+
* };
|
|
140
|
+
* game.init();
|
|
141
|
+
* game.start();
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
animTimeDur: number;
|
|
145
|
+
/**
|
|
146
|
+
* Unix timestamp in milliseconds of when `drawAnim()` last moved to another frame. Starts at `0`.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```js
|
|
150
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
151
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
152
|
+
* game.startState = 'game';
|
|
153
|
+
* game.states['game'] = function() {
|
|
154
|
+
* var hero = game.assets['hero'];
|
|
155
|
+
* hero.drawAnim(0, 3, 200, 200);
|
|
156
|
+
* hero.frameTimeLast; // e.g. 1767225600000
|
|
157
|
+
* };
|
|
158
|
+
* game.init();
|
|
159
|
+
* game.start();
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
frameTimeLast: number;
|
|
163
|
+
/**
|
|
164
|
+
* Whether `drawAnim()` starts over after the last frame. Default is `false`. Set it with `setLoop()`.
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```js
|
|
168
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
169
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
170
|
+
* game.startState = 'game';
|
|
171
|
+
* game.states['game'] = function() {
|
|
172
|
+
* game.assets['hero'].animLoop; // false
|
|
173
|
+
* };
|
|
174
|
+
* game.init();
|
|
175
|
+
* game.start();
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
|
+
animLoop: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* Function called when a non-looping animation finishes. Default does nothing. Set it with `setAnimCallback()`.
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```js
|
|
184
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
185
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
186
|
+
* game.startState = 'game';
|
|
187
|
+
* game.states['game'] = function() {
|
|
188
|
+
* game.assets['hero'].animCallback(); // does nothing until you set one
|
|
189
|
+
* };
|
|
190
|
+
* game.init();
|
|
191
|
+
* game.start();
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
animCallback: () => void;
|
|
195
|
+
/**
|
|
196
|
+
* Creates a sprite from an image. The image must have finished loading, because its size is read here; until you call `setSpriteMap()` the whole image is one frame. Must be called with `new`, and a `THRUNIUM.Game` must exist before the sprite draws.
|
|
197
|
+
* @param image A loaded image to use as the sprite or sprite map.
|
|
198
|
+
* @example
|
|
199
|
+
* ```js
|
|
200
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
201
|
+
* var image = new Image();
|
|
202
|
+
* image.onload = function() {
|
|
203
|
+
* var sprite = new THRUNIUM.Sprite(image);
|
|
204
|
+
* sprite.draw(0, 200, 200);
|
|
205
|
+
* };
|
|
206
|
+
* image.src = 'images/hero.png';
|
|
207
|
+
* ```
|
|
208
|
+
*/
|
|
209
|
+
constructor(image: HTMLImageElement);
|
|
210
|
+
/**
|
|
211
|
+
* Sets the rotation, in degrees clockwise, that the sprite is drawn with from now on.
|
|
212
|
+
* @param angle The rotation in degrees.
|
|
213
|
+
* @example
|
|
214
|
+
* ```js
|
|
215
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
216
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
217
|
+
* game.startState = 'game';
|
|
218
|
+
* game.states['game'] = function() {
|
|
219
|
+
* var hero = game.assets['hero'];
|
|
220
|
+
* hero.setAngle(hero.angle + 90 * game.delta); // a quarter turn per second
|
|
221
|
+
* hero.draw(0, 200, 200);
|
|
222
|
+
* };
|
|
223
|
+
* game.init();
|
|
224
|
+
* game.start();
|
|
225
|
+
* ```
|
|
226
|
+
*/
|
|
227
|
+
setAngle(angle: number): void;
|
|
228
|
+
/**
|
|
229
|
+
* Sets whether `drawAnim()` starts over after the last frame. Without a loop, the animation calls the `setAnimCallback()` function after its last frame, and the next `drawAnim()` call starts it again. Since 1.1.0 `drawAnim()` honours this setting; 1.0.0 ignored it.
|
|
230
|
+
* @param loop `true` to loop the animation.
|
|
231
|
+
* @example
|
|
232
|
+
* ```js
|
|
233
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
234
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
235
|
+
* game.startState = 'game';
|
|
236
|
+
* game.states['game'] = function() {
|
|
237
|
+
* var hero = game.assets['hero'];
|
|
238
|
+
* hero.setLoop(true);
|
|
239
|
+
* hero.drawAnim(0, 3, 200, 200);
|
|
240
|
+
* };
|
|
241
|
+
* game.init();
|
|
242
|
+
* game.start();
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
setLoop(loop: boolean): void;
|
|
246
|
+
/**
|
|
247
|
+
* Sets the function called each time a non-looping animation finishes.
|
|
248
|
+
* @param fun The function to call; it gets no arguments.
|
|
249
|
+
* @example
|
|
250
|
+
* ```js
|
|
251
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
252
|
+
* game.assets = [{ src: 'images/explosion.png', index: 'boom', spriteMap: { width: 64, height: 64 } }];
|
|
253
|
+
* game.startState = 'game';
|
|
254
|
+
* game.states['game'] = function() {
|
|
255
|
+
* var boom = game.assets['boom'];
|
|
256
|
+
* boom.setAnimCallback(function() {
|
|
257
|
+
* game.state = 'gameover';
|
|
258
|
+
* });
|
|
259
|
+
* boom.drawAnim(0, 7, 200, 200);
|
|
260
|
+
* };
|
|
261
|
+
* game.states['gameover'] = function() {
|
|
262
|
+
* game.drawText('Game over', 200, 200);
|
|
263
|
+
* };
|
|
264
|
+
* game.init();
|
|
265
|
+
* game.start();
|
|
266
|
+
* ```
|
|
267
|
+
*/
|
|
268
|
+
setAnimCallback(fun: () => void): void;
|
|
269
|
+
/**
|
|
270
|
+
* Sets how long one run of an animation takes, in milliseconds. The time is split evenly over the frames `drawAnim()` plays. Since 1.1.0 this works; in 1.0.0 it overwrote itself and had no effect.
|
|
271
|
+
* @param time Duration of the whole animation in milliseconds.
|
|
272
|
+
* @example
|
|
273
|
+
* ```js
|
|
274
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
275
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
276
|
+
* game.startState = 'game';
|
|
277
|
+
* game.states['game'] = function() {
|
|
278
|
+
* var hero = game.assets['hero'];
|
|
279
|
+
* hero.setAnimTime(400); // 4 frames, 100 ms each
|
|
280
|
+
* hero.setLoop(true);
|
|
281
|
+
* hero.drawAnim(0, 3, 200, 200);
|
|
282
|
+
* };
|
|
283
|
+
* game.init();
|
|
284
|
+
* game.start();
|
|
285
|
+
* ```
|
|
286
|
+
*/
|
|
287
|
+
setAnimTime(time: number): void;
|
|
288
|
+
/**
|
|
289
|
+
* Turns the image into a sprite map of frames of `width` x `height` pixels. Frames are numbered from 0, left to right, then row by row. A sprite-map asset has this set already.
|
|
290
|
+
* @param width Width of one frame in pixels.
|
|
291
|
+
* @param height Height of one frame in pixels.
|
|
292
|
+
* @example
|
|
293
|
+
* ```js
|
|
294
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
295
|
+
* var image = new Image();
|
|
296
|
+
* image.onload = function() {
|
|
297
|
+
* var tiles = new THRUNIUM.Sprite(image);
|
|
298
|
+
* tiles.setSpriteMap(40, 40);
|
|
299
|
+
* tiles.draw(2, 200, 200); // the third 40 x 40 frame
|
|
300
|
+
* };
|
|
301
|
+
* image.src = 'images/tiles.png';
|
|
302
|
+
* ```
|
|
303
|
+
*/
|
|
304
|
+
setSpriteMap(width: number, height: number): void;
|
|
305
|
+
/**
|
|
306
|
+
* Draws one frame centred on (`x`, `y`), rotated by `angle`. The frame is drawn at its own size unless you pass `width` and `height`.
|
|
307
|
+
* @param imgNum Number of the frame to draw, counting from 0 left to right, then row by row. Default is `0`.
|
|
308
|
+
* @param x X coordinate of the centre of the drawn frame.
|
|
309
|
+
* @param y Y coordinate of the centre of the drawn frame.
|
|
310
|
+
* @param width Width to draw the frame at. Default is the frame width.
|
|
311
|
+
* @param height Height to draw the frame at. Default is the frame height.
|
|
312
|
+
* @example
|
|
313
|
+
* ```js
|
|
314
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
315
|
+
* game.assets = [{ src: 'images/tiles.png', index: 'tiles', spriteMap: { width: 40, height: 40 } }];
|
|
316
|
+
* game.startState = 'game';
|
|
317
|
+
* game.states['game'] = function() {
|
|
318
|
+
* game.assets['tiles'].draw(0, 50, 50); // frame 0 at its own size
|
|
319
|
+
* game.assets['tiles'].draw(1, 150, 50, 80, 80); // frame 1 at double size
|
|
320
|
+
* };
|
|
321
|
+
* game.init();
|
|
322
|
+
* game.start();
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
draw(imgNum: number | undefined, x: number, y: number, width?: number, height?: number): void;
|
|
326
|
+
/**
|
|
327
|
+
* Plays an animation over the frames `imgFrom` to `imgTo`: call it every frame of your game state and it draws the current frame, moving to the next one when its share of `animTimeDur` has passed. After `imgTo` it starts over when `setLoop(true)` is set; otherwise it calls the `setAnimCallback()` function, and the next call starts again from `imgFrom`. Drawing works as in `draw()`.
|
|
328
|
+
* @param imgFrom Number of the first frame of the animation.
|
|
329
|
+
* @param imgTo Number of the last frame of the animation.
|
|
330
|
+
* @param x X coordinate of the centre of the drawn frame.
|
|
331
|
+
* @param y Y coordinate of the centre of the drawn frame.
|
|
332
|
+
* @param width Width to draw the frame at. Default is the frame width.
|
|
333
|
+
* @param height Height to draw the frame at. Default is the frame height.
|
|
334
|
+
* @example
|
|
335
|
+
* ```js
|
|
336
|
+
* var game = new THRUNIUM.Game(400, 400);
|
|
337
|
+
* game.assets = [{ src: 'images/hero.png', index: 'hero', spriteMap: { width: 32, height: 32 } }];
|
|
338
|
+
* game.startState = 'game';
|
|
339
|
+
* game.states['game'] = function() {
|
|
340
|
+
* // frames 0 to 3, drawn at double size
|
|
341
|
+
* game.assets['hero'].drawAnim(0, 3, 200, 200, 64, 64);
|
|
342
|
+
* };
|
|
343
|
+
* game.init();
|
|
344
|
+
* game.start();
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
drawAnim(imgFrom: number, imgTo: number, x: number, y: number, width?: number, height?: number): void;
|
|
348
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export interface StorageOptions {
|
|
2
|
+
/** Called when the player has granted access. Misspelled on purpose; kept for compatibility. */
|
|
3
|
+
succes?: (e: unknown) => void;
|
|
4
|
+
/** Called with `{ type, event }` when the request fails or the player rejects it; `type` is `'ajaxFailed'` or `'userRejected'`. */
|
|
5
|
+
error?: (e: unknown) => void;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Sets the request token of the Thrun db user-token flow, a way to save data in Thrungames' cloud. The flow is a work in progress: it does not work in this version and will change when authentication is added.
|
|
9
|
+
* @param token The game's request token.
|
|
10
|
+
*
|
|
11
|
+
* @experimental
|
|
12
|
+
*/
|
|
13
|
+
export declare function setReqToken(token: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Asks Thrungames for a user token for the request token set with `setReqToken()`, so the game can save data in Thrungames' cloud (Thrun db). The flow is a work in progress: it does not work in this version, so do not rely on its callbacks. It will change when authentication is added.
|
|
16
|
+
* @param options The callbacks to call with the result.
|
|
17
|
+
*
|
|
18
|
+
* @experimental
|
|
19
|
+
*/
|
|
20
|
+
export declare function reqUserToken(options: StorageOptions): void;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/** Cookie-backed storage. */
|
|
2
|
+
/**
|
|
3
|
+
* Saves a value on the player's device, in a cookie that lasts 365 days and belongs to the current page's path. The value is turned into a string, so store objects with `JSON.stringify` and read them back with `JSON.parse`. Keep values small: browsers drop a cookie over 4 KB. Always returns `true`.
|
|
4
|
+
*
|
|
5
|
+
* Since 1.1.0 values may contain any character: `%`, `;`, line breaks and other control characters, and leading or trailing spaces are escaped, and `get()` turns them back. 1.0.0 cut values off at a `;`.
|
|
6
|
+
* @param name Name to save the value under.
|
|
7
|
+
* @param value The value to save; anything but a string is converted with `String()`.
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* THRUNIUM.Storage.set('highscore', 120);
|
|
11
|
+
* THRUNIUM.Storage.get('highscore'); // '120'
|
|
12
|
+
* ```
|
|
13
|
+
* @example
|
|
14
|
+
* ```js
|
|
15
|
+
* var save = { level: 3, coins: 40 };
|
|
16
|
+
* THRUNIUM.Storage.set('save', JSON.stringify(save));
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare function set(name: string, value: unknown): true;
|
|
20
|
+
/**
|
|
21
|
+
* Reads a value saved with `set()`, as a string, or `null` if nothing is saved under `name`. Values saved by 1.0.0 still read back. Since 1.1.0 it no longer throws when another cookie on the page contains a malformed `%` escape.
|
|
22
|
+
* @param name Name the value was saved under.
|
|
23
|
+
* @example
|
|
24
|
+
* ```js
|
|
25
|
+
* var highscore = Number(THRUNIUM.Storage.get('highscore')) || 0;
|
|
26
|
+
* ```
|
|
27
|
+
* @example
|
|
28
|
+
* ```js
|
|
29
|
+
* var saved = THRUNIUM.Storage.get('save');
|
|
30
|
+
* var save = saved ? JSON.parse(saved) : { level: 1, coins: 0 };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function get(name: string): string | null;
|
|
34
|
+
export declare const storage: {
|
|
35
|
+
set: typeof set;
|
|
36
|
+
get: typeof get;
|
|
37
|
+
};
|
|
38
|
+
export {};
|