real program
This commit is contained in:
parent
0edde5d50c
commit
ad06f7f616
5 changed files with 77 additions and 10 deletions
2
Makefile
2
Makefile
|
|
@ -12,7 +12,7 @@ test:
|
||||||
|
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run:
|
run:
|
||||||
cargo run
|
cargo run -- game.ayin
|
||||||
|
|
||||||
.PHONY: review
|
.PHONY: review
|
||||||
review:
|
review:
|
||||||
|
|
|
||||||
19
game.ayin
Normal file
19
game.ayin
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
let setup = fn() {
|
||||||
|
return {
|
||||||
|
.player: { .position: { .x: 10, .y: 20 }, },
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
let update = fn(state, input) {
|
||||||
|
let new = 100;
|
||||||
|
state.player.position.x = new;
|
||||||
|
return state;
|
||||||
|
};
|
||||||
|
|
||||||
|
let draw = fn(frame, state) {
|
||||||
|
frame.clear(0,0,0);
|
||||||
|
};
|
||||||
|
|
||||||
|
let migrate = fn(state) {
|
||||||
|
return { .player: { .pos: state.player.position } };
|
||||||
|
};
|
||||||
16
src/main.rs
16
src/main.rs
|
|
@ -1,4 +1,3 @@
|
||||||
use ayin::ast;
|
|
||||||
use ayin::runtime::*;
|
use ayin::runtime::*;
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
|
|
||||||
|
|
@ -17,12 +16,23 @@ async fn main() {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
info!("Hello, 👁️🗨️!");
|
info!("Hello, 👁️🗨️!");
|
||||||
|
|
||||||
let mut state = setup(ast::Program(vec![])).await;
|
let args: Vec<String> = std::env::args().collect();
|
||||||
|
let file = args[1].clone();
|
||||||
|
|
||||||
|
match std::fs::read_to_string(file) {
|
||||||
|
Err(err) => println!("Error: {err:#?}"),
|
||||||
|
Ok(txt) => match ayin::parser::parse_file(txt) {
|
||||||
|
Err(err) => println!("Error: {err:#?}"),
|
||||||
|
Ok(program) => {
|
||||||
|
let mut state = setup(program).await;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let events = fetch_events();
|
let events = fetch_events(&mut state);
|
||||||
update(&mut state, events);
|
update(&mut state, events);
|
||||||
draw(&state);
|
draw(&state);
|
||||||
next_frame().await;
|
next_frame().await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use super::types::*;
|
use super::types::*;
|
||||||
use crate::ast;
|
use crate::ast;
|
||||||
|
use crate::ast::helpers;
|
||||||
use crate::interpret;
|
use crate::interpret;
|
||||||
use gamepads;
|
use gamepads;
|
||||||
use macroquad::prelude::*;
|
use macroquad::prelude::*;
|
||||||
|
|
@ -64,7 +65,39 @@ pub async fn migrate(mut state: State, code: ast::Program) -> State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update(_state: &mut State, input: Input) {}
|
pub fn update(state: &mut State, input: Input) {
|
||||||
|
let input = helpers::record(vec![(
|
||||||
|
"gamepad1",
|
||||||
|
helpers::record(vec![
|
||||||
|
(
|
||||||
|
"buttons",
|
||||||
|
helpers::record(vec![
|
||||||
|
("a", input.gamepad1.buttons.a.into()),
|
||||||
|
("b", input.gamepad1.buttons.b.into()),
|
||||||
|
("x", input.gamepad1.buttons.x.into()),
|
||||||
|
("y", input.gamepad1.buttons.y.into()),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"dpad",
|
||||||
|
helpers::record(vec![
|
||||||
|
("left", input.gamepad1.dpad.left.into()),
|
||||||
|
("right", input.gamepad1.dpad.right.into()),
|
||||||
|
("up", input.gamepad1.dpad.up.into()),
|
||||||
|
("down", input.gamepad1.dpad.down.into()),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
)]);
|
||||||
|
match interpret::interpret(
|
||||||
|
&mut state.state,
|
||||||
|
"update".into(),
|
||||||
|
vec![ast::Expr::Value(state.game_state.clone()), input],
|
||||||
|
) {
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(err) => println!("Error: {}", err),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn fetch_events(state: &mut State) -> Input {
|
pub fn fetch_events(state: &mut State) -> Input {
|
||||||
state.gamepads.poll();
|
state.gamepads.poll();
|
||||||
|
|
@ -117,4 +150,9 @@ pub fn draw(state: &State) {
|
||||||
});
|
});
|
||||||
|
|
||||||
set_default_camera();
|
set_default_camera();
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"{:#?}",
|
||||||
|
interpret::value_to_stadnalone_expr(&state.state, state.game_state.clone())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ pub struct Menu {
|
||||||
pub menu: bool,
|
pub menu: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub const SCALE: i32 = 4;
|
pub const SCALE: i32 = 1;
|
||||||
|
|
||||||
pub const SCREEN_WIDTH: i32 = 360 * SCALE;
|
pub const SCREEN_WIDTH: i32 = 360 * SCALE;
|
||||||
pub const SCREEN_HEIGHT: i32 = 360 * SCALE;
|
pub const SCREEN_HEIGHT: i32 = 360 * SCALE;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue