diff --git a/src/columns.c b/src/columns.c index 171aaf7..426509a 100644 --- a/src/columns.c +++ b/src/columns.c @@ -10,79 +10,8 @@ #include #include #include -#include "sprite_sheet.h" -#include "text.h" -#include "ascii.h" + #include "game.h" - -enum gradient {Blue = 0, Green = 10, Red = 20, Yellow = 30, Magenta = 40, Cyan = 50, Grey = 60} colour = 0; - -int backdrop (enum gradient colour); -int check_key(void); -int Ren_restart(void); // game over/restart -int Ren_pause(void); // pause -int Ren_game(void); // render game -int Ren_logo (void); // display logo -int Ren_about (void); // display about -int Ren_info (void); // info screen -int Ren_menu (void); // main menu -int Ren_level (void); // display level / current score -int Ren_next (void); // display next block/brick/piece -int Ren_high (void); // display high scores -int Ren_line (char line[], int char_x, int char_y, int ln, int ll, bool col ); // parameter names in function prototypes not necessary -int initSDL (void); // initialise SDL -int shutdownSDL (void); // shutdown SDL -int render (void); // render output -int init_gfx (void); // create texture -int i, j, k, x, y, z, l; // index variables -int gamep = 0; -int tile_c; -int tile_pos = 112; - -bool next_p = false; // next piece flag -bool quit = false; // quit flag -bool main_m = false; -bool pause_f = 0; - -SDL_Window *window = NULL; -SDL_Renderer *sr; -SDL_Event event; -SDL_RWops* rwops_new; -SDL_Surface* image; -SDL_Texture * texture; -SDL_Rect logo_src = { 384, 0, 78, 54 }; -SDL_Rect logo_dst = { 230, 136, 78, 54 }; -//SDL_Rect char_src = {463, 0 , 7 , 5}; -//SDL_Rect char_dst = {22, 11 , 7 , 5}; -SDL_Rect main_back = {110, 0, 100, 200}; -SDL_Rect main_trim = {111, 0, 98, 200}; -SDL_Rect level_back = {231, 7, 76, 66}; -SDL_Rect level_trim = {230, 6, 78, 68}; -SDL_Rect next_back = {257, 86, 18, 37}; -SDL_Rect next_trim = {256, 85, 20, 39}; -SDL_Rect high_back = {13, 7, 76, 186}; -SDL_Rect high_trim = {12, 6, 78, 188}; -SDL_Rect tile_src = {132, 0, 12, 11}; -SDL_Rect tile_dst = {112, 1, 12, 11}; -SDL_Rect gameo_back = {119, 93, 82, 13}; - -/* window paramaters */ -#define WIDTH 1280 // pixels -#define HEIGHT 800 // pixels -#define TITLE "FUN COLUMNS" // window title - -/** board background colours **/ -int grad_tab[] = { - - 0x0000cc, 0x0000bb, 0x0000aa, 0x000099, 0x000088, 0x000077, 0x000066, 0x000055, 0x000044, 0x000033, // blue - 0x00cc00, 0x00bb00, 0x00aa00, 0x009900, 0x008800, 0x007700, 0x006600, 0x005500, 0x004400, 0x003300, // green - 0xcc0000, 0xbb0000, 0xaa0000, 0x990000, 0x880000, 0x770000, 0x660000, 0x550000, 0x440000, 0x330000, // red - 0xcccc00, 0xbbbb00, 0xaaaa00, 0x999900, 0x888800, 0x777700, 0x666600, 0x555500, 0x444400, 0x333300, // yellow - 0xcc00cc, 0xbb00bb, 0xaa00aa, 0x990099, 0x880088, 0x770077, 0x660066, 0x550055, 0x440044, 0x330033, // magenta - 0x00cccc, 0x00bbbb, 0x00aaaa, 0x009999, 0x008888, 0x007777, 0x006666, 0x005555, 0x004444, 0x003333, // cyan - 0xcccccc, 0xbbbbbb, 0xaaaaaa, 0x999999, 0x888888, 0x777777, 0x666666, 0x555555, 0x444444, 0x333333 // grey -}; - // ============= Main ============= int main (void) { @@ -355,22 +284,56 @@ int Ren_logo(void) { return 0; } + +// ============= display play field ============= + +int display_grid() +{ + tiledst_y = 1; + for (i = 0; i < 18; i++) { + tiledst_x = 112; + for (j = 0; j < 8; j++) { + k = grid[0][i][j]; + tile_shp = 1; // tile shape + tilesrc_y = 0; + if (k > 0) { + k--; + tilesrc_x = spr_x[tile_shp][k]; + tile_src.x = tilesrc_x; + tile_src.y = tilesrc_y; + tile_dst.x = tiledst_x; + tile_dst.y = tiledst_y; + SDL_RenderCopy(sr, texture, &tile_src, &tile_dst); // draw colour tile + } else { + tile_dst.x = tiledst_x; + tile_dst.y = tiledst_y; + SDL_SetRenderDrawColor(sr, 0x0 , 0x0 , 0x0, 0xff); + SDL_RenderFillRect(sr, &tile_dst); // draw empty tile + } + tiledst_x = tiledst_x + 12; // next column + } + tiledst_y = tiledst_y + 11; // next row + } + return 0; +} + // ============= Game ============= int Ren_game(void) { SDL_SetRenderDrawColor(sr, 0x0 , 0x0 , 0x0, 0xff); SDL_RenderFillRect(sr, &main_back); // background SDL_SetRenderDrawColor (sr, 0xff, 0xff, 0xff, 255); SDL_RenderDrawRect(sr, &main_trim); // trim - if(tile_c > 17) { - tile_c = 0; - } +// if(tile_c > 17) { +// tile_c = 0; +// } - for (i = 0; i < 1; i++) { - tile_dst.x = tile_pos; - tile_dst.y = 11 * tile_c + 1; - SDL_RenderCopy(sr, texture, &tile_src, &tile_dst); - tile_c++; - } +// for (i = 0; i < 1; i++) { +// tile_dst.x = tile_pos; +// tile_dst.y = 11 * tile_c + 1; +// SDL_RenderCopy(sr, texture, &tile_src, &tile_dst); +// tile_c++; +// } +display_grid(); return 0; } @@ -395,7 +358,6 @@ int Ren_info(void) { for (z = 0; z < 11; z++) { // 11 lines of text Ren_line(info, infol[z][0], infol[z][1], z * 11, 11, 0); } - return 0; }