-
Notifications
You must be signed in to change notification settings - Fork 1
/
null0.wit
executable file
·577 lines (453 loc) · 14.2 KB
/
null0.wit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
interface types {
record vector2 {
x: s32,
y: s32,
}
record rect {
x: s32,
y: s32,
w: u32,
h: u32,
}
record color {
r: u8,
g: u8,
b: u8,
a: u8,
}
enum filtertype {
NEARESTNEIGHBOR,
BILINEAR,
SMOOTH,
}
record sfxparams {
randseed: u32,
wavetype: sfxwave,
attacktime: f32,
sustaintime: f32,
sustainpunch: f32,
decaytime: f32,
startfrequency: f32,
minfrequency: f32,
slide: f32,
deltaslide: f32,
vibratodepth: f32,
vibratospeed: f32,
changeamount: f32,
changespeed: f32,
squareduty: f32,
dutysweep: f32,
repeatspeed: f32,
phaseroffset: f32,
phasersweep: f32,
lpfcutoff: f32,
lpfcutoffsweep: f32,
lpfresonance: f32,
hpfcutoff: f32,
hpfcutoffsweep: f32,
}
enum sfxpreset {
COIN,
LASER,
EXPLOSION,
POWERUP,
HURT,
JUMP,
SELECT,
}
enum sfxwave {
SQUARE,
SAW,
SINE,
NOISE,
TRIANGLE,
PINK,
}
enum key {
INVALID,
SPACE,
APOSTROPHE,
COMMA,
MINUS,
PERIOD,
SLASH,
N0,
N1,
N2,
N3,
N4,
N5,
N6,
N7,
N8,
N9,
SEMICOLON,
EQUAL,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
LEFT-BRACKET,
BACKSLASH,
RIGHT-BRACKET,
GRAVE-ACCENT,
WORLD1,
WORLD2,
ESCAPE,
ENTER,
TAB,
BACKSPACE,
INSERT,
DELETE,
RIGHT,
LEFT,
DOWN,
UP,
PAGE-UP,
PAGE-DOWN,
HOME,
END,
CAPS-LOCK,
SCROLL-LOCK,
NUM-LOCK,
PRINT-SCREEN,
PAUSE,
F1,
F2,
F3,
F4,
F5,
F6,
F7,
F8,
F9,
F10,
F11,
F12,
F13,
F14,
F15,
F16,
F17,
F18,
F19,
F20,
F21,
F22,
F23,
F24,
F25,
KP-N0,
KP-N1,
KP-N2,
KP-N3,
KP-N4,
KP-N5,
KP-N6,
KP-N7,
KP-N8,
KP-N9,
KP-DECIMAL,
KP-DIVIDE,
KP-MULTIPLY,
KP-SUBTRACT,
KP-ADD,
KP-ENTER,
KP-EQUAL,
LEFT-SHIFT,
LEFT-CONTROL,
LEFT-ALT,
LEFT-SUPER,
RIGHT-SHIFT,
RIGHT-CONTROL,
RIGHT-ALT,
RIGHT-SUPER,
MENU,
}
enum mousebutton {
UNKNOWN,
LEFT,
RIGHT,
MIDDLE,
}
enum gamepadbutton {
UNKNOWN,
UP,
RIGHT,
DOWN,
LEFT,
Y,
B,
A,
X,
LEFTSHOULDER,
LEFTTRIGGER,
RIGHTSHOULDER,
RIGHTTRIGGER,
SELECT,
MENU,
START,
LEFTTHUMB,
RIGHTTHUMB,
}
}
interface sound {
use types.{sfxparams,sfxpreset};
// Load a sound from a file in cart
load-sound: func(filename: string) -> u32;
// Play a sound
play-sound: func(sound: u32, loop: bool);
// Stop a sound
stop-sound: func(sound: u32);
// Create a new sound-effect from some sfxr params
new-sfx: func(params: sfxparams) -> u32;
// Generate randomized preset sfxr params
preset-sfx: func(params: sfxparams, preset: sfxpreset);
// Create a new sfxr from a .rfx file
load-sfx: func(filename: string) -> sfxparams;
// Unload a sound
unload-sound: func(sound: u32);
}
interface input {
use types.{key,gamepadbutton,mousebutton,vector2};
// Has the key been pressed? (tracks unpress/read correctly)
key-pressed: func(key: key) -> bool;
// Is the key currently down?
key-down: func(key: key) -> bool;
// Has the key been released? (tracks press/read correctly)
key-released: func(key: key) -> bool;
// Is the key currently up?
key-up: func(key: key) -> bool;
// Has the button been pressed? (tracks unpress/read correctly)
gamepad-button-pressed: func(gamepad: s32, button: gamepadbutton) -> bool;
// Is the button currently down?
gamepad-button-down: func(gamepad: s32, button: gamepadbutton) -> bool;
// Has the button been released? (tracks press/read correctly)
gamepad-button-released: func(gamepad: s32, button: gamepadbutton) -> bool;
// Get current position of mouse
mouse-position: func() -> vector2;
// Has the button been pressed? (tracks unpress/read correctly)
mouse-button-pressed: func(button: mousebutton) -> bool;
// Is the button currently down?
mouse-button-down: func(button: mousebutton) -> bool;
// Has the button been released? (tracks press/read correctly)
mouse-button-released: func(button: mousebutton) -> bool;
// Is the button currently up?
mouse-button-up: func(button: mousebutton) -> bool;
}
interface graphics {
use types.{color,vector2,rect,filtertype};
// Create a new blank image
new-image: func(width: s32, height: s32, color: color) -> u32;
// Copy an image to a new image
image-copy: func(image: u32) -> u32;
// Create an image from a region of another image
image-subimage: func(image: u32, region: rect) -> u32;
// Clear the screen
clear: func(color: color);
// Draw a single pixel on the screen
point: func(x: s32, y: s32, color: color);
// Draw a line on the screen
line: func(start:vector2, end:vector2, color: color);
// Draw a filled rectangle on the screen
rectangle: func(rect: rect, color: color);
// Draw a filled triangle on the screen
triangle: func(pt1: vector2, pt2: vector2, pt3: vector2, color: color);
// Draw a filled ellipse on the screen
ellipse: func(center: vector2, radius: vector2, color: color);
// Draw a filled circle on the screen
circle: func(center: vector2, radius: s32, color: color);
// Draw a filled polygon on the screen
polygon: func(points: list<vector2>, color: color);
// Draw several lines on the screen
polyline: func(points: list<vector2>, color: color);
// Draw a filled arc on the screen
arc: func(center:vector2, radius: s32, startangle: f32, endangle: f32, segments: s32, color: color);
// Draw a filled round-rectangle on the screen
rectangle-rounded: func(rect: rect, radius: s32, color: color);
// Draw an image on the screen
draw-image: func(src: u32, pos: vector2);
// Draw a tinted image on the screen
draw-image-tinted: func(src: u32, pos:vector2, tint: color);
// Draw an image, rotated, on the screen
draw-image-rotated: func(src: u32, pos: vector2, degrees: f32, offset: vector2, filter: filtertype);
// Draw an image, flipped, on the screen
draw-image-flipped: func(src: u32, pos: vector2, fliphorizontal: bool, flipvertical: bool, flipdiagonal: bool);
// Draw an image, scaled, on the screen
draw-image-scaled: func(src: u32, pos: vector2, scale: vector2, offset: vector2, filter: filtertype);
// Draw some text on the screen
text: func(font: u32, text: string, pos: vector2, color: color);
// Save an image to persistant storage
save-image: func(image: u32, filename: string);
// Load an image from a file in cart
load-image: func(filename: string) -> u32;
// Resize an image, in-place
image-resize: func(image: u32, rect: rect, fill: color);
// Scale an image, in-place
image-scale: func(image: u32, scale: vector2, filter: filtertype);
// Replace a color in an image, in-place
image-replace: func(image: u32, color: color, replace: color);
// Tint a color in an image, in-place
image-tint: func(image: u32, color: color);
// Fade a color in an image, in-place
image-fade: func(image: u32, alpha: f32);
// Copy a font to a new font
font-copy: func(font: u32) -> u32;
// Scale a font, return a new font
font-scale: func(font: u32, scale: vector2, filter: filtertype) -> u32;
// Load a BMF font from a file in cart
load-font-bmf: func(filename: string, characters: string) -> u32;
// Load a BMF font from an image
load-font-bmf-from-image: func(image: u32, characters: string) -> u32;
// Measure the size of some text
measure-text: func(font: u32, text: string) -> vector2;
// Measure an image (use 0 for screen)
measure-image: func(image: u32) -> vector2;
// Load a TTY font from a file in cart
load-font-tty: func(filename: string, glyphsize: vector2, characters: string) -> u32;
// Load a TTY font from an image
load-font-tty-from-image: func(image: u32, glyphsize: vector2, characters: string) -> u32;
// Load a TTF font from a file in cart
load-font-ttf: func(filename: string, fontsize: s32) -> u32;
// Invert the colors in an image, in-place
image-invert: func(image: u32);
// Calculate a rectangle representing the available alpha border in an image
image-alpha-border: func(image: u32, threshold: f32) -> rect;
// Crop an image, in-place
image-crop: func(image: u32, rect: rect);
// Crop an image based on the alpha border, in-place
image-alpha-crop: func(image: u32, threshold: f32);
// Adjust the brightness of an image, in-place
image-brightness: func(image: u32, factor: f32);
// Flip an image, in-place
image-flip: func(image: u32, horizontal: bool, vertical: bool);
// Change the contrast of an image, in-place
image-contrast: func(image: u32, contrast: f32);
// Use an image as an alpha-mask on another image
image-alpha-mask: func(image: u32, alphamask: u32, pos: vector2);
// Create a new image, rotating another image
image-rotate: func(image: u32, degrees: f32, filter: filtertype) -> u32;
// Create a new image of a gradient
image-gradient: func(size: vector2, topleft: color, topright: color, bottomleft: color, bottomright: color) -> u32;
// Unload an image
unload-image: func(image: u32);
// Unload a font
unload-font: func(font: u32);
// Clear an image
clear-on-image: func(destination: u32, color: color);
// Draw a single pixel on an image
point-on-image: func(destination: u32, x: s32, y: s32, color: color);
// Draw a line on an image
line-on-image: func(destination: u32, start: vector2, end: vector2, color: color);
// Draw a filled rectangle on an image
rectangle-on-image: func(destination: u32, rect: rect, color: color);
// Draw a filled triangle on an image
triangle-on-image: func(destination: u32, pt1: vector2, pt2: vector2, pt3: vector2, color: color);
// Draw a filled ellipse on an image
ellipse-on-image: func(destination: u32, center: vector2, radius: vector2, color: color);
// Draw a circle on an image
circle-on-image: func(destination: u32, center: vector2, radius: s32, color: color);
// Draw a filled polygon on an image
polygon-on-image: func(destination: u32, points: list<vector2>, color: color);
// Draw several lines on an image
polyline-on-image: func(destination: u32, points: list<vector2>, color: color);
// Draw a filled round-rectangle on an image
rectangle-rounded-on-image: func(destination: u32, rect: rect, radius: s32, color: color);
// Draw an image on an image
image-on-image: func(destination: u32, src: u32, pos: vector2);
// Draw a tinted image on an image
image-tint-on-image: func(destination: u32, src: u32, pos: vector2, tint: color);
// Draw an image, rotated, on an image
image-rotated-on-image: func(destination: u32, src: u32, pos: vector2, degrees: f32, offset: vector2, filter: filtertype);
// Draw an image, flipped, on an image
image-flipped-on-image: func(destination: u32, src: u32, pos: vector2, fliphorizontal: bool, flipvertical: bool, flipdiagonal: bool);
// Draw an image, scaled, on an image
image-scaled-on-image: func(destination: u32, src: u32, pos: vector2, scale: vector2, offset: vector2, filter: filtertype);
// Draw some text on an image
text-on-image: func(destination: u32, font: u32, text: string, pos: vector2, color: color);
// Draw a 1px outlined rectangle on the screen
rectangle-outline: func(pos: vector2, width: s32, height: s32, color: color);
// Draw a 1px outlined triangle on the screen
triangle-outline: func(pt1: vector2, pt2: vector2, pt3: vector2, color: color);
// Draw a 1px outlined ellipse on the screen
ellipse-outline: func(center: vector2, radius: vector2, color: color);
// Draw a 1px outlined circle on the screen
circle-outline: func(center: vector2, radius: s32, color: color);
// Draw a 1px outlined polygon on the screen
polygon-outline: func(points: list<vector2>, color: color);
// Draw a 1px outlined arc on the screen
arc-outline: func(center: vector2, radius: f32, startangle: f32, endangle: f32, segments: s32, color: color);
// Draw a 1px outlined round-rectangle on the screen
rectangle-rounded-outline: func(rect: rect, radius: s32, color: color);
// Draw a 1px outlined rectangle on an image
rectangle-outline-on-image: func(destination: u32, pos: vector2, width: s32, height: s32, color: color);
// Draw a 1px outlined triangle on an image
triangle-outline-on-image: func(destination: u32, pt1: vector2, pt2: vector2, pt3: vector2, color: color);
// Draw a 1px outlined ellipse on an image
ellipse-outline-on-image: func(destination: u32, center: vector2, radius: vector2, color: color);
// Draw a 1px outlined circle on an image
circle-outline-on-image: func(destination: u32, center: vector2, radius: s32, color: color);
// Draw a 1px outlined polygon on an image
polygon-outline-on-image: func(destination: u32, points: list<vector2>, color: color);
// Draw a 1px outlined round-rectangle on an image
rectangle-rounded-outline-on-image: func(destination: u32, rect: rect, radius: s32, color: color);
}
interface colors {
use types.{color,vector2};
// Tint a color with another color
tint: func(color: color, tint: color) -> color;
// Fade a color
fade: func(color: color, alpha: f32) -> color;
// Change the brightness of a color
brightness: func(color: color, factor: f32) -> color;
// Invert a color
invert: func(color: color) -> color;
// Blend 2 colors together
alpha-blend: func(dst: color, src: color) -> color;
// color_contrast
contrast: func(color: color, contrast: f32) -> color;
// Interpolate colors
bilinear-interpolate: func(color00: color, color01: color, color10: color, color11: color, coordinate: vector2) -> color;
}
interface callbacks {
use types.{gamepadbutton};
// called on cart load
load: func();
// called on cart unload
unload: func();
// called on every frame
update: func();
// called when a mapped input is triggered
button-down: func(button: gamepadbutton);
// called when a mapped input is triggered
button-up: func(button: gamepadbutton);
}
world null0 {
import sound;
import input;
import graphics;
import colors;
export callbacks;
}