mirror of
https://github.com/italicsjenga/rust_minifb.git
synced 2025-01-12 03:51:37 +11:00
aa5d84eb2b
* Added get_keys_pressed(KeyRepeat::Yes/No) in order for the user to decide if repeat should be used or not * added is_key_pressed(key, KeyRepeat::Yes/No) * Added set_key_repeat_delay/rate in order to control the rate/delays of keys
49 lines
1.2 KiB
Rust
49 lines
1.2 KiB
Rust
extern crate minifb;
|
|
|
|
use minifb::*;
|
|
|
|
const WIDTH: usize = 640;
|
|
const HEIGHT: usize = 360;
|
|
|
|
fn main() {
|
|
let mut noise;
|
|
let mut carry;
|
|
let mut seed = 0xbeefu32;
|
|
|
|
let mut buffer: [u32; WIDTH * HEIGHT] = [0; WIDTH * HEIGHT];
|
|
|
|
let mut window = Window::new("Noise Test - Press ESC to exit",
|
|
WIDTH,
|
|
HEIGHT,
|
|
Scale::X1,
|
|
Vsync::No)
|
|
.unwrap();
|
|
|
|
while window.is_open() && !window.is_key_down(Key::Escape) {
|
|
for i in buffer.iter_mut() {
|
|
noise = seed;
|
|
noise >>= 3;
|
|
noise ^= seed;
|
|
carry = noise & 1;
|
|
noise >>= 1;
|
|
seed >>= 1;
|
|
seed |= carry << 30;
|
|
noise &= 0xFF;
|
|
*i = (noise << 16) | (noise << 8) | noise;
|
|
}
|
|
|
|
window.get_keys_pressed(KeyRepeat::No).map(|keys| {
|
|
for t in keys.iter() {
|
|
match *t {
|
|
Key::W => println!("holding w!"),
|
|
Key::T => println!("holding t!"),
|
|
_ => (),
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
window.update(&buffer);
|
|
}
|
|
}
|