From e6e99fe3162784f53eba49f2c8e9c4d8fea7adfc Mon Sep 17 00:00:00 2001 From: maxcodehack Date: Sat, 12 Dec 2020 16:49:35 +0000 Subject: [PATCH] Fridge: code refactoring git-svn-id: svn://kolibrios.org@8378 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/games/fridge/Tupfile.lua | 3 + programs/games/fridge/fridge.c | 109 +++++++++++++++--------------- 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/programs/games/fridge/Tupfile.lua b/programs/games/fridge/Tupfile.lua index 2d156f93a7..3b70753f08 100755 --- a/programs/games/fridge/Tupfile.lua +++ b/programs/games/fridge/Tupfile.lua @@ -9,5 +9,8 @@ INCLUDES = INCLUDES .. " -I../../../contrib/C_Layer/INCLUDE" table.insert(LIBDEPS, "../../../contrib/C_Layer/OBJ/") LIBS = LIBS .. " ../../../contrib/C_Layer/OBJ/loadlibimg.o" +-- Subsystem native +LDFLAGS = LDFLAGS .. " --subsystem native" + compile_gcc{"fridge.c"} link_gcc("fridge") diff --git a/programs/games/fridge/fridge.c b/programs/games/fridge/fridge.c index 38ac4970a1..9d874f37b2 100644 --- a/programs/games/fridge/fridge.c +++ b/programs/games/fridge/fridge.c @@ -1,13 +1,15 @@ +// Includes // #include #include #include #include #include + #include -/* -#include "mp3.h" -*/ -//EVENTS LOOK LIKE IN C-- +// #include "mp3.h" + + +// C-- event defines // #define evReDraw 1 #define evKey 2 #define evButton 3 @@ -19,31 +21,30 @@ #define evDebug 9 -#define RESTART 99 +// Code // +#define button_color 0xbbbbbb +#define button_size 44 -#define b_color 0xbbbbbb -#define _size 4 -#define bs 44 +#define field_size 4 -int field[_size][_size] = { +int field[field_size][field_size] = { {0, 0, 0, 1}, {0, 0, 1, 0}, {0, 0, 0, 1}, {1, 0, 0, 0} }; -short vict = 0; -short debug_pr = 0; char* title = "Fridge"; +#define BUTTON_RESTART 99 +short victory = 0; -// PICTURES LOADING CODE +// Load pictures // char temp_path[4096]; -char* HOR; -char* VER; +char* HORIZONTAL_IMAGE; +char* VERTICAL_IMAGE; - -char* load_file_inmem(char* fname, int32_t* read_sz) +char* load_file_inmem(char* fname, int32_t* read_sz) { FILE *f = fopen(fname, "rb"); if (!f) { @@ -52,13 +53,13 @@ char* load_file_inmem(char* fname, int32_t* read_sz) if (fseek(f, 0, SEEK_END)) { exit(1); } - int filesize = ftell(f); + int filefield_size = ftell(f); rewind(f); - char* fdata = malloc(filesize); + char* fdata = malloc(filefield_size); if(!fdata) { exit(1); } - *read_sz = fread(fdata, 1, filesize, f); + *read_sz = fread(fdata, 1, filefield_size, f); if (ferror(f)) { exit(1); } @@ -67,9 +68,8 @@ char* load_file_inmem(char* fname, int32_t* read_sz) return fdata; } - -void load_pict() { - const int icon_rgb_size = bs*bs; +void load_pictures() { + const int icon_rgb_field_size = button_size*button_size; char *image_data, *filedata; @@ -77,49 +77,50 @@ void load_pict() { int32_t read_bytes; filedata = load_file_inmem(temp_path, &read_bytes); - HOR = malloc(icon_rgb_size * 3); + HORIZONTAL_IMAGE = malloc(icon_rgb_field_size * 3); image_data = img_decode(filedata, read_bytes, 0); - img_to_rgb2(image_data, HOR); + img_to_rgb2(image_data, HORIZONTAL_IMAGE); strcpy(temp_path, "v.png"); filedata = load_file_inmem(temp_path, &read_bytes); - VER = malloc(icon_rgb_size * 3); + VERTICAL_IMAGE = malloc(icon_rgb_field_size * 3); image_data = img_decode(filedata, read_bytes, 0); - img_to_rgb2(image_data, VER); + img_to_rgb2(image_data, VERTICAL_IMAGE); img_destroy(image_data); free(filedata); } -// END OF PICTURES LOAD CODE - +// GUI functions // void redraw_buttons() { - for (int j = 5, yy = 0; yy<_size; j+=bs, yy++) - for (int i = 15, xx = 0; xx<_size; i+=bs, xx++) + for (int j = 5, x = 0; x