summaryrefslogtreecommitdiff
path: root/kon/kontile.h
blob: f671da94ee53ffcf5ea9545dd264f1d8df91d01d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* SPDX-License-Identifier: MIT */
/*
 * kontile.h
 *
 * Copyright (c) 2026 KonAki
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef KONTILE_H
#define KONTILE_H

#include "konsofren.h"

/*** definition ***/

/* tiles holds columns * rows ids, 0 is empty and n draws tile n - 1 of the sheet, counted left to right then top to bottom */
typedef struct kon_tilemap {
	int columns, rows;
	int tileWidth, tileHeight;
	uint16_t *tiles;
	const kon_image *sheet;
	int sheetColumns; /* 0 works it out from the sheet width */
} kon_tilemap_t;

/* 0 outside the map */
uint16_t kon_tilemapAt(const kon_tilemap_t *map, int column, int row);

/* does nothing outside the map */
void kon_tilemapSet(kon_tilemap_t *map, int column, int row, uint16_t tile);

/* works for negative positions too, returns 0 if the position is outside the map */
int kon_tilemapPixelToTile(const kon_tilemap_t *map, int x, int y, int *column, int *row);

/* solid is indexed by tile id, non-zero means solid, ids past solidCount are not solid. solid[0] decides what the empty tile
   and everything outside the map counts as. returns 1 if any tile touching the box x, y, width, height (in map pixels) is solid */
int kon_tilemapBoxHits(const kon_tilemap_t *map, int x, int y, int width, int height, const uint8_t *solid, int solidCount);

/* cameraX, cameraY is the map pixel shown at the top left of fb */
void kon_drawTilemap(kon_framebuffer_t *fb, const kon_tilemap_t *map, int cameraX, int cameraY);

#endif