diff --git a/build.py b/build.py index 21802c3..02a876f 100644 --- a/build.py +++ b/build.py @@ -6,7 +6,7 @@ from pathlib import Path GCC = "gcc" -ARGS = "-fdiagnostics-color -pthread -Wall -std=c17 -pedantic -g" +ARGS = "-fdiagnostics-color -pthread -Wall -std=c17 -pedantic -Os" SOURCE_DIR = Path("source/") diff --git a/build/errors.txt b/build/errors.txt index f9b644f..b369704 100644 --- a/build/errors.txt +++ b/build/errors.txt @@ -1 +1 @@ -{"ringbuffer": "", "event": "", "ctrl": "", "terminal": "", "fumoengine": "", "parseinput": "", "dictionary": "", "fumocommon": "", "win": "", "input": "", "fumotris": "\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:\u001b[m\u001b[K In function '\u001b[01m\u001b[Kmain\u001b[m\u001b[K':\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:138:37:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KEventAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;31m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 138 | EventAdd(&inst.on_start, &game, \u001b[01;31m\u001b[KFumotrisStart\u001b[m\u001b[K);\n | \u001b[01;31m\u001b[K^~~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;31m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;31m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K\nIn file included from \u001b[01m\u001b[Ksource\\fumoengine/fumoengine.h:3\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.h:2\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include/event.h:24:60:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Khandler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Kvoid (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'\n 24 | bool EventAdd(struct Event *event, void *instance, \u001b[01;36m\u001b[Khandler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:139:38:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KEventAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;31m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 139 | EventAdd(&inst.on_update, &game, \u001b[01;31m\u001b[KFumotrisUpdate\u001b[m\u001b[K);\n | \u001b[01;31m\u001b[K^~~~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;31m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;31m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumoengine\\include/event.h:24:60:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Khandler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Kvoid (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'\n 24 | bool EventAdd(struct Event *event, void *instance, \u001b[01;36m\u001b[Khandler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:140:36:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KEventAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;31m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 140 | EventAdd(&inst.on_draw, &game, \u001b[01;31m\u001b[KFumotrisDraw\u001b[m\u001b[K);\n | \u001b[01;31m\u001b[K^~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;31m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;31m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumoengine\\include/event.h:24:60:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Khandler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Kvoid (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'\n 24 | bool EventAdd(struct Event *event, void *instance, \u001b[01;36m\u001b[Khandler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:142:32:\u001b[m\u001b[K \u001b[01;31m\u001b[Kerror: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KCoroutineAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;31m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 142 | CoroutineAdd(&inst, &game, \u001b[01;31m\u001b[KFumotrisFall\u001b[m\u001b[K);\n | \u001b[01;31m\u001b[K^~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;31m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;31m\u001b[Knsec (*)(struct Instance *, struct Fumotris *) {aka long long unsigned int (*)(struct Instance *, struct Fumotris *)}\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumoengine/fumoengine.h:35:73:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Kcoroutine_handler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Klong long unsigned int (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Knsec (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Klong long unsigned int (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'}\n 35 | bool CoroutineAdd(struct Instance *inst, void *state, \u001b[01;36m\u001b[Kcoroutine_handler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~~~~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n", "vector": "", "tetra": ""} \ No newline at end of file +{"dictionary": "", "event": "", "fumoengine": "", "parseinput": "", "ctrl": "", "terminal": "", "vector": "", "ringbuffer": "", "input": "", "win": "", "fumotris": "\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:\u001b[m\u001b[K In function '\u001b[01m\u001b[Kmain\u001b[m\u001b[K':\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:168:37:\u001b[m\u001b[K \u001b[01;35m\u001b[Kwarning: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KEventAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;35m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 168 | EventAdd(&inst.on_start, &game, \u001b[01;35m\u001b[KFumotrisStart\u001b[m\u001b[K);\n | \u001b[01;35m\u001b[K^~~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;35m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;35m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K\nIn file included from \u001b[01m\u001b[Ksource\\fumoengine/fumoengine.h:3\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.h:2\u001b[m\u001b[K,\n from \u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:1\u001b[m\u001b[K:\n\u001b[01m\u001b[Ksource\\fumoengine\\include/event.h:24:60:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Khandler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Kvoid (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'\n 24 | bool EventAdd(struct Event *event, void *instance, \u001b[01;36m\u001b[Khandler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:169:38:\u001b[m\u001b[K \u001b[01;35m\u001b[Kwarning: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KEventAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;35m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 169 | EventAdd(&inst.on_update, &game, \u001b[01;35m\u001b[KFumotrisUpdate\u001b[m\u001b[K);\n | \u001b[01;35m\u001b[K^~~~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;35m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;35m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumoengine\\include/event.h:24:60:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Khandler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Kvoid (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'\n 24 | bool EventAdd(struct Event *event, void *instance, \u001b[01;36m\u001b[Khandler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:170:36:\u001b[m\u001b[K \u001b[01;35m\u001b[Kwarning: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KEventAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;35m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 170 | EventAdd(&inst.on_draw, &game, \u001b[01;35m\u001b[KFumotrisDraw\u001b[m\u001b[K);\n | \u001b[01;35m\u001b[K^~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;35m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;35m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumoengine\\include/event.h:24:60:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Khandler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Kvoid (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Kvoid (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'\n 24 | bool EventAdd(struct Event *event, void *instance, \u001b[01;36m\u001b[Khandler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumotris\\fumotris.c:172:32:\u001b[m\u001b[K \u001b[01;35m\u001b[Kwarning: \u001b[m\u001b[Kpassing argument 3 of '\u001b[01m\u001b[KCoroutineAdd\u001b[m\u001b[K' from incompatible pointer type [\u001b[01;35m\u001b[K-Wincompatible-pointer-types\u001b[m\u001b[K]\n 172 | CoroutineAdd(&inst, &game, \u001b[01;35m\u001b[KFumotrisFall\u001b[m\u001b[K);\n | \u001b[01;35m\u001b[K^~~~~~~~~~~~\u001b[m\u001b[K\n | \u001b[01;35m\u001b[K|\u001b[m\u001b[K\n | \u001b[01;35m\u001b[Knsec (*)(struct Instance *, struct Fumotris *) {aka long long unsigned int (*)(struct Instance *, struct Fumotris *)}\u001b[m\u001b[K\n\u001b[01m\u001b[Ksource\\fumoengine/fumoengine.h:35:73:\u001b[m\u001b[K \u001b[01;36m\u001b[Knote: \u001b[m\u001b[Kexpected '\u001b[01m\u001b[Kcoroutine_handler\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Klong long unsigned int (*)(void *, void *)\u001b[m\u001b[K'} but argument is of type '\u001b[01m\u001b[Knsec (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K' {aka '\u001b[01m\u001b[Klong long unsigned int (*)(struct Instance *, struct Fumotris *)\u001b[m\u001b[K'}\n 35 | bool CoroutineAdd(struct Instance *inst, void *state, \u001b[01;36m\u001b[Kcoroutine_handler callback\u001b[m\u001b[K);\n | \u001b[01;36m\u001b[K~~~~~~~~~~~~~~~~~~^~~~~~~~\u001b[m\u001b[K\n", "fumocommon": "", "tetra": ""} \ No newline at end of file diff --git a/build/hdr_checksums.txt b/build/hdr_checksums.txt index 065dca5..3c2707f 100644 --- a/build/hdr_checksums.txt +++ b/build/hdr_checksums.txt @@ -1 +1 @@ -["7d30e573f96a566ed9510833b95d5520", "5ce28b2bf9d7c5750ea290f80fbd1264", "f315479de287d3cccdfa665c1e8c58bd", "0d65896ce70d098bdf4cb3587ca74508", "72e1b62b85eac654ed094a8ecf009416", "cd22e396133a64303ecae95280f8ba1a", "7d7451ae7d88f4d1f84055180f9e84a7"] \ No newline at end of file +["7d7451ae7d88f4d1f84055180f9e84a7", "7d30e573f96a566ed9510833b95d5520", "f6611a0f07f78cc4fd52df267e0d3d25", "f315479de287d3cccdfa665c1e8c58bd", "0eaec40fe47b9cb31ff5a70f7bfee15a", "ec4912a725a2bc606bd76ba34159435c", "184f2c12e4c8c2365b4e6ca95df9be16", "08bf0c5c8dd2f8b3842cfc802719a95c", "29f6d19bcc5a1897b220a192ef6fc3cc", "1d88301163b019760c3dc8396ce2aa4b", "0d65896ce70d098bdf4cb3587ca74508", "cd22e396133a64303ecae95280f8ba1a", "9f0597e7cacc7c918163affc5f3d9841", "72e1b62b85eac654ed094a8ecf009416"] \ No newline at end of file diff --git a/build/src_checksums.txt b/build/src_checksums.txt index 73078c4..d879592 100644 --- a/build/src_checksums.txt +++ b/build/src_checksums.txt @@ -1 +1 @@ -["dd2f269c19f28201dce9133ab27198af"] \ No newline at end of file +["b0b3fe164a3dd9c9fac4a4df58f4eaa1"] \ No newline at end of file diff --git a/debug.exe b/debug.exe index ac7f303..617e471 100644 Binary files a/debug.exe and b/debug.exe differ diff --git a/objects/ctrl.o b/objects/ctrl.o index 9eff00a..33a4ea8 100644 Binary files a/objects/ctrl.o and b/objects/ctrl.o differ diff --git a/objects/dictionary.o b/objects/dictionary.o index d5ce134..50114a5 100644 Binary files a/objects/dictionary.o and b/objects/dictionary.o differ diff --git a/objects/event.o b/objects/event.o index 9581e8a..fdfd3ac 100644 Binary files a/objects/event.o and b/objects/event.o differ diff --git a/objects/fumocommon.o b/objects/fumocommon.o index 5452fad..0103e8f 100644 Binary files a/objects/fumocommon.o and b/objects/fumocommon.o differ diff --git a/objects/fumoengine.o b/objects/fumoengine.o index abcbea5..4fcb254 100644 Binary files a/objects/fumoengine.o and b/objects/fumoengine.o differ diff --git a/objects/fumotris.o b/objects/fumotris.o index 467e9b5..c16081c 100644 Binary files a/objects/fumotris.o and b/objects/fumotris.o differ diff --git a/objects/input.o b/objects/input.o index b9a14eb..d8289e3 100644 Binary files a/objects/input.o and b/objects/input.o differ diff --git a/objects/parseinput.o b/objects/parseinput.o index 3353ca8..03ac94d 100644 Binary files a/objects/parseinput.o and b/objects/parseinput.o differ diff --git a/objects/ringbuffer.o b/objects/ringbuffer.o index 017d124..7fce2a1 100644 Binary files a/objects/ringbuffer.o and b/objects/ringbuffer.o differ diff --git a/objects/terminal.o b/objects/terminal.o index 6832335..df060df 100644 Binary files a/objects/terminal.o and b/objects/terminal.o differ diff --git a/objects/tetra.o b/objects/tetra.o index 6b35add..7867b25 100644 Binary files a/objects/tetra.o and b/objects/tetra.o differ diff --git a/objects/vector.o b/objects/vector.o index cac1378..f2db604 100644 Binary files a/objects/vector.o and b/objects/vector.o differ diff --git a/objects/win.o b/objects/win.o index 4a2c2ab..cdfa94e 100644 Binary files a/objects/win.o and b/objects/win.o differ diff --git a/rewritesrc/silly.zig b/rewritesrc/silly.zig new file mode 100644 index 0000000..e69de29 diff --git a/source/fumo.txt b/source/fumo.txt deleted file mode 100644 index 224eec7..0000000 --- a/source/fumo.txt +++ /dev/null @@ -1,14 +0,0 @@ - _,_ _,_ - }\>' ``'-./\.-''` ' ,-''``''-. ,' `. str, "\x1b[H\x1b[0m", 7); - usize i = 0; + struct Char4 *ch4 = term->buf; for (usize y = 0; y < term->hgt; y++) { - for (usize x = 0; x < term->wid; x++, i++) { - struct Char4 *ch4 = &term->buf[i]; - + for (usize x = 0; x < term->wid; x++, ch4++) { // DEBUG if (ch4->ch == 0) ch4->ch = '#'; @@ -135,4 +133,9 @@ usize TerminalPrint(struct Terminal *term) term->str[len] = 0; return len; +} + +struct Char4 *TerminalGet(struct Terminal *term, usize x, usize y) +{ + return term->buf + term->wid * y + x; } \ No newline at end of file diff --git a/source/fumoengine/terminal/terminal.h b/source/fumoengine/terminal/terminal.h index c965bf5..9dde487 100644 --- a/source/fumoengine/terminal/terminal.h +++ b/source/fumoengine/terminal/terminal.h @@ -29,4 +29,6 @@ bool CreateTerminal(struct Terminal *term, usize wid, usize hgt); void FreeTerminal(struct Terminal *term); -usize TerminalPrint(struct Terminal *term); \ No newline at end of file +usize TerminalPrint(struct Terminal *term); + +struct Char4 *TerminalGet(struct Terminal *term, usize x, usize y); \ No newline at end of file diff --git a/source/fumotris/fumotris.c b/source/fumotris/fumotris.c index 82b601d..4f1e334 100644 --- a/source/fumotris/fumotris.c +++ b/source/fumotris/fumotris.c @@ -1,5 +1,6 @@ #include "fumotris.h" #include +#include struct Fumotris { @@ -28,23 +29,30 @@ void shuffle(struct Fumotris *fumo) } } -void check_clear() +bool check_clear(struct Tetra *board, usize y) { - + for (usize x = 0; x < board->wid; x++) { + if (board->blks[board->wid * y + x] == 0) + return false; + } + + return true; +} + +void shift_down(struct Tetra *board, usize y) +{ + memmove(board->blks + board->wid, board->blks, board->wid * y); } void place(struct Fumotris *fumo) { TetraOverlay(&fumo->piece, &fumo->board); - usize lines_cleared = fumo->piece.hgt; - + usize lines_cleared = 0; for (usize y = fumo->piece.y; y < fumo->piece.y + fumo->piece.hgt; y++) { - for (usize x = 0; x < fumo->board.wid; x++) { - if (fumo->board.blks[fumo->board.wid * y + x] == 0) { - lines_cleared -= 1; - break; - } + if (check_clear(&fumo->board, y)) { + lines_cleared += 1; + shift_down(&fumo->board, y); } } @@ -66,7 +74,25 @@ void FumotrisStart(struct Instance *inst, struct Fumotris *fumo) { ControllerBindMulti(&inst->ctrl, BINDS_N, CONTROLS, CODES, TYPES); - CreateTerminal(&fumo->term, 20, 20); + CreateTerminal(&fumo->term, 64, 26); + FILE *file; + file = fopen("fumo.txt", "r"); + if (file) { + signed char ch; + usize x = 0; + usize y = 0; + + while ((ch = getc(file)) != EOF) { + if (ch == '\n') { + x = 0; + y += 1; + continue; + } + + fumo->term.buf[fumo->term.wid * y + x++] = (struct Char4) { .ch = ch, .color.fg = 15 }; + } + fclose(file); + } for (usize i = 0; i < 7; i++) fumo->bag[i] = templates[i]; @@ -120,9 +146,11 @@ nsec FumotrisFall(struct Instance *inst, struct Fumotris *fumo) void FumotrisDraw(struct Instance *inst, struct Fumotris *fumo) { - TetraTerminalClear(&fumo->board, &fumo->term); - TetraTerminalDraw(&fumo->board, &fumo->term); - TetraTerminalDraw(&fumo->piece, &fumo->term); + TetraTerminalClear(&fumo->board, &fumo->term, 3, 5); + TetraTerminalDraw(&fumo->board, &fumo->term, 3, 5); + + TetraTerminalDrawGhost(&fumo->piece, &fumo->board, &fumo->term, 3, 5); + TetraTerminalDraw(&fumo->piece, &fumo->term, 3, 5); TerminalPrint(&fumo->term); puts(fumo->term.str); @@ -130,6 +158,8 @@ void FumotrisDraw(struct Instance *inst, struct Fumotris *fumo) int main() { + system("color"); + struct Instance inst; CreateFumoInstance(&inst); @@ -144,27 +174,4 @@ int main() FumoInstanceRun(&inst); return 0; -} - -| | NEXT LINES -| [][][]. . . . . . . | -| [][][]. . . . . . . | SCORE -| [][][][]. . . . . . | -| [][][]. . . . . . [] | -| []. . [][]. . . . [] | -| [][][][][][]. . . [] | -| . . [][]. . . . . [] | -| [][][][]. [][]. [][] | -| [][][][][][][]. [][] | -| [][][][][][][][][][] | -| [][][][][][][][][][] | -| [][][][][][][][][][] | -| [][][][][][][][][][] | -| [][][][][][][]. [][] | -| . [][][][][][]. . [] | -| [][][]. [][][][]. [] | -| [][][][][][][][]. [] | -| [][][][][][][][]. [] | -| . [][][][][][][][][] | -| . [][][][][][][][][] | -|________________________| \ No newline at end of file +} \ No newline at end of file diff --git a/source/fumotris/tetra.c b/source/fumotris/tetra.c index 2551362..d13855f 100644 --- a/source/fumotris/tetra.c +++ b/source/fumotris/tetra.c @@ -59,14 +59,14 @@ usize rotate_index(usize i, usize wid, u8 rot) return 0; } -bool TetraIsCollision(struct Tetra *t, struct Tetra *board) +bool TetraIsCollision(struct Tetra *piece, struct Tetra *board) { usize i = 0; - for (i16 y = t->y; y < t->y + t->hgt; y++) { - for (i16 x = t->x; x < t->x + t->wid; x++, i++) { - usize rot_i = rotate_index(i, t->wid, t->rot); + for (i16 y = piece->y; y < piece->y + piece->hgt; y++) { + for (i16 x = piece->x; x < piece->x + piece->wid; x++, i++) { + usize rot_i = rotate_index(i, piece->wid, piece->rot); - if(t->blks[rot_i] == 0) + if(piece->blks[rot_i] == 0) continue; if(x < 0 or x >= board->wid or y < 0 or y >= board->hgt) @@ -127,34 +127,57 @@ void TetraOverlay(struct Tetra *t, struct Tetra *board) } } -void TetraTerminalClear(struct Tetra *board, struct Terminal *term) +void TetraTerminalClear(struct Tetra *board, struct Terminal *term, u16 OFS_X, u16 OFS_Y) { - for (usize i = 0; i < board->wid * board->hgt; i++) { - struct Char4 *block = term->buf + i * 2; + for (i16 y = board->y; y < board->y + board->hgt; y++) { + for (i16 x = board->x; x < board->x + board->wid; x++) { + struct Char4 *ch4 = TerminalGet(term, (x * 2) + OFS_X, y + OFS_Y); - block[0] = (struct Char4) { .ch = '.', .color.fg = 8 }; - block[1] = (struct Char4) { .ch = ' ', .color.fg = 8 }; + ch4[0] = (struct Char4) { .ch = '.', .color.fg = 8 }; + ch4[1] = (struct Char4) { .ch = ' ', .color.fg = 8 }; + } } } -void TetraTerminalDraw(struct Tetra *t, struct Terminal *term) +void TetraTerminalDraw(struct Tetra *piece, struct Terminal *term, u16 OFS_X, u16 OFS_Y) { static const u8f blk_colors[8] = { 8, 14, 11, 13, 10, 9, 12, 3 }; usize i = 0; - for (usize y = 0; y < t->hgt; y++) { - for (usize x = 0; x < t->wid; x++, i++) { - usize rot_i = rotate_index(i, t->wid, t->rot); + for (i16 y = piece->y; y < piece->y + piece->hgt; y++) { + for (i16 x = piece->x; x < piece->x + piece->wid; x++, i++) { + usize rot_i = rotate_index(i, piece->wid, piece->rot); - if (t->blks[rot_i] == 0) + if (piece->blks[rot_i] == 0) continue; - usize term_i = (y + t->y) * term->wid + (x + t->x) * 2; - struct Char4 *block = term->buf + term_i; + struct Char4 *ch4 = TerminalGet(term, (x * 2) + OFS_X, y + OFS_Y); - u8 fg = blk_colors[t->blks[rot_i]]; - block[0] = (struct Char4) { .ch = '[', .color.fg = fg }; - block[1] = (struct Char4) { .ch = ']', .color.fg = fg }; + u8 fg = blk_colors[piece->blks[rot_i]]; + + ch4[0] = (struct Char4) { .ch = '[', .color.fg = fg }; + ch4[1] = (struct Char4) { .ch = ']', .color.fg = fg }; + } + } +} + +void TetraTerminalDrawGhost(struct Tetra *t, struct Tetra *board, struct Terminal *term, u16 OFS_X, u16 OFS_Y) +{ + struct Tetra ghost = *t; + while(TetraMove(&ghost, board, 0, 1)); + + usize i = 0; + for (i16 y = ghost.y; y < ghost.y + ghost.hgt; y++) { + for (i16 x = ghost.x; x < ghost.x + ghost.wid; x++, i++) { + usize rot_i = rotate_index(i, ghost.wid, ghost.rot); + + if (ghost.blks[rot_i] == 0) + continue; + + struct Char4 *ch4 = TerminalGet(term, (x * 2) + OFS_X, y + OFS_Y); + + ch4[0] = (struct Char4) { .ch = '[', .color.fg = 8 }; + ch4[1] = (struct Char4) { .ch = ']', .color.fg = 8 }; } } } \ No newline at end of file diff --git a/source/fumotris/tetra.h b/source/fumotris/tetra.h index 1f6541c..5133fb8 100644 --- a/source/fumotris/tetra.h +++ b/source/fumotris/tetra.h @@ -36,6 +36,8 @@ bool TetraRotate(struct Tetra *t, struct Tetra *board, i8 dr); void TetraOverlay(struct Tetra *t, struct Tetra *board); -void TetraTerminalClear(struct Tetra *board, struct Terminal *term); +void TetraTerminalClear(struct Tetra *board, struct Terminal *term, u16 OFS_X, u16 OFS_Y); -void TetraTerminalDraw(struct Tetra *t, struct Terminal *term); \ No newline at end of file +void TetraTerminalDraw(struct Tetra *piece, struct Terminal *term, u16 OFS_X, u16 OFS_Y); + +void TetraTerminalDrawGhost(struct Tetra *t, struct Tetra *board, struct Terminal *term, u16 OFS_X, u16 OFS_Y);