mirror of https://git.sr.ht/~kikoodx/sle
53 lines
1.4 KiB
C
53 lines
1.4 KiB
C
/* SPDX-License-Identifier: GPL-3.0-or-later */
|
|
/* Copyright (C) 2021 KikooDX */
|
|
|
|
#include "conf.h"
|
|
#include "editing_area/level.h"
|
|
#include "options.h"
|
|
#include <raylib.h>
|
|
#include <stdlib.h>
|
|
|
|
void level_draw(struct Level level, struct Options options,
|
|
Texture2D tileset)
|
|
{
|
|
int x;
|
|
int y;
|
|
for (x = 0; x < level.width; x += 1) {
|
|
for (y = 0; y < level.height; y += 1) {
|
|
const int tile_index = x + y * level.width;
|
|
if (tile_index &&
|
|
tile_index < options.tileset_width *
|
|
options.tileset_height) {
|
|
const int tile =
|
|
level.data[x + y * level.width];
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void editor_mouse_draw(struct Options options, int x, int y)
|
|
{
|
|
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);
|
|
}
|