obstacles finally spawning
This commit is contained in:
@@ -7,10 +7,13 @@
|
||||
#include "player.h"
|
||||
#include "../game/state.h"
|
||||
#include "../game/animation.h"
|
||||
#include "../game/collision.h"
|
||||
#include "../hardware/uart.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;
|
||||
@@ -38,9 +41,14 @@ void render_loop(int speed) {
|
||||
int anim_tick_counter = 0;
|
||||
int tick_counter = 0;
|
||||
int player_speed = 6;
|
||||
bool game_over = false;
|
||||
|
||||
player_state.set_state(PlayerState::Run);
|
||||
while (true) {
|
||||
|
||||
spawn_obstacle(CrawlObstacleType::Crawl1, 40);
|
||||
obstacle_pool[0].data.y = 8;
|
||||
obstacle_pool[0].active = true;
|
||||
while (!game_over) {
|
||||
tick_counter++;
|
||||
|
||||
mover.update_position(player_speed, timing.get_ground_speed());
|
||||
@@ -56,11 +64,9 @@ void render_loop(int speed) {
|
||||
if (uart_event == UartEvent::Triggered) {
|
||||
PlayerState current = player_state.get_state();
|
||||
|
||||
// pressing UART trigger while walking/running -> Crawl1
|
||||
if (current == PlayerState::Walk || current == PlayerState::Run) {
|
||||
player_state.start_crawl(PlayerState::Crawl1);
|
||||
}
|
||||
// pressing again while crawling -> Crawl2
|
||||
else if (current == PlayerState::Crawl1) {
|
||||
player_state.start_crawl(PlayerState::Crawl2);
|
||||
}
|
||||
@@ -84,6 +90,17 @@ void render_loop(int speed) {
|
||||
CharacterPosition draw_pos = get_aligned_frame_position(pos, frame.movement, frame.frame_index);
|
||||
draw_character(draw_pos.x, draw_pos.y, frame.movement, frame.frame_index);
|
||||
|
||||
for (int i = 0; i < MAX_OBSTACLES; i++) {
|
||||
if (!obstacle_pool[i].active)
|
||||
continue;
|
||||
draw_obstacle(obstacle_pool[i].data.x,
|
||||
obstacle_pool[i].data.y,
|
||||
obstacle_pool[i].type);
|
||||
}
|
||||
|
||||
if (game_over)
|
||||
break;
|
||||
|
||||
ThisThread::sleep_for(50ms);
|
||||
}
|
||||
|
||||
|
||||
31
semestralka1/src/render/obstacle.cpp
Normal file
31
semestralka1/src/render/obstacle.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
// src/render/obstacle.cpp
|
||||
#include "obstacle.h"
|
||||
#include "../assets/obstacle_crawl_frames.h"
|
||||
#include <cstdio>
|
||||
|
||||
// Draw a single obstacle ASCII sprite at (x, y)
|
||||
void draw_obstacle(int x, int y, CrawlObstacleType type) {
|
||||
const char **obstacle = nullptr;
|
||||
int obstacle_height = 0;
|
||||
|
||||
switch (type) {
|
||||
case CrawlObstacleType::Crawl1:
|
||||
obstacle = OBSTACLE_CRAWL1_FRAME;
|
||||
obstacle_height = OBSTACLE_CRAWL1_FRAME_HEIGHT;
|
||||
break;
|
||||
|
||||
case CrawlObstacleType::Crawl2:
|
||||
obstacle = OBSTACLE_CRAWL2_FRAME;
|
||||
obstacle_height = OBSTACLE_CRAWL2_FRAME_HEIGHT;
|
||||
break;
|
||||
|
||||
default:
|
||||
return; // in case of invalid type
|
||||
}
|
||||
|
||||
// Each obstacle row is printed using ANSI cursor positioning
|
||||
for (int i = 0; i < obstacle_height; i++) {
|
||||
printf("\033[%d;%dH%s", y + i + 1, x + 1, obstacle[i]);
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
7
semestralka1/src/render/obstacle.h
Normal file
7
semestralka1/src/render/obstacle.h
Normal file
@@ -0,0 +1,7 @@
|
||||
// src/render/obstacle.h
|
||||
#pragma once
|
||||
|
||||
#include "../assets/obstacle_crawl_frames.h"
|
||||
|
||||
// Draw the obstacle ASCII block starting at given (x, y)
|
||||
void draw_obstacle(int x, int y, CrawlObstacleType type);
|
||||
Reference in New Issue
Block a user