added drawing function
This commit is contained in:
parent
8a729e2884
commit
8dfb262a78
BIN
bin/mamaker
BIN
bin/mamaker
Binary file not shown.
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#include "consts.h"
|
#include "consts.h"
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
#include "display.h"
|
||||||
#include "assembly.h"
|
#include "assembly.h"
|
||||||
|
|
||||||
void init_empty_board() {
|
void init_empty_board() {
|
||||||
|
@ -26,12 +27,10 @@ void init_empty_board() {
|
||||||
start->prev_2 = NULL;
|
start->prev_2 = NULL;
|
||||||
start->prev_3 = NULL;
|
start->prev_3 = NULL;
|
||||||
start->prev_4 = NULL;
|
start->prev_4 = NULL;
|
||||||
start->prev_5 = NULL;
|
|
||||||
start->next_1 = start;
|
start->next_1 = start;
|
||||||
start->next_2 = NULL;
|
start->next_2 = NULL;
|
||||||
start->next_3 = NULL;
|
start->next_3 = NULL;
|
||||||
start->next_4 = NULL;
|
start->next_4 = NULL;
|
||||||
start->next_5 = NULL;
|
|
||||||
start->meta = "start";
|
start->meta = "start";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,14 @@ bool is_an_integer(char c) {
|
||||||
return ((int)c >= 48 && (int)c <= 57);
|
return ((int)c >= 48 && (int)c <= 57);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float to_float(int n) {
|
||||||
|
return (float)n ;
|
||||||
|
}
|
||||||
|
|
||||||
|
float to_int(float n) {
|
||||||
|
return (int)n ;
|
||||||
|
}
|
||||||
|
|
||||||
imgs import_digits(SDL_Renderer* renderer) {
|
imgs import_digits(SDL_Renderer* renderer) {
|
||||||
imgs res;
|
imgs res;
|
||||||
res.arr = malloc(sizeof(SDL_Texture*)*10);
|
res.arr = malloc(sizeof(SDL_Texture*)*10);
|
||||||
|
|
|
@ -5,10 +5,14 @@ int ln_baseN(int n, int b);
|
||||||
|
|
||||||
int pw(int x, int n);
|
int pw(int x, int n);
|
||||||
|
|
||||||
|
bool is_an_integer(char c);
|
||||||
|
|
||||||
|
float to_float(int n);
|
||||||
|
|
||||||
|
float to_int(float n);
|
||||||
|
|
||||||
imgs import_digits(SDL_Renderer* renderer);
|
imgs import_digits(SDL_Renderer* renderer);
|
||||||
|
|
||||||
void free_digits(imgs dgts);
|
void free_digits(imgs dgts);
|
||||||
|
|
||||||
bool is_an_integer(char c);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -42,12 +42,10 @@ typedef struct cell {
|
||||||
struct cell* prev_2 ;
|
struct cell* prev_2 ;
|
||||||
struct cell* prev_3 ;
|
struct cell* prev_3 ;
|
||||||
struct cell* prev_4 ;
|
struct cell* prev_4 ;
|
||||||
struct cell* prev_5 ;
|
|
||||||
struct cell* next_1 ;
|
struct cell* next_1 ;
|
||||||
struct cell* next_2 ;
|
struct cell* next_2 ;
|
||||||
struct cell* next_3 ;
|
struct cell* next_3 ;
|
||||||
struct cell* next_4 ;
|
struct cell* next_4 ; // I dont wanna deal with free/malloc there pls
|
||||||
struct cell* next_5 ; // I dont wanna deal with free/malloc there pls
|
|
||||||
char* meta ; // mostly for event spaces (also for hidden blocks)
|
char* meta ; // mostly for event spaces (also for hidden blocks)
|
||||||
} cell ;
|
} cell ;
|
||||||
|
|
||||||
|
@ -100,4 +98,9 @@ static player* players ;
|
||||||
static imgs* digits ;
|
static imgs* digits ;
|
||||||
// len is always 10 for this
|
// len is always 10 for this
|
||||||
|
|
||||||
|
static int __width__ = 1200 ;
|
||||||
|
static int __height__ = 800 ;
|
||||||
|
|
||||||
|
static int tile_size = 50 ;
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -12,6 +12,7 @@
|
||||||
#include <SDL2/SDL_image.h>
|
#include <SDL2/SDL_image.h>
|
||||||
|
|
||||||
#include "consts.h"
|
#include "consts.h"
|
||||||
|
#include "base.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
|
||||||
void updateRenderer(SDL_Renderer* renderer) {
|
void updateRenderer(SDL_Renderer* renderer) {
|
||||||
|
@ -70,3 +71,29 @@ void drawNumberToRenderer(SDL_Renderer* renderer, imgs data, int n, int X, int Y
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void draw_cell(SDL_Renderer* renderer, int xmin, int xmax, int ymin, int ymax, cell* cl, int draw_id) {
|
||||||
|
if(cl != NULL && cl->id != draw_id && cl->coord_x - tile_size > xmin && cl->coord_x - tile_size < xmax && cl->coord_y > ymin && cl->coord_y < ymax) {
|
||||||
|
int nxmin = to_int((to_float(cl->coord_x) - to_float(xmin)) * to_float(__width__)) / (to_float(xmax) - to_float(xmin)) ;
|
||||||
|
int nymin = to_int((to_float(cl->coord_y) - to_float(ymin)) * to_float(__height__)) / (to_float(ymax) - to_float(ymin)) ;
|
||||||
|
placeRectToRenderer(renderer, nxmin, nymin, tile_size, tile_size, 255, 255, 255, SDL_ALPHA_OPAQUE);
|
||||||
|
|
||||||
|
cl->id = draw_id ;
|
||||||
|
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->prev_1, draw_id);
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->prev_2, draw_id);
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->prev_3, draw_id);
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->prev_4, draw_id);
|
||||||
|
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->next_1, draw_id);
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->next_2, draw_id);
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->next_3, draw_id);
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, cl->next_4, draw_id);
|
||||||
|
} else if(cl != NULL) {
|
||||||
|
cl->id = draw_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_board(SDL_Renderer* renderer, int xmin, int xmax, int ymin, int ymax, cell* one_cell) {
|
||||||
|
draw_cell(renderer, xmin, xmax, ymin, ymax, one_cell, one_cell->id +1);
|
||||||
|
}
|
|
@ -13,4 +13,8 @@ void drawDigitToRenderer(SDL_Renderer* renderer, imgs data, int digit, int X, in
|
||||||
|
|
||||||
void drawNumberToRenderer(SDL_Renderer* renderer, imgs data, int n, int X, int Y, int W, int H, int Woffset);
|
void drawNumberToRenderer(SDL_Renderer* renderer, imgs data, int n, int X, int Y, int W, int H, int Woffset);
|
||||||
|
|
||||||
|
void draw_cell(SDL_Renderer* renderer, int xmin, int xmax, int ymin, int ymax, cell* cl, int draw_id);
|
||||||
|
|
||||||
|
void draw_board(SDL_Renderer* renderer, int xmin, int xmax, int ymin, int ymax, cell* one_cell);
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Reference in New Issue