commit 57356f21317ec277d04896bfcd09fa822401c5f7
parent bf9b1846d069a431087c28e6eac17ce71fd78226
Author: Benjamin Paul <bpaul@bpaul.xyz>
Date: Wed, 1 Sep 2021 23:48:02 +1000
draws queue, started on drawing board
Diffstat:
4 files changed, 51 insertions(+), 9 deletions(-)
diff --git a/board.h b/board.h
@@ -0,0 +1,11 @@
+#pragma once
+
+typedef struct {
+ int grid[40][10];
+ /* Ring buffer queue btw */
+ int q[7];
+ int qi;
+ int hold;
+ /* For 7 bag randomizer and stuff */
+ int bag;
+} Board;
diff --git a/draw.c b/draw.c
@@ -1,5 +1,6 @@
#include <ncurses.h>
+#include "board.h"
#include "piece.h"
extern const bool piece_occupancy[PIECE_CNT][ROTATION_CNT][9];
@@ -44,3 +45,23 @@ draw_box(int x1, int y1, int x2, int y2) {
attroff(COLOR_PAIR(8));
}
+void
+draw_board(Board *b) {
+ int i,j;
+ for (i = 0; i < 21; i++) {
+ for (j = 0; j < 10; j++) {
+ attron(COLOR_PAIR(1));
+ draw_square(LINES/2 + 10 - i, COLS/2 - 10 + j*2);
+ attroff(COLOR_PAIR(1));
+ }
+ }
+}
+
+void
+draw_queue(Board *b) {
+ int i = b->qi+1;
+ for (int _ = 0; _ < 6; _++) {
+ draw_piece(LINES/2 - 10 + 3*_, COLS/2 + 16, b->q[i++], NORTH);
+ i %= 7;
+ }
+}
diff --git a/draw.h b/draw.h
@@ -2,5 +2,9 @@
#include <ncurses.h>
+#include "board.h"
+
void draw_piece(int y, int x, int piece, int rot);
void draw_box(int x1, int y1, int x2, int y2);
+void draw_board(Board *b);
+void draw_queue(Board *b);
diff --git a/main.c b/main.c
@@ -1,24 +1,30 @@
#include <ncurses.h>
#include <string.h>
+#include "board.h"
#include "draw.h"
#include "piece.h"
void
play_sprint() {
+ Board b;
+ b.q[0] = O;
+ b.q[1] = I;
+ b.q[2] = T;
+ b.q[3] = L;
+ b.q[4] = J;
+ b.q[5] = S;
+ b.q[6] = Z;
+ b.qi = 5;
+
clear();
- draw_box(COLS/2 - 10, LINES/2 - 10, COLS/2 + 10, LINES/2 + 10);
+ draw_box(COLS/2 - 11, LINES/2 - 11, COLS/2 + 10, LINES/2 + 11);
char key;
for (;;) {
- draw_piece(LINES/2 - 9, COLS/2 - 2, O, NORTH);
- draw_piece(LINES/2 - 6, COLS/2 - 2, I, NORTH);
- draw_piece(LINES/2 - 3, COLS/2 - 2, T, NORTH);
- draw_piece(LINES/2 - 0, COLS/2 - 2, L, NORTH);
- draw_piece(LINES/2 + 3, COLS/2 - 2, J, NORTH);
- draw_piece(LINES/2 + 6, COLS/2 - 2, S, NORTH);
- draw_piece(LINES/2 + 9, COLS/2 - 2, Z, NORTH);
+ draw_board(&b);
+ draw_queue(&b);
key = getch();
if (key == 'q') break;
}
@@ -33,7 +39,7 @@ void
draw_main_menu() {
clear();
- draw_box(COLS/2 - 10, LINES/2 - 10, COLS/2 + 10, LINES/2 + 10);
+ draw_box(COLS/2 - 11, LINES/2 - 11, COLS/2 + 10, LINES/2 + 11);
draw_menu_item(LINES/2 - 8, "Sprint");
}