hyperultra/src/map.c

92 lines
1.8 KiB
C
Raw Normal View History

2023-03-17 13:45:20 +01:00
#include "map.h"
#include "lzy.h"
#include "cfg.h"
2023-03-24 23:31:41 +01:00
#include "maps.h"
2023-03-17 21:07:07 +01:00
#include <stddef.h>
2023-03-23 22:10:37 +01:00
#include <string.h>
2023-03-17 21:07:07 +01:00
2023-03-24 23:31:41 +01:00
struct {
const Tmj2cMap *map;
const char *name;
} maps[] = {
{ &map_nuancierdesaut_tmj, "nuancier de saut" },
{ &map_trailblazer_tmj, "trailblazer" },
2023-09-24 12:15:34 +02:00
{ &map_weallstartsomewhere_tmj, "deceptive routing" },
2023-03-24 23:34:26 +01:00
{ &map_wakywakysnakysnake_tmj, "waky waky snaky snek" },
2023-03-25 10:01:23 +01:00
{ &map_fillerepisode_tmj, "filler episode" },
2023-03-24 23:31:41 +01:00
{ &map_idkwymmdr_tmj, "idk wym mdr" },
2023-03-25 10:25:37 +01:00
{ &map_brulez_tmj, "brulez" },
2023-03-17 21:07:07 +01:00
};
unsigned int map_id = 0;
void
map_next(void)
{
2023-03-24 23:31:41 +01:00
if (map_id + 1 < sizeof(maps) / sizeof(maps[0]))
map_id += 1;
2023-03-17 21:07:07 +01:00
else
map_id = 0;
}
2023-03-17 13:45:20 +01:00
2023-03-17 20:44:59 +01:00
int
map_width(void)
{
2023-03-18 19:01:48 +01:00
return 25;
2023-03-17 20:44:59 +01:00
}
int
map_height(void)
{
2023-03-18 19:01:48 +01:00
return 14;
2023-03-17 20:44:59 +01:00
}
2023-03-17 13:45:20 +01:00
int
map_get(int x, int y)
{
2023-03-18 19:01:48 +01:00
if (x < 0 || y < 0 || x >= map_width() || y >= map_height())
2023-03-19 05:57:16 +01:00
return 1;
2023-03-24 23:31:41 +01:00
return maps[map_id].map->layers[0].data[x + y * map_width()];
2023-03-17 13:45:20 +01:00
}
int
map_get_px(int x, int y)
{
if (x < 0 || y < 0)
2023-03-19 05:57:16 +01:00
return 1;
2023-03-17 13:45:20 +01:00
return map_get(x / TSIZE, y / TSIZE);
}
2023-03-19 05:57:16 +01:00
static void
draw_outline(int x, int y)
{
const int left = (map_get(x - 1, y) == 1);
const int right = (map_get(x + 1, y) == 1);
const int up = (map_get(x, y - 1) == 1);
const int down = (map_get(x, y + 1) == 1);
x *= TSIZE;
y *= TSIZE;
2023-03-25 21:54:50 +01:00
if (!left) (void)LZY_FillRect(x, y, 1, TSIZE);
if (!right) (void)LZY_FillRect(x + TSIZE - 1, y, 1, TSIZE);
if (!up) (void)LZY_FillRect(x, y, TSIZE, 1);
if (!down) (void)LZY_FillRect(x, y + TSIZE - 1, TSIZE, 1);
2023-03-19 05:57:16 +01:00
}
2023-03-17 13:45:20 +01:00
void
map_draw(void)
{
2023-03-21 22:19:31 +01:00
LZY_DrawSetColor(BLACK);
2023-03-18 19:01:48 +01:00
for (int y = 0; y < map_height(); y++)
for (int x = 0; x < map_width(); x++)
2023-03-19 05:57:16 +01:00
if (map_get(x, y) == 1)
draw_outline(x, y);
2023-03-17 13:45:20 +01:00
}
2023-03-21 22:19:31 +01:00
void
map_draw_ui(void)
{
2023-03-24 23:31:41 +01:00
const char *s = maps[map_id].name;
2023-03-21 22:19:31 +01:00
const int x = (DISPLAY_WIDTH - CHR_WIDTH * strlen(s)) / 2;
const int y = (DISPLAY_HEIGHT - CHR_HEIGHT) / 2;
2023-03-25 21:54:50 +01:00
(void)LZY_DrawText(x, y, s);
2023-03-21 22:19:31 +01:00
}