mirror of https://github.com/bgiraudr/Adoranda.git
characters into map and detect current tile
This commit is contained in:
parent
49673f86f7
commit
144ba20042
|
@ -26,6 +26,7 @@ set(SOURCES
|
|||
src/animation.c
|
||||
src/character.c
|
||||
src/player.c
|
||||
src/map.c
|
||||
)
|
||||
|
||||
set(ASSETS_cg
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
tileset.png:
|
||||
type: bopti-image
|
||||
name: img_tileset
|
||||
profile:p4
|
||||
|
||||
spritesheet.png:
|
||||
type: bopti-image
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<map version="1.5" tiledversion="1.7.1" orientation="orthogonal" renderorder="right-down" width="56" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="25">
|
||||
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="56" height="38" tilewidth="16" tileheight="16" infinite="0" nextlayerid="8" nextobjectid="25">
|
||||
<editorsettings>
|
||||
<export target="testCarte.json" format="json"/>
|
||||
</editorsettings>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<tileset version="1.5" tiledversion="1.7.1" name="tileset" tilewidth="16" tileheight="16" tilecount="754" columns="29">
|
||||
<tileset version="1.5" tiledversion="1.7.2" name="tileset" tilewidth="16" tileheight="16" tilecount="754" columns="29">
|
||||
<editorsettings>
|
||||
<export target="tileset.json" format="json"/>
|
||||
</editorsettings>
|
||||
|
@ -178,15 +178,15 @@
|
|||
<tile id="723" type="solid"/>
|
||||
<tile id="724" type="solid"/>
|
||||
<tile id="742" type="solid"/>
|
||||
<tile id="743" type="solid"/>
|
||||
<tile id="743" type="door"/>
|
||||
<tile id="744" type="solid"/>
|
||||
<tile id="745" type="solid"/>
|
||||
<tile id="746" type="solid"/>
|
||||
<tile id="747" type="solid"/>
|
||||
<tile id="747" type="door"/>
|
||||
<tile id="748" type="solid"/>
|
||||
<tile id="749" type="solid"/>
|
||||
<tile id="750" type="solid"/>
|
||||
<tile id="751" type="solid"/>
|
||||
<tile id="751" type="door"/>
|
||||
<tile id="752" type="solid"/>
|
||||
<tile id="753" type="solid"/>
|
||||
<wangsets>
|
||||
|
|
|
@ -10,4 +10,5 @@ struct character {
|
|||
};
|
||||
|
||||
void draw_dialog(struct character *character);
|
||||
struct character* get_character_xy(struct character *characters[], int x, int y);
|
||||
struct character* get_character_xy(struct character *characters[], int x, int y);
|
||||
struct character** get_map_characters(int id);
|
|
@ -1,4 +1,6 @@
|
|||
/*the x radius the player is able to see*/
|
||||
#define PLAYER_VIEW_X 13
|
||||
/*the y radius the player is able to see*/
|
||||
#define PLAYER_VIEW_Y 7
|
||||
#define PLAYER_VIEW_Y 8
|
||||
/*the width of the tileset*/
|
||||
#define TILESET_WIDTH 29
|
||||
|
|
|
@ -17,7 +17,7 @@ void engine_draw(struct game const *game);
|
|||
void engine_draw_map_around_player(struct game const *game);
|
||||
void engine_draw_player(struct player const *player);
|
||||
int engine_move(struct game *game, int direction);
|
||||
int map_walkable(struct map const *map, int x, int y);
|
||||
void engine_tick(struct game *game, int dt);
|
||||
void engine_set_background(struct game *game, int color);
|
||||
void engine_action(struct game const *game, int action);
|
||||
void engine_action(struct game const *game, int action);
|
||||
void engine_check_position(struct game *game);
|
|
@ -1,5 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <gint/display.h>
|
||||
#include "engine.h"
|
||||
|
||||
struct map {
|
||||
/*width, height and the number of layer of the map (max 2)*/
|
||||
int w, h, nb_layer;
|
||||
|
@ -19,3 +22,6 @@ enum map_state {
|
|||
TILE_DOOR = 2,
|
||||
TILE_CHARACTER = 3,
|
||||
};
|
||||
|
||||
int map_walkable(struct map const *map, int x, int y);
|
||||
int map_get_player_tile(struct game const *game);
|
|
@ -2,6 +2,15 @@
|
|||
#include <gint/keyboard.h>
|
||||
#include <string.h>
|
||||
#include "character.h"
|
||||
#include "engine.h"
|
||||
#include "map.h"
|
||||
|
||||
struct character character_default = {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.name = "default name",
|
||||
.dialog = "default dialog"
|
||||
};
|
||||
|
||||
/*draw the dialog of a specified character*/
|
||||
void draw_dialog(struct character *character) {
|
||||
|
@ -28,5 +37,29 @@ struct character* get_character_xy(struct character *characters[], int x, int y)
|
|||
if(characters[i]->x == x && characters[i]->y == y) return characters[i];
|
||||
i++;
|
||||
}
|
||||
return characters[i];
|
||||
return &character_default;
|
||||
}
|
||||
|
||||
struct character** get_map_characters(int id) {
|
||||
if(id == 1) {
|
||||
extern struct character character_Tituya;
|
||||
extern struct character character_Lephenixnoir;
|
||||
extern struct character character_Tituya2;
|
||||
extern struct character character_KikooDX;
|
||||
extern struct character character_Massena;
|
||||
extern struct character character_PancarteVille;
|
||||
|
||||
static struct character *characters[] = {
|
||||
&character_Tituya,
|
||||
&character_Lephenixnoir,
|
||||
&character_Massena,
|
||||
&character_Tituya2,
|
||||
&character_KikooDX,
|
||||
&character_PancarteVille,
|
||||
&character_default,
|
||||
};
|
||||
return characters;
|
||||
}
|
||||
static struct character *characters[] = {};
|
||||
return characters;
|
||||
}
|
19
src/engine.c
19
src/engine.c
|
@ -8,8 +8,6 @@
|
|||
#include "define.h"
|
||||
#include "character.h"
|
||||
|
||||
#define TILESET_WIDTH 29
|
||||
|
||||
/*draw the current state of the game*/
|
||||
void engine_draw(struct game const *game) {
|
||||
dclear(game->background);
|
||||
|
@ -109,6 +107,7 @@ int engine_move(struct game *game, int direction) {
|
|||
game->player->x += dx;
|
||||
game->player->y += dy;
|
||||
game->player->idle = !anim_player_walking(&game->player->anim, 1);
|
||||
engine_check_position(game);
|
||||
} else {
|
||||
game->player->idle = !anim_player_idle(&game->player->anim, 1);
|
||||
}
|
||||
|
@ -128,13 +127,6 @@ void engine_tick(struct game *game, int dt) {
|
|||
}
|
||||
}
|
||||
|
||||
/*check if a tile is walkable*/
|
||||
int map_walkable(struct map const *map, int x, int y) {
|
||||
int tile = map->info_map[x + map->w * y];
|
||||
if(x < 0 || x > map->w-1 || y < 0 || y > map->h-1) return 0;
|
||||
return (tile != TILE_SOLID && tile != TILE_CHARACTER);
|
||||
}
|
||||
|
||||
/*set the background color*/
|
||||
void engine_set_background(struct game *game, int color) {
|
||||
game->background = color;
|
||||
|
@ -150,4 +142,13 @@ void engine_action(struct game const *game, int action) {
|
|||
draw_dialog(get_character_xy(game->characters, game->player->x + dx, game->player->y + dy));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void engine_check_position(struct game *game) {
|
||||
int player_curr_tile = map_get_player_tile(game);
|
||||
if(player_curr_tile == TILE_DOOR) {
|
||||
engine_set_background(game, C_BLACK);
|
||||
} else {
|
||||
engine_set_background(game, C_WHITE);
|
||||
}
|
||||
}
|
31
src/main.c
31
src/main.c
|
@ -16,37 +16,13 @@ struct map *maps[] = {
|
|||
&map_1,
|
||||
};
|
||||
|
||||
extern struct character character_Tituya;
|
||||
extern struct character character_Lephenixnoir;
|
||||
extern struct character character_Tituya2;
|
||||
extern struct character character_KikooDX;
|
||||
extern struct character character_Massena;
|
||||
extern struct character character_PancarteVille;
|
||||
|
||||
|
||||
struct character character_default = {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.name = "default name",
|
||||
.dialog = "default dialog"
|
||||
};
|
||||
|
||||
struct character *characters[] = {
|
||||
&character_Tituya,
|
||||
&character_Lephenixnoir,
|
||||
&character_Massena,
|
||||
&character_Tituya2,
|
||||
&character_KikooDX,
|
||||
&character_PancarteVille,
|
||||
&character_default,
|
||||
};
|
||||
|
||||
static int callback_tick(volatile int *tick) {
|
||||
*tick = 1;
|
||||
return TIMER_CONTINUE;
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
/*Structure definition*/
|
||||
struct player player = {
|
||||
.x = 32,
|
||||
.y = 30,
|
||||
|
@ -61,22 +37,23 @@ int main(void) {
|
|||
struct game game = {
|
||||
.map = maps[0],
|
||||
.player = &player,
|
||||
.characters = characters,
|
||||
.background = C_WHITE
|
||||
};
|
||||
game.characters = get_map_characters(1);
|
||||
|
||||
/*Timer*/
|
||||
static volatile int tick = 1;
|
||||
|
||||
int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000,
|
||||
GINT_CALL(callback_tick, &tick));
|
||||
if(t >= 0) timer_start(t);
|
||||
|
||||
/*Main loop*/
|
||||
while(!keydown(KEY_MENU)) {
|
||||
while(!tick) sleep();
|
||||
tick = 0;
|
||||
|
||||
engine_draw(&game);
|
||||
dprint(1,20,C_BLACK, "%d", player_facing(&game));
|
||||
dupdate();
|
||||
|
||||
int action = get_inputs();
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
#include "map.h"
|
||||
#include "engine.h"
|
||||
#include "player.h"
|
||||
|
||||
/*check if a tile is walkable*/
|
||||
int map_walkable(struct map const *map, int x, int y) {
|
||||
int tile = map->info_map[x + map->w * y];
|
||||
if(x < 0 || x > map->w-1 || y < 0 || y > map->h-1) return 0;
|
||||
return (tile != TILE_SOLID && tile != TILE_CHARACTER);
|
||||
}
|
||||
|
||||
int map_get_player_tile(struct game const *game) {
|
||||
return game->map->info_map[game->player->x + game->map->w * game->player->y];
|
||||
}
|
Loading…
Reference in New Issue