#include #include #include "draw.h" #include "main.h" #include "items.h" #include "gfx/gfx.h" #include "gfx/tiles.h" #define SPRITES_COUNT ITEM_COUNT uint8_t draw_tileset; uint8_t draw_palette = 0; void draw_init_palette(void) { gfx_SetPalette(draw_palette ? grayscale_palette : global_palette, sizeof_global_palette, 0); } void draw_init(void) { gfx_Begin(); draw_init_palette(); // gfx_FillScreen(0); // not actually required gfx_SetDrawBuffer(); } void draw_toggle_palette(void) { draw_palette = !draw_palette; draw_init_palette(); } void draw_exit(void) { gfx_End(); } void draw_sprite(uint8_t item, uint8_t spriteX, uint8_t spriteY) { // if (item > ITEM_COUNT) return; // not actually required gfx_Sprite_NoClip( (gfx_sprite_t*) tiles_tiles_data[(draw_tileset*SPRITES_COUNT)+item], spriteX*SPRITES_SIZE, spriteY*SPRITES_SIZE ); } void draw_view(uint8_t* level_data, uint8_t level_width, uint8_t level_height, uint8_t viewX, uint8_t viewY) { uint16_t spriteX, spriteY; for (spriteX = 0; spriteX < SCREEN_SPRITES_X; spriteX++) { uint8_t cellX = viewX + spriteX; for (spriteY = 0; spriteY < SCREEN_SPRITES_Y; spriteY++) { uint8_t cellY = viewY + spriteY; uint8_t item = ITEM_DIRT; if (cellX < level_width && cellY < level_height) { item = level_data[cellY * level_width + cellX] & ITEM_MASK; } draw_sprite(item, spriteX, spriteY); } } gfx_SwapDraw(); }