i has a stick!
This commit is contained in:
parent
dd62cecd50
commit
b0b10ef54c
3 changed files with 43 additions and 0 deletions
|
|
@ -1,3 +1,5 @@
|
||||||
|
let speed = 100
|
||||||
|
|
||||||
let setup = fn() {
|
let setup = fn() {
|
||||||
return {
|
return {
|
||||||
.color: {
|
.color: {
|
||||||
|
|
@ -23,6 +25,15 @@ let setup = fn() {
|
||||||
|
|
||||||
let update = fn(state, input) {
|
let update = fn(state, input) {
|
||||||
let delta = get_frame_time();
|
let delta = get_frame_time();
|
||||||
|
let movement = {
|
||||||
|
.x: input.gamepad1.sticks.left.x,
|
||||||
|
.y: input.gamepad1.sticks.left.y,
|
||||||
|
};
|
||||||
|
|
||||||
|
state.rect.dimensions.x =
|
||||||
|
state.rect.dimensions.x + (delta * speed * movement.x);
|
||||||
|
state.rect.dimensions.y =
|
||||||
|
state.rect.dimensions.y + (delta * speed * movement.y);
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -203,6 +203,18 @@ impl From<i32> for Expr {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<f32> for Value {
|
||||||
|
fn from(f: f32) -> Value {
|
||||||
|
Value::Float(f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<f32> for Expr {
|
||||||
|
fn from(f: f32) -> Expr {
|
||||||
|
Expr::Value(f.into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl From<bool> for Value {
|
impl From<bool> for Value {
|
||||||
fn from(b: bool) -> Value {
|
fn from(b: bool) -> Value {
|
||||||
Value::Boolean(b)
|
Value::Boolean(b)
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,25 @@ pub fn update(state: &mut State, input: Input) {
|
||||||
("down", input.gamepad1.dpad.down.into()),
|
("down", input.gamepad1.dpad.down.into()),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
"sticks",
|
||||||
|
helpers::record(vec![
|
||||||
|
(
|
||||||
|
"left",
|
||||||
|
helpers::record(vec![
|
||||||
|
("x", input.gamepad1.left_stick.x.into()),
|
||||||
|
("y", (0.0 - input.gamepad1.left_stick.y).into()),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"right",
|
||||||
|
helpers::record(vec![
|
||||||
|
("x", input.gamepad1.right_stick.x.into()),
|
||||||
|
("y", (0.0 - input.gamepad1.right_stick.y).into()),
|
||||||
|
]),
|
||||||
|
),
|
||||||
|
]),
|
||||||
|
),
|
||||||
]),
|
]),
|
||||||
)]);
|
)]);
|
||||||
match interpret::interpret(
|
match interpret::interpret(
|
||||||
|
|
@ -105,6 +124,7 @@ pub fn fetch_events(state: &mut State) -> Input {
|
||||||
let mut input = Input::new();
|
let mut input = Input::new();
|
||||||
|
|
||||||
for gamepad in state.gamepads.all() {
|
for gamepad in state.gamepads.all() {
|
||||||
|
//println!("{:#?}", gamepad.all_currently_pressed().collect::<Vec<_>>());
|
||||||
// action buttons
|
// action buttons
|
||||||
input.gamepad1.buttons.a = gamepad.is_currently_pressed(gamepads::Button::ActionRight);
|
input.gamepad1.buttons.a = gamepad.is_currently_pressed(gamepads::Button::ActionRight);
|
||||||
input.gamepad1.buttons.b = gamepad.is_currently_pressed(gamepads::Button::ActionDown);
|
input.gamepad1.buttons.b = gamepad.is_currently_pressed(gamepads::Button::ActionDown);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue