#include #include #include "draw.h" #include "level.h" #include "gfx/gfx.h" #include "gfx/paths.h" static const uint8_t color_bits[] = { /*0b11010000*/0xD0, // RED /*0b11001000*/0xC8, // GREEN /*0b11000100*/0xC4, // BLUE /*0b11011000*/0xD8, // YELLOW /*0b11011100*/0xDC, // WHITE /*0b11010100*/0xD4, // PURPLE }; enum paths_sprites { PATH_SPRITE_U, PATH_SPRITE_L, PATH_SPRITE_R, PATH_SPRITE_D, PATH_SPRITE_UL, PATH_SPRITE_UR, PATH_SPRITE_UD, PATH_SPRITE_LR, PATH_SPRITE_LD, PATH_SPRITE_, PATH_SPRITE_RD, PATH_SPRITE_COUNT }; #define TILE_SPRITE_SIZE (2+(20*20)) static uint8_t paths_sprites[TILE_SPRITE_SIZE * PATH_SPRITE_COUNT]; #define PATH_SPRITE(i) (&paths_sprites[(i)*TILE_SPRITE_SIZE]) void draw_paths_init(void) { static const uint8_t base[PATH_SPRITE_COUNT] = {1,1,1,1,2,2,3,3,2,0,2}; static const uint8_t rots[PATH_SPRITE_COUNT] = {0,3,1,2,0,1,1,0,3,0,2}; draw_tiles_init(PATH_SPRITE_COUNT, paths_tiles_data, paths_sprites, base, rots); } void draw_paths_color(uint8_t color) { #define MASK_BITS (/*0b11100000*/0xE0) uint8_t base_bits = color_bits[color-1]; uint8_t i; for (i = 0; i < PATH_SPRITE_COUNT; ++i) { uint8_t* p = PATH_SPRITE(i) + 1; uint24_t l; for (l = 20*20; l --> 0; ) if (*++p) { *p = (*p & MASK_BITS) | base_bits; } } #undef MASK_BITS } void draw_paths_cell(uint8_t x, uint8_t y, uint8_t src, uint8_t dst) { uint8_t paths_sprites_index = PATH_SPRITE_; if (src != dst) { if (src > dst) { uint8_t tmp; tmp = src; src = dst; dst = tmp; } /*if (!src) { paths_sprites_index = (dst - DIR_U)+PATH_SPRITE_U; } else { paths_sprites_index = (src*2 + dst-4)+PATH_SPRITE_UL; }*/ paths_sprites_index = (src*2 + dst-4)+PATH_SPRITE_UL-(!src); } draw_sprite_or(x, y, (unsigned char*) PATH_SPRITE(paths_sprites_index)); }