65 lines
960 B
C
65 lines
960 B
C
#include "fillit.h"
|
|
#include <stdlib.h>
|
|
#include <stdio.h>
|
|
|
|
unsigned int ft_sqrt_ceil(unsigned int num)
|
|
{
|
|
int i;
|
|
|
|
i = 1;
|
|
while (i * i < num)
|
|
i++;
|
|
return (i);
|
|
}
|
|
|
|
void clear_map(t_map *map)
|
|
{
|
|
int i;
|
|
|
|
i = 0;
|
|
while (i < 16)
|
|
map->line[i++] = 0;
|
|
}
|
|
|
|
t_tetraminos *convert_tetramino(char *s)
|
|
{
|
|
t_tetraminos *res;
|
|
uint16_t temp;
|
|
int i;
|
|
int y;
|
|
|
|
res = (t_tetraminos*)malloc(sizeof(t_tetraminos));
|
|
res->offset_y = 0;
|
|
i = 0;
|
|
y = 1;
|
|
while (i < 16)
|
|
{
|
|
temp = 0;
|
|
while (i < y * 4)
|
|
{
|
|
temp = temp << 1;
|
|
if (s[i++] == '#')
|
|
temp = temp | 0x01;
|
|
|
|
}
|
|
temp = temp << 12;
|
|
res->line[y - 1] = temp;
|
|
y++;
|
|
}
|
|
return (res);
|
|
}
|
|
|
|
t_map *map_initialization(char **tetramino_table)
|
|
{
|
|
t_map *map;
|
|
unsigned int i;
|
|
|
|
map = (t_map*)malloc(sizeof(t_map));
|
|
i = 0;
|
|
while (*tetramino_table)
|
|
map->figure[i++] = convert_tetramino(*tetramino_table++);
|
|
map->figure_amount = i;
|
|
map->size = ft_sqrt_ceil(i * 4);
|
|
clear_map(map);
|
|
return (map);
|
|
}
|