30 lines
702 B
C
30 lines
702 B
C
#include "level.h"
|
|
|
|
void init_level(Game *g, Level *l) {
|
|
l->width = 50;
|
|
l->length = 300;
|
|
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] = rand() % 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) {
|
|
Camera2D *camera = l->game->camera;
|
|
for (int i = 0; i < l->width; i++) {
|
|
for (int j = 0; j < l->length; j++) {
|
|
draw_tile(l, i, j);
|
|
}
|
|
}
|
|
}
|