Skip to content

Commit da10a8e

Browse files
committed
chore: update README.md
1 parent 2bed060 commit da10a8e

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

README.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,32 @@ Idiomatic bindings for WASM-4 in Rust.
77
cartridges (ROMs) are small, self-contained `.wasm` files that can be built with any programming
88
language that compiles to WebAssembly.
99

10-
Usage
10+
Example
1111
----
1212

13-
TODO
13+
```rust
14+
#![no_main]
15+
16+
use wasm4 as w4;
17+
18+
struct MyRuntime {
19+
count: i32,
20+
}
21+
22+
// prints "tick" every second
23+
impl w4::rt::Runtime for MyRuntime {
24+
fn start(_: w4::rt::Resources) -> Self {
25+
MyRuntime { count: 0 }
26+
}
27+
28+
fn update(&mut self) {
29+
if self.count % 60 == 0 {
30+
w4::trace("tick");
31+
self.count = 0;
32+
}
33+
self.count += 1;
34+
}
35+
}
36+
37+
w4::main! { MyRuntime }
38+
```

0 commit comments

Comments
 (0)