This commit is contained in:
me 2025-12-25 00:44:18 +02:00
parent bb5a24fa2b
commit 690c600941
2 changed files with 124 additions and 28 deletions

41
games/basic.ayin Normal file
View file

@ -0,0 +1,41 @@
let migrate = fn(state) {
state
}
let setup = fn() {
return {
.color: {
.r: 0,
.g: 0,
.b: 100,
},
}
}
let update = fn(state, input) {
let x = if input.gamepad1.dpad.up { 1 } else { 0 } + if input.gamepad1.dpad.down { -1 } else { 0 }
let new_blue = state.color.b + x
state.color.b = min(255, max(0, new_blue))
}
let draw = fn(state) {
frame_clear(state.color.r, state.color.g, state.color.b)
}
let min = fn(a,b) {
if a < b {
a
} else {
b
}
}
let max = fn(a,b) {
if a < b {
b
} else {
a
}
}

111
readme.md
View file

@ -1,46 +1,99 @@
Ayin Ayin 👁️‍🗨️
---- -------
Programming language and games in 1 week inspired by Langjam Gamejam.
- Tiny, procedural, gamedev ## Main ideas
- only user input is controller input
- Live code reload - Tiny procedural language specifically for gamedev
- int, float, string, char, bool - Wrapped by a game framework
- arrays and objects - Only user input is controller input (or specific keyboard keys)
- variables and functions - Basic types: int, float, string, char, bool, objects, arrays, first-class functions
- if, loop, break, return - if, loop, break, return
- function calls - ✨Live code reload✨
- first class functions
``` ## Basic example
let setup = fn() {
return {
.player: { .position: { .x: 10, .y: 20 }, },
}
}
let update = fn(state, events) {
let new = 100
state.player.position.x = new
state
}
let draw = fn(frame, state) {
frame_clear(0,0,0)
}
```rs
let migrate = fn(state) { let migrate = fn(state) {
state state
} }
let setup = fn() {
return {
.color: {
.r: 0,
.g: 0,
.b: 100,
},
}
}
let update = fn(state, input) {
let x = if input.gamepad1.dpad.up { 1 } else { 0 } + if input.gamepad1.dpad.down { -1 } else { 0 }
let new_blue = state.color.b + x
state.color.b = min(255, max(0, new_blue))
}
let draw = fn(state) {
frame_clear(state.color.r, state.color.g, state.color.b)
}
let min = fn(a,b) {
if a < b {
a
} else {
b
}
}
let max = fn(a,b) {
if a < b {
b
} else {
a
}
}
``` ```
- dynamic software updating could occur every frame
- user might be required to migrate the state (migrate function is hashed and only applied on updates when it is changed)
## Program interface
A program is consists of 4 functions.
- `let setup = fn() -> state` - create a state object for your program. Runs at the start of the program.
- `let update = fn(state, input)` - update the state using user inputs at each game loop cycle.
- `let draw = fn(state)` - draw the state to the screen at the end of each game loop cycle.
- `let migrate = fn(state) -> state'` - update the game state to a new start, runs on live reloading.
### Live reloading
- Live code reloading watches the file for changes and updates the code between game loop cycles while keeping the state.
- The `migrate` function is used to migrate the state value for when the structure of the state changes.
## Build instructions ## Build instructions
### Non-web
To run There-she-is:
```
make run
```
On Fedora, required for hot code reloading:
```
sudo dnf install systemd-devel
```
### WASM ### WASM
Requires to build for wasm:
``` ```
rustup target add wasm32-unknown-unknown rustup target add wasm32-unknown-unknown
``` ```
@ -48,3 +101,5 @@ rustup target add wasm32-unknown-unknown
``` ```
make wasm make wasm
``` ```
Go to `html/` and start a web server.