-
Notifications
You must be signed in to change notification settings - Fork 0
/
snake_controller.cpp
36 lines (30 loc) · 1.23 KB
/
snake_controller.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// Created by asuka on 10.03.2023.
//
# include <snake_controller.hpp>
# include <keys_input.hpp>
namespace snake {
SnakeController::SnakeController(Snake& snake)
: snake_(snake) {}
void SnakeController::input(const KeysInput& keys_input) {
if (keys_input.get_key_state(VirtualKey::key_w) == VirtualKeyAction::press ||
keys_input.get_key_state(VirtualKey::key_up) == VirtualKeyAction::press) {
direction = SnakeMove::up;
}
if (keys_input.get_key_state(VirtualKey::key_s) == VirtualKeyAction::press ||
keys_input.get_key_state(VirtualKey::key_down) == VirtualKeyAction::press) {
direction = SnakeMove::down;
}
if (keys_input.get_key_state(VirtualKey::key_d) == VirtualKeyAction::press ||
keys_input.get_key_state(VirtualKey::key_right) == VirtualKeyAction::press) {
direction = SnakeMove::right;
}
if (keys_input.get_key_state(VirtualKey::key_a) == VirtualKeyAction::press ||
keys_input.get_key_state(VirtualKey::key_left) == VirtualKeyAction::press) {
direction = SnakeMove::left;
}
}
void SnakeController::update() {
snake_.move(direction);
}
} // snake