obstacles comming properly well
This commit is contained in:
@@ -4,16 +4,24 @@
|
|||||||
|
|
||||||
// Crawl obstacle for CRAWL1 (2 lines tall)
|
// Crawl obstacle for CRAWL1 (2 lines tall)
|
||||||
static const char *OBSTACLE_CRAWL1_FRAME[] = {
|
static const char *OBSTACLE_CRAWL1_FRAME[] = {
|
||||||
|
"#######",
|
||||||
|
"#######",
|
||||||
|
"#######",
|
||||||
|
"#######",
|
||||||
"#######",
|
"#######",
|
||||||
"#######"
|
"#######"
|
||||||
};
|
};
|
||||||
|
|
||||||
// Crawl obstacle for CRAWL2 (4 lines tall)
|
// Crawl obstacle for CRAWL2 (4 lines tall)
|
||||||
static const char *OBSTACLE_CRAWL2_FRAME[] = {
|
static const char *OBSTACLE_CRAWL2_FRAME[] = {
|
||||||
"########",
|
"#######",
|
||||||
"########",
|
"#######",
|
||||||
"########",
|
"#######",
|
||||||
"########"
|
"#######",
|
||||||
|
"#######",
|
||||||
|
"#######",
|
||||||
|
"#######",
|
||||||
|
"#######"
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class CrawlObstacleType { Crawl1 = 0, Crawl2, COUNT };
|
enum class CrawlObstacleType { Crawl1 = 0, Crawl2, COUNT };
|
||||||
|
|||||||
@@ -15,13 +15,13 @@ constexpr int MAX_OBSTACLES = 6;
|
|||||||
static MovingObstacle obstacle_pool[MAX_OBSTACLES];
|
static MovingObstacle obstacle_pool[MAX_OBSTACLES];
|
||||||
|
|
||||||
// Create / reset obstacle in one slot
|
// Create / reset obstacle in one slot
|
||||||
inline void spawn_obstacle(CrawlObstacleType type, int x_start) {
|
inline int spawn_obstacle(CrawlObstacleType type, int x_start) {
|
||||||
for (int i = 0; i < MAX_OBSTACLES; i++) {
|
for (int i = 0; i < MAX_OBSTACLES; i++) {
|
||||||
if (!obstacle_pool[i].active) {
|
if (!obstacle_pool[i].active) {
|
||||||
obstacle_pool[i].active = true;
|
obstacle_pool[i].active = true;
|
||||||
obstacle_pool[i].type = type;
|
obstacle_pool[i].type = type;
|
||||||
obstacle_pool[i].data.x = x_start;
|
obstacle_pool[i].data.x = x_start;
|
||||||
obstacle_pool[i].data.y = 10; // hangs from ceiling
|
obstacle_pool[i].data.y = 0;
|
||||||
if (type == CrawlObstacleType::Crawl1) {
|
if (type == CrawlObstacleType::Crawl1) {
|
||||||
obstacle_pool[i].data.width = OBSTACLE_CRAWL1_COLLISION_WIDTH;
|
obstacle_pool[i].data.width = OBSTACLE_CRAWL1_COLLISION_WIDTH;
|
||||||
obstacle_pool[i].data.height = OBSTACLE_CRAWL1_COLLISION_HEIGHT;
|
obstacle_pool[i].data.height = OBSTACLE_CRAWL1_COLLISION_HEIGHT;
|
||||||
@@ -29,9 +29,10 @@ inline void spawn_obstacle(CrawlObstacleType type, int x_start) {
|
|||||||
obstacle_pool[i].data.width = OBSTACLE_CRAWL2_COLLISION_WIDTH;
|
obstacle_pool[i].data.width = OBSTACLE_CRAWL2_COLLISION_WIDTH;
|
||||||
obstacle_pool[i].data.height = OBSTACLE_CRAWL2_COLLISION_HEIGHT;
|
obstacle_pool[i].data.height = OBSTACLE_CRAWL2_COLLISION_HEIGHT;
|
||||||
}
|
}
|
||||||
break;
|
return i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update X positions; mark inactive if offscreen
|
// Update X positions; mark inactive if offscreen
|
||||||
|
|||||||
@@ -45,19 +45,12 @@ void render_loop(int speed) {
|
|||||||
|
|
||||||
player_state.set_state(PlayerState::Run);
|
player_state.set_state(PlayerState::Run);
|
||||||
|
|
||||||
{
|
|
||||||
CrawlObstacleType type = CrawlObstacleType::Crawl1;
|
CrawlObstacleType type = CrawlObstacleType::Crawl1;
|
||||||
int obstacle_width = OBSTACLE_CRAWL1_COLLISION_WIDTH;
|
|
||||||
|
|
||||||
// The obstacle should start just outside right edge, e.g. +10 px
|
|
||||||
int start_x = VIEW_WIDTH + 10;
|
int start_x = VIEW_WIDTH + 10;
|
||||||
int start_y = 8; // vertical position within visible area
|
|
||||||
|
|
||||||
spawn_obstacle(type, start_x);
|
spawn_obstacle(type, start_x);
|
||||||
// override y manually (spawn sets y=10 high by default)
|
|
||||||
obstacle_pool[0].data.y = start_y;
|
Timer spawn_timer;
|
||||||
obstacle_pool[0].active = true;
|
spawn_timer.start();
|
||||||
}
|
|
||||||
|
|
||||||
while (!game_over) {
|
while (!game_over) {
|
||||||
tick_counter++;
|
tick_counter++;
|
||||||
@@ -65,6 +58,16 @@ void render_loop(int speed) {
|
|||||||
mover.update_position(player_speed, timing.get_ground_speed());
|
mover.update_position(player_speed, timing.get_ground_speed());
|
||||||
pos.x = mover.get_position();
|
pos.x = mover.get_position();
|
||||||
|
|
||||||
|
if (spawn_timer.elapsed_time() > 2s) {
|
||||||
|
spawn_timer.reset();
|
||||||
|
CrawlObstacleType s_type = CrawlObstacleType::Crawl1;
|
||||||
|
int spawn_x = VIEW_WIDTH;
|
||||||
|
int idx = spawn_obstacle(s_type, spawn_x);
|
||||||
|
if (idx >= 0) {
|
||||||
|
obstacle_pool[idx].active = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
need_redraw = false;
|
need_redraw = false;
|
||||||
UartEvent uart_event = uart.poll();
|
UartEvent uart_event = uart.poll();
|
||||||
|
|
||||||
@@ -112,11 +115,8 @@ void render_loop(int speed) {
|
|||||||
draw_character(draw_pos.x, draw_pos.y, 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++) {
|
for (int i = 0; i < MAX_OBSTACLES; i++) {
|
||||||
if (!obstacle_pool[i].active)
|
if (!obstacle_pool[i].active) continue;
|
||||||
continue;
|
draw_obstacle(obstacle_pool[i].data.x, obstacle_pool[i].data.y, obstacle_pool[i].type);
|
||||||
draw_obstacle(obstacle_pool[i].data.x,
|
|
||||||
obstacle_pool[i].data.y,
|
|
||||||
obstacle_pool[i].type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game_over)
|
if (game_over)
|
||||||
|
|||||||
Reference in New Issue
Block a user