#include #include #include #include #include #include #include #include #include "level.h" #include "level_test.h" #include "instructions.h" #include "progress.h" #include "items.h" #include "paths.h" #include "main.h" #include "draw.h" struct level level; uint8_t cells_ground_type[256]; uint8_t cells_ground_links[256]; uint8_t cells_item_type[256]; uint8_t cells_item_color[256]; uint8_t cells_item_state[256]; struct truck level_trucks[LEVEL_CELLS]; uint8_t global_delay; /*void level_info(void) { static const char _ENTER_[] = {/-*[*-/0xC1, 'e','n','t','e','r', ']', '\0'}; draw_exit(); os_ClrHome(); print_text(3, 1, "LEVEL"); print_number(12 + 6, 1, level.level_index); print_text(16+6 -6,7, "press"); print_text(16+6 -7,8, _ENTER_); keys_wait(); draw_init(); }*/ void level_draw(void) { draw_level_ground(); paths_draw(); draw_level_items(); draw_level_trucks(); } void level_info(void) { level_draw(); draw_bubble((320-82)/2, (240-17)/2, 82, 17); draw_level_name(level.level_index, (320-82)/2 + 5, (240-17)/2 + 5); draw_done(); keys_wait(); } static enum level_play_result level_step_keys(bool* redraw_needed) { static uint8_t pressed_alpha = 0; uint8_t pressed_direction; kb_key_t key; kb_Scan(); *redraw_needed = ((pressed_direction = kb_Data[2] & kb_Alpha) ^ pressed_alpha) && (pressed_alpha = pressed_direction) && paths_alpha(); pressed_direction = keys_test_dir(); *redraw_needed |= paths_cursor(pressed_direction, kb_Data[1] & kb_2nd); key = kb_Data[6]; if (key & kb_Clear) return QUIT; return (key & kb_Enter) ? DONE : PLAYING; } void level_trucks_init(void) { struct truck* truck = &level_trucks[0]; { uint8_t position; for (position = 0; ++position; ) { if (cells_item_type[position] == ITEM_TRUCK) { truck->position = position; truck->color = cells_item_color[position]; truck->directions_last_next = (cells_item_state[position] + 1) << 4; memset(&truck->cargos[0], COLOR_NONE, 3); ++truck; } } } } uint8_t level_trucks_dir(void) { uint8_t paths_directions_used = 0; struct truck* truck = &level_trucks[0]; uint8_t index; for (index = 0; index < level.count.trucks; ++index, ++truck) { const uint8_t direction = paths_direction(&paths_connections[truck->position]); truck->directions_last_next = (direction ? direction * 17 : truck->directions_last_next & 0xF0); paths_directions_used |= direction; } return paths_directions_used; } enum level_play_result level_play(void) { enum level_play_result result/* = PLAYING*/; bool redraw_needed; paths_clear(); level_trucks_init(); level_info(); instructions_show(); progress_level_load(); for (;;) { level_trucks_dir(); level_draw(); draw_cursor(); draw_done(); same_frame: if (global_delay < 65) { delay(65 - global_delay); } global_delay = 0; if ((result = level_step_keys(&redraw_needed)) == DONE) { result = level_test_loop(); redraw_needed = true; } if (result != PLAYING) break; if (!redraw_needed) goto same_frame; } progress_level_save(); return result; }