DONE
DONE
This commit is contained in:
parent
1a84049b1e
commit
73597a9ac0
2
build.py
2
build.py
|
@ -6,7 +6,7 @@ from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
GCC = "gcc"
|
GCC = "gcc"
|
||||||
ARGS = "-fdiagnostics-color -pthread -Wall -std=c17 -pedantic -g"
|
ARGS = "-fdiagnostics-color -pthread -Wall -std=c17 -pedantic -Os"
|
||||||
|
|
||||||
|
|
||||||
SOURCE_DIR = Path("source/")
|
SOURCE_DIR = Path("source/")
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -1 +1 @@
|
||||||
["7d30e573f96a566ed9510833b95d5520", "5ce28b2bf9d7c5750ea290f80fbd1264", "f315479de287d3cccdfa665c1e8c58bd", "0d65896ce70d098bdf4cb3587ca74508", "72e1b62b85eac654ed094a8ecf009416", "cd22e396133a64303ecae95280f8ba1a", "7d7451ae7d88f4d1f84055180f9e84a7"]
|
["7d7451ae7d88f4d1f84055180f9e84a7", "7d30e573f96a566ed9510833b95d5520", "f6611a0f07f78cc4fd52df267e0d3d25", "f315479de287d3cccdfa665c1e8c58bd", "0eaec40fe47b9cb31ff5a70f7bfee15a", "ec4912a725a2bc606bd76ba34159435c", "184f2c12e4c8c2365b4e6ca95df9be16", "08bf0c5c8dd2f8b3842cfc802719a95c", "29f6d19bcc5a1897b220a192ef6fc3cc", "1d88301163b019760c3dc8396ce2aa4b", "0d65896ce70d098bdf4cb3587ca74508", "cd22e396133a64303ecae95280f8ba1a", "9f0597e7cacc7c918163affc5f3d9841", "72e1b62b85eac654ed094a8ecf009416"]
|
|
@ -1 +1 @@
|
||||||
["dd2f269c19f28201dce9133ab27198af"]
|
["b0b3fe164a3dd9c9fac4a4df58f4eaa1"]
|
BIN
objects/ctrl.o
BIN
objects/ctrl.o
Binary file not shown.
Binary file not shown.
BIN
objects/event.o
BIN
objects/event.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
objects/input.o
BIN
objects/input.o
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
objects/tetra.o
BIN
objects/tetra.o
Binary file not shown.
BIN
objects/vector.o
BIN
objects/vector.o
Binary file not shown.
BIN
objects/win.o
BIN
objects/win.o
Binary file not shown.
0
rewritesrc/silly.zig
Normal file
0
rewritesrc/silly.zig
Normal file
|
@ -1,14 +0,0 @@
|
||||||
_,_ _,_
|
|
||||||
}\>' ``'-./\.-''` '</{
|
|
||||||
}\> ,-''``''-. </{
|
|
||||||
}\> ,' `. </{
|
|
||||||
}\/ /\ /\ \/{
|
|
||||||
} ( /__',( __\ )\{
|
|
||||||
,;' ) \|^ | `|^ |/ ( \{
|
|
||||||
}/ /_[],`' `',[]_\ \{
|
|
||||||
}/ ( )\`-.`..-'/( ) \{
|
|
||||||
`''--\(_.-'/\'-._)/--''`
|
|
||||||
\ /L]\ /
|
|
||||||
;',_/ \_,';
|
|
||||||
'.'',__,''.'
|
|
||||||
\_.' '._/
|
|
|
@ -118,11 +118,9 @@ usize TerminalPrint(struct Terminal *term)
|
||||||
usize len = 7;
|
usize len = 7;
|
||||||
memcpy(term->str, "\x1b[H\x1b[0m", 7);
|
memcpy(term->str, "\x1b[H\x1b[0m", 7);
|
||||||
|
|
||||||
usize i = 0;
|
struct Char4 *ch4 = term->buf;
|
||||||
for (usize y = 0; y < term->hgt; y++) {
|
for (usize y = 0; y < term->hgt; y++) {
|
||||||
for (usize x = 0; x < term->wid; x++, i++) {
|
for (usize x = 0; x < term->wid; x++, ch4++) {
|
||||||
struct Char4 *ch4 = &term->buf[i];
|
|
||||||
|
|
||||||
// DEBUG
|
// DEBUG
|
||||||
if (ch4->ch == 0)
|
if (ch4->ch == 0)
|
||||||
ch4->ch = '#';
|
ch4->ch = '#';
|
||||||
|
@ -135,4 +133,9 @@ usize TerminalPrint(struct Terminal *term)
|
||||||
|
|
||||||
term->str[len] = 0;
|
term->str[len] = 0;
|
||||||
return len;
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Char4 *TerminalGet(struct Terminal *term, usize x, usize y)
|
||||||
|
{
|
||||||
|
return term->buf + term->wid * y + x;
|
||||||
}
|
}
|
|
@ -29,4 +29,6 @@ bool CreateTerminal(struct Terminal *term, usize wid, usize hgt);
|
||||||
|
|
||||||
void FreeTerminal(struct Terminal *term);
|
void FreeTerminal(struct Terminal *term);
|
||||||
|
|
||||||
usize TerminalPrint(struct Terminal *term);
|
usize TerminalPrint(struct Terminal *term);
|
||||||
|
|
||||||
|
struct Char4 *TerminalGet(struct Terminal *term, usize x, usize y);
|
|
@ -1,5 +1,6 @@
|
||||||
#include "fumotris.h"
|
#include "fumotris.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
|
||||||
struct Fumotris {
|
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)
|
void place(struct Fumotris *fumo)
|
||||||
{
|
{
|
||||||
TetraOverlay(&fumo->piece, &fumo->board);
|
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 y = fumo->piece.y; y < fumo->piece.y + fumo->piece.hgt; y++) {
|
||||||
for (usize x = 0; x < fumo->board.wid; x++) {
|
if (check_clear(&fumo->board, y)) {
|
||||||
if (fumo->board.blks[fumo->board.wid * y + x] == 0) {
|
lines_cleared += 1;
|
||||||
lines_cleared -= 1;
|
shift_down(&fumo->board, y);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +74,25 @@ void FumotrisStart(struct Instance *inst, struct Fumotris *fumo)
|
||||||
{
|
{
|
||||||
ControllerBindMulti(&inst->ctrl, BINDS_N, CONTROLS, CODES, TYPES);
|
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++)
|
for (usize i = 0; i < 7; i++)
|
||||||
fumo->bag[i] = templates[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)
|
void FumotrisDraw(struct Instance *inst, struct Fumotris *fumo)
|
||||||
{
|
{
|
||||||
TetraTerminalClear(&fumo->board, &fumo->term);
|
TetraTerminalClear(&fumo->board, &fumo->term, 3, 5);
|
||||||
TetraTerminalDraw(&fumo->board, &fumo->term);
|
TetraTerminalDraw(&fumo->board, &fumo->term, 3, 5);
|
||||||
TetraTerminalDraw(&fumo->piece, &fumo->term);
|
|
||||||
|
TetraTerminalDrawGhost(&fumo->piece, &fumo->board, &fumo->term, 3, 5);
|
||||||
|
TetraTerminalDraw(&fumo->piece, &fumo->term, 3, 5);
|
||||||
|
|
||||||
TerminalPrint(&fumo->term);
|
TerminalPrint(&fumo->term);
|
||||||
puts(fumo->term.str);
|
puts(fumo->term.str);
|
||||||
|
@ -130,6 +158,8 @@ void FumotrisDraw(struct Instance *inst, struct Fumotris *fumo)
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
system("color");
|
||||||
|
|
||||||
struct Instance inst;
|
struct Instance inst;
|
||||||
CreateFumoInstance(&inst);
|
CreateFumoInstance(&inst);
|
||||||
|
|
||||||
|
@ -144,27 +174,4 @@ int main()
|
||||||
FumoInstanceRun(&inst);
|
FumoInstanceRun(&inst);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
| | NEXT LINES
|
|
||||||
| [][][]. . . . . . . |
|
|
||||||
| [][][]. . . . . . . | SCORE
|
|
||||||
| [][][][]. . . . . . |
|
|
||||||
| [][][]. . . . . . [] |
|
|
||||||
| []. . [][]. . . . [] |
|
|
||||||
| [][][][][][]. . . [] |
|
|
||||||
| . . [][]. . . . . [] |
|
|
||||||
| [][][][]. [][]. [][] |
|
|
||||||
| [][][][][][][]. [][] |
|
|
||||||
| [][][][][][][][][][] |
|
|
||||||
| [][][][][][][][][][] |
|
|
||||||
| [][][][][][][][][][] |
|
|
||||||
| [][][][][][][][][][] |
|
|
||||||
| [][][][][][][]. [][] |
|
|
||||||
| . [][][][][][]. . [] |
|
|
||||||
| [][][]. [][][][]. [] |
|
|
||||||
| [][][][][][][][]. [] |
|
|
||||||
| [][][][][][][][]. [] |
|
|
||||||
| . [][][][][][][][][] |
|
|
||||||
| . [][][][][][][][][] |
|
|
||||||
|________________________|
|
|
|
@ -59,14 +59,14 @@ usize rotate_index(usize i, usize wid, u8 rot)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TetraIsCollision(struct Tetra *t, struct Tetra *board)
|
bool TetraIsCollision(struct Tetra *piece, struct Tetra *board)
|
||||||
{
|
{
|
||||||
usize i = 0;
|
usize i = 0;
|
||||||
for (i16 y = t->y; y < t->y + t->hgt; y++) {
|
for (i16 y = piece->y; y < piece->y + piece->hgt; y++) {
|
||||||
for (i16 x = t->x; x < t->x + t->wid; x++, i++) {
|
for (i16 x = piece->x; x < piece->x + piece->wid; x++, i++) {
|
||||||
usize rot_i = rotate_index(i, t->wid, t->rot);
|
usize rot_i = rotate_index(i, piece->wid, piece->rot);
|
||||||
|
|
||||||
if(t->blks[rot_i] == 0)
|
if(piece->blks[rot_i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if(x < 0 or x >= board->wid or y < 0 or y >= board->hgt)
|
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++) {
|
for (i16 y = board->y; y < board->y + board->hgt; y++) {
|
||||||
struct Char4 *block = term->buf + i * 2;
|
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 };
|
ch4[0] = (struct Char4) { .ch = '.', .color.fg = 8 };
|
||||||
block[1] = (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 };
|
static const u8f blk_colors[8] = { 8, 14, 11, 13, 10, 9, 12, 3 };
|
||||||
|
|
||||||
usize i = 0;
|
usize i = 0;
|
||||||
for (usize y = 0; y < t->hgt; y++) {
|
for (i16 y = piece->y; y < piece->y + piece->hgt; y++) {
|
||||||
for (usize x = 0; x < t->wid; x++, i++) {
|
for (i16 x = piece->x; x < piece->x + piece->wid; x++, i++) {
|
||||||
usize rot_i = rotate_index(i, t->wid, t->rot);
|
usize rot_i = rotate_index(i, piece->wid, piece->rot);
|
||||||
|
|
||||||
if (t->blks[rot_i] == 0)
|
if (piece->blks[rot_i] == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
usize term_i = (y + t->y) * term->wid + (x + t->x) * 2;
|
struct Char4 *ch4 = TerminalGet(term, (x * 2) + OFS_X, y + OFS_Y);
|
||||||
struct Char4 *block = term->buf + term_i;
|
|
||||||
|
|
||||||
u8 fg = blk_colors[t->blks[rot_i]];
|
u8 fg = blk_colors[piece->blks[rot_i]];
|
||||||
block[0] = (struct Char4) { .ch = '[', .color.fg = fg };
|
|
||||||
block[1] = (struct Char4) { .ch = ']', .color.fg = fg };
|
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 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -36,6 +36,8 @@ bool TetraRotate(struct Tetra *t, struct Tetra *board, i8 dr);
|
||||||
|
|
||||||
void TetraOverlay(struct Tetra *t, struct Tetra *board);
|
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);
|
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);
|
||||||
|
|
Loading…
Reference in a new issue