You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Aside from text and symbols, many slots are empty. This is because in ASCII, the text format used for the `text()` function, doesn't have any character indexed to it. Moreover, some of them *are* mapped, but as control characters.
75
75
@@ -80,37 +80,41 @@ It's possible to print one of these characters by escaping it's charcode.
80
80
81
81
| Key | Escape Character |
82
82
|-------------|------------------|
83
-
|A button |`\x80`|
84
-
|B button |`\x81`|
83
+
|X button |`\x80`|
84
+
|Y button |`\x81`|
85
85
| Left arrow |`\x84`|
86
86
| Right arrow |`\x85`|
87
87
| Up arrow |`\x86`|
88
88
| Down arrow |`\x87`|
89
89
90
90
We could use those as instructions for our games!
91
91
92
-
<!-- <MultiLanguageCode> -->
92
+
<MultiLanguageCode>
93
93
94
94
```typescript
95
95
// Press UP to jump!
96
96
w4.text("Press \x86 to jump!", 10, 10);
97
97
```
98
98
99
-
<!-- </MultiLanguageCode> -->
99
+
```rust
100
+
// Press UP to jump!
101
+
text(b"Press \x86 to jump!", 10, 10);
102
+
```
103
+
104
+
</MultiLanguageCode>
100
105
101
106
## Custom Fonts
102
107
103
108
Since WASM-4 doesn't have a custom font, we have to figure a way to implement our own. One way to approach this is treating a font like a tilemap, except we're indexing characters instead of numbers!
104
109
105
110
The example below will print a text using the [BitScript sprite font](https://opengameart.org/content/bitscript-a-low-res-handwriting-font):
106
111
107
-
<!-- <MultiLanguageCode> -->
112
+
<MultiLanguageCode>
108
113
109
114
```typescript
110
115
import*asw4from"./wasm4";
111
116
112
117
const fontWidth =208;
113
-
const fontHeight =8;
114
118
const fontFlags =w4.BLIT_1BPP;
115
119
const charWidth =8;
116
120
const charHeight =8;
@@ -143,6 +147,18 @@ const font = memory.data<u8>([
143
147
0x42, 0x2c, 0x82, 0x84, 0x3a, 0x40, 0x08, 0x86,
144
148
0x38, 0x40, 0x3a, 0x10, 0x48, 0x46, 0x30, 0x66
145
149
]);
150
+
151
+
function drawSpace(x:i32, y:i32, column:i32, line:i32, colors:u16) {
152
+
store<u16>(w4.DRAW_COLORS, w4.DRAW_COLORS&0x0F);
153
+
w4.rect(
154
+
x+ (column*CHAR_WIDTH),
155
+
y+ (line*CHAR_HEIGHT),
156
+
CHAR_WIDTH,
157
+
CHAR_HEIGHT
158
+
);
159
+
store<u16>(w4.DRAW_COLORS, colors);
160
+
}
161
+
146
162
function write(text:string, x:i32, y:i32, colors:u16):void {
0 commit comments