2021-03-23 19:03:44 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
|
|
/* Copyright (C) 2021 KikooDX */
|
|
|
|
|
|
|
|
#include "conf.h"
|
2021-03-23 23:23:43 +01:00
|
|
|
#include "editing_area/level.h"
|
2021-03-26 13:54:38 +01:00
|
|
|
#include "options.h"
|
2021-03-23 19:03:44 +01:00
|
|
|
#include <raylib.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2021-03-26 13:54:38 +01:00
|
|
|
void level_draw(struct Level level, struct Options options,
|
|
|
|
Texture2D tileset)
|
2021-03-23 19:03:44 +01:00
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
for (x = 0; x < level.width; x += 1) {
|
|
|
|
for (y = 0; y < level.height; y += 1) {
|
2021-03-26 13:54:38 +01:00
|
|
|
const int tile_index = x + y * level.width;
|
2021-03-26 18:54:25 +01:00
|
|
|
/* if tile index is out of bound, skip */
|
2021-03-26 23:25:23 +01:00
|
|
|
if (tile_index >= level.width * level.height)
|
2021-03-26 18:54:25 +01:00
|
|
|
continue;
|
|
|
|
const Tile tile =
|
|
|
|
level.data[x + y * level.width];
|
|
|
|
/* if tile is not in tileset, skip */
|
2021-03-26 23:25:23 +01:00
|
|
|
if (!tile || tile >= options.tileset_width *
|
|
|
|
options.tileset_height)
|
2021-03-26 18:54:25 +01:00
|
|
|
continue;
|
|
|
|
|
|
|
|
const Rectangle tile_rect = {
|
|
|
|
(int)(tile % options.tileset_width) *
|
|
|
|
options.tile_width,
|
|
|
|
(int)(tile / options.tileset_height) *
|
|
|
|
options.tile_height,
|
|
|
|
options.tile_width, options.tile_height};
|
|
|
|
const Vector2 tile_pos = {
|
|
|
|
x * options.tile_width +
|
|
|
|
options.editor_draw_offset_x,
|
|
|
|
y * options.tile_height +
|
|
|
|
options.editor_draw_offset_y};
|
|
|
|
DrawTextureRec(tileset, tile_rect, tile_pos,
|
|
|
|
WHITE);
|
2021-03-23 19:03:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-03-25 00:24:04 +01:00
|
|
|
|
2021-03-26 13:54:38 +01:00
|
|
|
void editor_mouse_draw(struct Options options, int x, int y)
|
2021-03-25 01:14:39 +01:00
|
|
|
{
|
2021-03-26 13:54:38 +01:00
|
|
|
const int tx =
|
|
|
|
x * options.tile_width + options.editor_draw_offset_x;
|
|
|
|
const int ty =
|
|
|
|
y * options.tile_height + options.editor_draw_offset_y;
|
|
|
|
DrawRectangle(tx, ty, options.tile_width, options.tile_height,
|
|
|
|
OVERRING_TILE_COLOR);
|
2021-03-25 00:24:04 +01:00
|
|
|
}
|