physical button press
This commit is contained in:
@@ -8,14 +8,13 @@
|
||||
#include "../game/state.h"
|
||||
#include "../game/animation.h"
|
||||
#include "../game/collision.h"
|
||||
#include "../hardware/uart.h"
|
||||
#include "../hardware/button.h"
|
||||
#include "../render/player.h"
|
||||
#include "../render/obstacle.h"
|
||||
#include "../timing/speed_controller.h"
|
||||
#include "../timing/movement_controller.h"
|
||||
#include "../game/obstacle_system.h"
|
||||
|
||||
extern BufferedSerial serial_port;
|
||||
extern DigitalOut led;
|
||||
|
||||
// Constants
|
||||
@@ -23,12 +22,12 @@ extern DigitalOut led;
|
||||
constexpr int PLAYER_X = 29;
|
||||
constexpr int PLAYER_Y = 6;
|
||||
|
||||
void draw_mask(const char *unused_filename, int shift, const char *text);
|
||||
void draw_mask(const char *unused_filename, int shift);
|
||||
|
||||
void render_loop(int speed) {
|
||||
MovementState player_state;
|
||||
AnimationController animation;
|
||||
UartReader uart(serial_port);
|
||||
ButtonHandler button;
|
||||
MovementController mover(PLAYER_X, VIEW_WIDTH);
|
||||
SpeedController timing;
|
||||
timing.set_ground_speed(speed);
|
||||
@@ -64,24 +63,19 @@ void render_loop(int speed) {
|
||||
int spawn_x = VIEW_WIDTH;
|
||||
int idx = spawn_obstacle(s_type, spawn_x);
|
||||
if (idx >= 0) {
|
||||
obstacle_pool[idx].active = true;
|
||||
obstacle_pool[idx].active = true;
|
||||
}
|
||||
}
|
||||
|
||||
need_redraw = false;
|
||||
UartEvent uart_event = uart.poll();
|
||||
ButtonEvent button_event = button.poll();
|
||||
|
||||
if (uart_event == UartEvent::MessageUpdate) {
|
||||
need_redraw = true;
|
||||
}
|
||||
|
||||
if (uart_event == UartEvent::Triggered) {
|
||||
if (button_event == ButtonEvent::Pressed) {
|
||||
PlayerState current = player_state.get_state();
|
||||
|
||||
if (current == PlayerState::Walk || current == PlayerState::Run) {
|
||||
player_state.start_crawl(PlayerState::Crawl1);
|
||||
}
|
||||
else if (current == PlayerState::Crawl1) {
|
||||
} else if (current == PlayerState::Crawl1) {
|
||||
player_state.start_crawl(PlayerState::Crawl2);
|
||||
}
|
||||
|
||||
@@ -108,7 +102,7 @@ void render_loop(int speed) {
|
||||
|
||||
if (need_redraw) {
|
||||
player_state.toggle_walk_frame(player_speed, anim_tick_counter);
|
||||
draw_mask(bg_file, animation.get_shift(), uart.get_message());
|
||||
draw_mask(bg_file, animation.get_shift());
|
||||
FrameSelection frame = player_state.get_frame_selection();
|
||||
|
||||
CharacterPosition draw_pos = get_aligned_frame_position(pos, frame.movement, frame.frame_index);
|
||||
|
||||
Reference in New Issue
Block a user