Level draw.
This commit is contained in:
parent
f3f6677386
commit
f9262b17b8
|
@ -15,8 +15,10 @@ find_package(Gint 2.1 REQUIRED)
|
|||
|
||||
set(SOURCES
|
||||
src/main.c
|
||||
src/player.c
|
||||
src/input.c
|
||||
src/level.c
|
||||
src/player.c
|
||||
src/tiles.c
|
||||
src/gen_levels.c
|
||||
# ...
|
||||
)
|
||||
|
|
|
@ -6,3 +6,5 @@
|
|||
#define LEVEL_WIDTH 16
|
||||
#define LEVEL_HEIGHT 16
|
||||
#define LEVEL_SIZE (LEVEL_WIDTH * LEVEL_HEIGHT)
|
||||
#define DRAW_OFFSET_X 70
|
||||
#define DRAW_OFFSET_Y 0
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include "conf.h"
|
||||
#include "tiles.h"
|
||||
#include "vec2.h"
|
||||
|
||||
typedef uint8_t tile_t;
|
||||
typedef struct Level{
|
||||
tile_t content[LEVEL_WIDTH * LEVEL_HEIGHT];
|
||||
Vec2 start_pos;
|
||||
} Level;
|
||||
|
||||
void level_draw(Level level);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
typedef uint8_t tile_t;
|
||||
enum {
|
||||
AIR_TILE,
|
||||
SOLID_TILE,
|
||||
|
@ -11,3 +12,5 @@ enum {
|
|||
CHECKY_TILE,
|
||||
};
|
||||
#define OUT_OF_BOUNDS AIR_TILE
|
||||
|
||||
int tile_color(tile_t tile);
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#include <gint/display.h>
|
||||
#include "level.h"
|
||||
#include "tiles.h"
|
||||
|
||||
void level_draw(Level level) {
|
||||
/* Pixel position (where we draw). */
|
||||
uint16_t x = DRAW_OFFSET_X;
|
||||
uint16_t y = DRAW_OFFSET_Y;
|
||||
/* Cursor position. */
|
||||
uint16_t cx = 0;
|
||||
while (cx < LEVEL_WIDTH) {
|
||||
uint16_t cy = 0;
|
||||
while (cy < LEVEL_HEIGHT) {
|
||||
const tile_t tile = level.content[cy * LEVEL_WIDTH + cx];
|
||||
const int color = tile_color(tile);
|
||||
drect(x, y, x + TILE_SIZE - 1, y + TILE_SIZE - 1, color);
|
||||
y += TILE_SIZE;
|
||||
cy += 1;
|
||||
}
|
||||
y = DRAW_OFFSET_Y;
|
||||
x += TILE_SIZE;
|
||||
cx += 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -52,6 +52,7 @@ int main(void) {
|
|||
/* Draw. */
|
||||
dclear(C_BLACK);
|
||||
/* player_draw(player); */
|
||||
level_draw(level);
|
||||
dupdate();
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#include <gint/display.h>
|
||||
#include "tiles.h"
|
||||
|
||||
int tile_color(tile_t tile) {
|
||||
int color = 0;
|
||||
switch (tile) {
|
||||
case AIR_TILE: color = C_RGB(0, 0, 0); break;
|
||||
case SOLID_TILE: color = C_RGB(10, 210, 180); break;
|
||||
case PAIN_TILE: color = C_RGB(210, 10, 180); break;
|
||||
case SPAWN_TILE: color = C_RGB(20, 220, 20); break;
|
||||
case EXIT_TILE: color = C_RGB(250, 220, 10); break;
|
||||
case KEY_TILE: color = C_RGB(210, 210, 210); break;
|
||||
case SEMI_SOLID: color = C_RGB(5, 105, 90); break;
|
||||
}
|
||||
return color;
|
||||
}
|
Loading…
Reference in New Issue