Paulo Laureano Because coding is fun!

Example "gamepad input" in Rust


use raylib::prelude::GamepadNumber::*;
use raylib::prelude::*;

fn main() {
let screen_width = 800.0;
let screen_height = 450.0;

// there seems to be no SetConfigFlags() wrapped
// raylib::set_config_flags(FLAG_MSAA_4X_HINT);

let (mut rl, thread) = raylib::init()
.size(screen_width as i32, screen_height as i32)
.title("raylib [core] example - gamepad input")
.build();

rl.set_target_fps(60); // Set our game to run at 60 frames-per-second

while !rl.window_should_close() {
let mut d = rl.begin_drawing(&thread);

d.clear_background(Color::RAYWHITE);

if d.is_gamepad_available(GAMEPAD_PLAYER1 as u32) {
d.draw_text(
&format!("GP1: {:?}", d.get_gamepad_name(GAMEPAD_PLAYER1 as u32)),
10,
10,
10,
Color::BLACK,
);

d.draw_text(
&format!(
"DETECTED AXIS [{}]:",
d.get_gamepad_axis_count(GAMEPAD_PLAYER1 as u32)
),
10,
50,
10,
Color::MAROON,
);

for i in 0..d.get_gamepad_axis_count(GAMEPAD_PLAYER1 as u32) {
d.draw_text(
&format!(
"AXIS {}: {}",
i,
d.get_gamepad_axis_movement(GAMEPAD_PLAYER1 as u32, i as u32)
),
20,
70 + 20 * i,
10,
Color::DARKGRAY,
);
}

d.draw_text(
&format!("DETECTED BUTTON: {:?}", d.get_gamepad_button_pressed()),
10,
430,
10,
Color::RED,
);
} else {
d.draw_text("GP1: NOT DETECTED", 10, 10, 10, Color::GRAY);
}
}
}