diff options
Diffstat (limited to 'kon/konrpg.h')
| -rw-r--r-- | kon/konrpg.h | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/kon/konrpg.h b/kon/konrpg.h new file mode 100644 index 0000000..3eb1820 --- /dev/null +++ b/kon/konrpg.h @@ -0,0 +1,104 @@ +/* SPDX-License-Identifier: MIT */ +/* + * konrpg.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 KONRPG_H +#define KONRPG_H + +#include "kontile.h" + +/*** directions ***/ + +/* the order of the rows in an RPG Maker character sheet */ +typedef enum kon_dir { + KON_DIR_DOWN, + KON_DIR_LEFT, + KON_DIR_RIGHT, + KON_DIR_UP +} kon_dir_t; + +/* one tile in that direction, y grows downwards */ +void kon_dirDelta(kon_dir_t dir, int *dx, int *dy); +kon_dir_t kon_dirOpposite(kon_dir_t dir); + +/*** actors ***/ + +/* something that walks a tile at a time. column, row is the tile it is on, or heading for while it moves. + the game picks the direction every frame, kon_actorWalk starts a step when it is standing still and kon_actorUpdate moves it along */ +typedef struct kon_actor { + int column, row; + int fromColumn, fromRow; + kon_dir_t facing; + int moving; + float progress; /* 0 to 1 along the current step */ + float speed; /* tiles a second */ + + /* private */ + float carry; +} kon_actor_t; + +/* return non-zero if something other than the tilemap stands in the way of a step onto column, row */ +typedef int (*kon_blockFn)(int column, int row, void *user); + +void kon_actorInit(kon_actor_t *actor, int column, int row, kon_dir_t facing); + +/* turns to face dir, then starts a step if the tile ahead is inside the map, not solid (see kon_tilemapBoxHits for solid) and not + blocked by the callback, which may be NULL. does nothing but turn while a step is going. returns 1 if a step started */ +int kon_actorWalk(kon_actor_t *actor, const kon_tilemap_t *map, const uint8_t *solid, int solidCount, kon_dir_t dir, kon_blockFn blocked, void *user); + +/* returns 1 on the frame the actor arrives on a tile. time left over at the end of a step is kept for the next one, + so holding a direction walks at exactly speed at any frame rate */ +int kon_actorUpdate(kon_actor_t *actor, float dt); + +/* where the actor's top left is in map pixels, in between tiles while it moves */ +void kon_actorPixel(const kon_actor_t *actor, const kon_tilemap_t *map, float *x, float *y); + +/* the tile the actor is looking at, the one it is on while it moves */ +void kon_actorFront(const kon_actor_t *actor, int *column, int *row); + +/*** events ***/ + +typedef enum kon_trigger { + KON_TRIGGER_TALK, /* the actor faces it and presses the action key */ + KON_TRIGGER_TOUCH, /* the actor walks into it */ + KON_TRIGGER_STEP /* the actor arrives on it */ +} kon_trigger_t; + +/* a thing on the map the game reacts to. id means whatever the game wants, a switch into its own script, a door, a chest. + blocks makes it solid like a person or a rock. to move one just change its column and row */ +typedef struct kon_tileEvent { + int column, row; + kon_trigger_t trigger; + int id; + int blocks; +} kon_tileEvent_t; + +/* index of the first event on the tile with that trigger, or -1. trigger -1 matches any */ +int kon_eventAt(const kon_tileEvent_t *events, int count, int column, int row, int trigger); + +/* 1 if a blocking event is on the tile, for kon_actorWalk. user is a kon_eventList_t */ +typedef struct kon_eventList { const kon_tileEvent_t *events; int count; } kon_eventList_t; +int kon_eventBlocks(int column, int row, void *user); + +#endif |
