Dino compiler: language, formatter, language server, docs, editor support
Compiler in Rust (lexer, parser, checker, C codegen), maps, chars, dino fmt, dino lsp (diagnostics, formatting, outline, definition, hover, completion, signature help), docs, examples, VS Code/Vim files. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e2779f447
commit
eaf9567a36
117 files changed
+19970
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// A game: bouncing square. Structs are values, no heap, no GC.
|
||||
import gfx
|
||||
|
||||
struct Vec2 {
|
||||
x, y: f32
|
||||
|
||||
func add(b: Vec2): Vec2 { return Vec2{x + b.x, y + b.y} }
|
||||
func scale(k: f32): Vec2 { return Vec2{x * k, y * k} }
|
||||
}
|
||||
|
||||
struct Player {
|
||||
pos: Vec2
|
||||
vel: Vec2
|
||||
size: f32
|
||||
|
||||
func update(dt: f32) { // writes pos/vel: inferred as mutating
|
||||
pos = pos.add(vel.scale(dt))
|
||||
if pos.x < 0 || pos.x > 800 { vel.x = -vel.x }
|
||||
if pos.y < 0 || pos.y > 600 { vel.y = -vel.y }
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
var win = gfx.open("Dino", 800, 600)
|
||||
var player = Player{pos: Vec2{100, 100}, vel: Vec2{200, 150}, size: 32}
|
||||
|
||||
for win.is_open() {
|
||||
player.update(win.dt())
|
||||
win.clear(gfx.BLACK)
|
||||
win.rect(player.pos.x, player.pos.y, player.size, player.size, gfx.GREEN)
|
||||
win.present()
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user