starship/level.c

29 lines
655 B
C

#include "level.h"
void init_level(Game *g, Level *l) {
l->width = 50;
l->length = 30;
l->data_size = l->width * l->length;
l->data = malloc(l->data_size * sizeof(char));
for (int i = 0; i < l->data_size; i++) {
//l->data[i] = 3;
}
l->game = g;
}
Color COLORS[4] = {BLACK, DARKGRAY, GRAY, LIGHTGRAY};
void draw_tile(Level *l, int x, int y) {
size_t index = x + (y * l->width);
size_t data = l->data[index] & 3;
Color c = COLORS[data];
DrawRectangle(x * 32, y * 32, 32, 32, c);
}
void draw_level(Level *l) {
for (int i = 0; i < l->width; i++) {
for (int j = 0; j < l->length; j++) {
draw_tile(l, i, j);
}
}
}