Skip to content

Commit

Permalink
brain.c
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenjxu committed Mar 16, 2024
1 parent 0dbb3f3 commit 0565bef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 14 deletions.
25 changes: 24 additions & 1 deletion brain.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@

#include "bt_ext.h"
#include "gpio.h"
#include "interrupts.h"
#include "jnxu.h"
#include "printf.h"
#include "re.h"
#include "uart.h"
#include <stdint.h>
#include "chess.h"
#include "chess_gui.h"
#include "gl.h"

void brain(void) {
interrupts_init();
interrupts_global_enable();
uart_init();
bt_ext_init();
chess_init();

chess_gui_init();

// while (1) {
// char* move = chess_get_move();
// chess_gui_update(move);
// chess_send_move("e7e5\n");
// }
}
2 changes: 1 addition & 1 deletion chess.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void chess_send_move(const char* move) {
uart_putstring(move);
}

void chess_init() { // TODO: white or black
void chess_init(void) { // TODO: white or black
uart_putstring("GAME_BEGIN\n");
while (true) {
char* start = chess_get_move();
Expand Down
28 changes: 16 additions & 12 deletions chess_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#include "gpio_interrupt.h"
#include "timer.h"

#define SCREEN_WIDTH 800
#define SCREEN_HEIGHT 600
#define CHESS_BLACK gl_color(124, 149, 93)
#define CHESS_WHITE gl_color(238, 238, 213)

// initialize
static int board[CHESS_SIZE][CHESS_SIZE] = {
{WR, WN, WB, WQ, WK, WB, WN, WR},
Expand All @@ -28,19 +33,18 @@ static int board[CHESS_SIZE][CHESS_SIZE] = {

void chess_gui_draw(int b[CHESS_SIZE][CHESS_SIZE]) {
// draw the chess board
printf("hi");
int s = SCREEN_HEIGHT/8 > SCREEN_WIDTH/8 ? SCREEN_WIDTH/8 : SCREEN_HEIGHT/8;

for (int i = 0; i < 8; i++) {
for (int j = 0; j < 8; j++) {
if ((i + j) % 2 == 0) {
gl_draw_rect(50*i, 50*j, 50, 50, GL_GREEN);
gl_draw_rect(s*i, s*j, s, s, CHESS_WHITE);
}
else {
gl_draw_rect(50*i, 50 * j, 50, 50, GL_YELLOW);
gl_draw_rect(s*i, s*j, s, s, CHESS_BLACK);
}
}
}

// TODO: print the piece name using board array
}

void chess_gui_update(const char* move) {
Expand All @@ -63,18 +67,18 @@ void chess_gui_print(void) {

void chess_gui_init(void) {

const int WIDTH = 300;
const int HEIGHT = 300;

gl_init(WIDTH, HEIGHT, GL_DOUBLEBUFFER);
gl_init(SCREEN_WIDTH, SCREEN_HEIGHT, GL_DOUBLEBUFFER);

uart_putstring("Clearing screen\n");
gl_clear(GL_WHITE);
gl_swap_buffer();
gl_draw_rect(0, 0, 50, 50, GL_GREEN);
gl_swap_buffer();

uart_putstring("Done\n");

// chess_gui_draw(board);
chess_gui_draw(board);
gl_swap_buffer();

while (1) {

}
}

0 comments on commit 0565bef

Please sign in to comment.