summaryrefslogtreecommitdiff
path: root/frontends
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2019-10-26 02:27:12 -0400
committerAndrew Opalach <andrew@akon.city> 2019-10-26 02:27:12 -0400
commitbc09954f9105ed62acd583c0c36a7ca1cf92349b (patch)
tree0b30545f01ab5f47fd4f9add8c338a5365e8093f /frontends
parentf3e7787552eef537f6954c73d6d42ca60fb76e84 (diff)
downloadcetris-bc09954f9105ed62acd583c0c36a7ca1cf92349b.tar.gz
cetris-bc09954f9105ed62acd583c0c36a7ca1cf92349b.tar.bz2
cetris-bc09954f9105ed62acd583c0c36a7ca1cf92349b.zip
more sdl ui
Diffstat (limited to 'frontends')
-rw-r--r--frontends/sdl/sdl_ui.c63
1 files changed, 47 insertions, 16 deletions
diff --git a/frontends/sdl/sdl_ui.c b/frontends/sdl/sdl_ui.c
index 3584c9d..0f40bbc 100644
--- a/frontends/sdl/sdl_ui.c
+++ b/frontends/sdl/sdl_ui.c
@@ -1,15 +1,19 @@
#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdio.h>
#include <pthread.h>
-#include <cetris.h>
#include <unistd.h>
+#include <time.h>
+#include <cetris.h>
#define W 480
#define H 640
-#define X_OFFSET 25
-#define Y_OFFSET 20
+#define X_OFFSET 40
+#define Y_OFFSET 30
SDL_Renderer* render;
TTF_Font* font;
@@ -31,16 +35,15 @@ uint8_t colors[8][3] = {
DWORD WINAPI game_loop(void* data) {
while(1) {
Sleep((1.0/60.0) * 1000.0);
- //if (!is_paused)
update_game_tick(&g);
}
return 0;
}
#else
void *game_loop(void) {
+ long nsec = (long)(1000000000L/CETRIS_HZ);
while(1) {
- sleep((1.0/60.0) * 1000000.0);
- //if (!is_paused)
+ nanosleep((const struct timespec[]){{0, nsec}}, NULL);
update_game_tick(&g);
}
return 0;
@@ -54,23 +57,50 @@ void setup() {
SDL_RenderSetLogicalSize(render, W, H);
if (!render) exit(fprintf(stderr, "err: could not create SDL renderer\n"));
- TTF_Init();
- font = TTF_OpenFont("LiberationMono-Regular.ttf", 18);
+ //TTF_Init();
+ //font = TTF_OpenFont("LiberationMono-Regular.ttf", 18);
}
-void draw(cetris_game* g) {
+void draw() {
+ SDL_SetRenderDrawColor(render, 255, 255, 255, 255);
+ SDL_RenderClear(render);
+
SDL_Rect b = {0, 0, 25, 25};
+
+ for (int y = 0; y < 4; y++) {
+ for (int x = 0; x < 4; x++) {
+ if ((g.current.m[y]>>(3 - x))&1) {
+ b.x = X_OFFSET + ((x + g.current.pos.x) * 25);
+ b.y = (Y_OFFSET + ((y + g.current.pos.y) * 25)) - (CETRIS_BOARD_VISABLE * 25);
+
+ uint8_t (*color)[3] = &(colors[g.current.t]);
+ SDL_SetRenderDrawColor(render, (*color)[0], (*color)[1], (*color)[2], 255);
+
+ SDL_RenderDrawRect(render, &b);
+
+ b.y = (Y_OFFSET + ((y + g.current.ghost_y) * 25)) - (CETRIS_BOARD_VISABLE * 25);
+
+ SDL_SetRenderDrawColor(render, 0, 0, 0, 255);
+ SDL_RenderDrawRect(render, &b);
+
+ }
+ //if ((default_matrices[game.piece_queue[g.current_index]][y]>>(3 - x))&1) {
+ // mvaddstr(6 + y, (x * 2) + 36, BLOCK);
+ //}
+ }
+ }
+
for (int x = 0; x < CETRIS_BOARD_X; x++) {
- for (int y = g->highest_line; y < CETRIS_BOARD_Y; y++) {
- if (g->board[x][y] & SLOT_OCCUPIED) {
+ for (int y = g.highest_line; y < CETRIS_BOARD_Y; y++) {
+ if (g.board[x][y] & SLOT_OCCUPIED) {
b.x = X_OFFSET + (x * 25);
- b.y = (Y_OFFSET + (y * 25)) - CETRIS_BOARD_VISABLE;
+ b.y = (Y_OFFSET + (y * 25)) - (CETRIS_BOARD_VISABLE * 25);
- uint8_t (*color)[3] = &(colors[(g->board[x][y] >> 5)]);
+ uint8_t (*color)[3] = &(colors[(g.board[x][y] >> 5)]);
SDL_SetRenderDrawColor(render, (*color)[0], (*color)[1], (*color)[2], 255);
- if (g->line_remove_tick[y]) {
- if (g->tick % 2 == 0) {
+ if (g.line_remove_tick[y]) {
+ if (g.tick % 2 == 0) {
SDL_RenderDrawRect(render, &b);
}
} else {
@@ -79,6 +109,7 @@ void draw(cetris_game* g) {
}
}
}
+ SDL_RenderPresent(render);
}
int main(void) {
@@ -114,7 +145,7 @@ int main(void) {
}
}
}
- draw(&g);
+ draw();
SDL_Delay(1000 / 60);
}