Fix issues with user input.

Maybe we should do something about the 36 if statements in handle_input
This commit is contained in:
Rekai Musuka 2020-07-14 23:35:00 -05:00
parent 8d1a2b59d6
commit ff1a8222a8
1 changed files with 64 additions and 32 deletions

View File

@ -58,85 +58,117 @@ fn handle_input(chip8: &mut Chip8, input: &mut WinitInputHelper, control_flow: &
return;
}
// 1 -> 1
if input.key_pressed(VirtualKeyCode::Key1) {
chip8.key.set_key(0x1);
} else {
}
if input.key_released(VirtualKeyCode::Key1) {
chip8.key.unset_key(0x1);
}
// 2 -> 2
if input.key_pressed(VirtualKeyCode::Key2) {
chip8.key.set_key(0x2);
} else {
chip8.key.set_key(0x2);
}
if input.key_released(VirtualKeyCode::Key2) {
chip8.key.unset_key(0x2);
}
// 3 -> 3
if input.key_pressed(VirtualKeyCode::Key3) {
chip8.key.set_key(0x3);
} else {
chip8.key.set_key(0x3);
}
if input.key_released(VirtualKeyCode::Key3) {
chip8.key.unset_key(0x3);
}
// 4 -> C
if input.key_pressed(VirtualKeyCode::Key4) {
chip8.key.set_key(0xC);
} else {
chip8.key.set_key(0xC);
}
if input.key_released(VirtualKeyCode::Key4) {
chip8.key.unset_key(0xC);
}
// Q -> 4
if input.key_pressed(VirtualKeyCode::Q) {
chip8.key.set_key(0x4);
} else {
chip8.key.set_key(0x4);
}
if input.key_released(VirtualKeyCode::Q) {
chip8.key.unset_key(0x4);
}
// W -> 5
if input.key_pressed(VirtualKeyCode::W) {
chip8.key.set_key(0x5);
} else {
chip8.key.set_key(0x5);
}
if input.key_released(VirtualKeyCode::W) {
chip8.key.unset_key(0x5);
}
// E -> 6
if input.key_pressed(VirtualKeyCode::E) {
chip8.key.set_key(0x6);
} else {
chip8.key.set_key(0x6);
}
if input.key_released(VirtualKeyCode::E) {
chip8.key.unset_key(0x6);
}
// R -> D
if input.key_pressed(VirtualKeyCode::R) {
chip8.key.set_key(0xD);
} else {
chip8.key.set_key(0xD);
}
if input.key_released(VirtualKeyCode::R) {
chip8.key.unset_key(0xD);
}
// A -> 7
if input.key_pressed(VirtualKeyCode::A) {
chip8.key.set_key(0x7);
} else {
chip8.key.set_key(0x7);
}
if input.key_released(VirtualKeyCode::A) {
chip8.key.unset_key(0x7);
}
// S -> 8
if input.key_pressed(VirtualKeyCode::S) {
chip8.key.set_key(0x8);
} else {
chip8.key.set_key(0x8);
}
if input.key_released(VirtualKeyCode::S) {
chip8.key.unset_key(0x8);
}
// D -> 9
if input.key_pressed(VirtualKeyCode::D) {
chip8.key.set_key(0x9);
} else {
chip8.key.set_key(0x9);
}
if input.key_released(VirtualKeyCode::D) {
chip8.key.unset_key(0x9);
}
// F -> A
if input.key_pressed(VirtualKeyCode::F) {
chip8.key.set_key(0x5);
} else {
chip8.key.set_key(0x5);
chip8.key.set_key(0xE);
}
if input.key_released(VirtualKeyCode::F) {
chip8.key.unset_key(0xE);
}
// Z -> A
if input.key_pressed(VirtualKeyCode::Z) {
chip8.key.set_key(0xA);
} else {
chip8.key.set_key(0xA);
}
if input.key_released(VirtualKeyCode::Z) {
chip8.key.unset_key(0xA);
}
// X -> 0
if input.key_pressed(VirtualKeyCode::X) {
chip8.key.set_key(0x0);
} else {
chip8.key.set_key(0x0);
}
if input.key_released(VirtualKeyCode::X) {
chip8.key.unset_key(0x0);
}
// C -> B
if input.key_pressed(VirtualKeyCode::C) {
chip8.key.set_key(0xB);
} else {
chip8.key.set_key(0xB);
}
if input.key_released(VirtualKeyCode::C) {
chip8.key.unset_key(0xB);
}
// V -> F
if input.key_pressed(VirtualKeyCode::V) {
chip8.key.set_key(0xF);
} else {
chip8.key.set_key(0xF);
}
if input.key_released(VirtualKeyCode::V) {
chip8.key.unset_key(0xF);
}
}