it works better with the sources

This commit is contained in:
bgiraudr 2021-08-07 01:49:03 +02:00
parent 7561089038
commit 0e72369cf0
10 changed files with 45 additions and 14 deletions

3
.gitignore vendored
View File

@ -4,9 +4,10 @@
/*.g1a
/*.g3a
*.json
*~
# Python bytecode
__pycache__/
__pycache__/
# Common IDE files
*.sublime-project

View File

@ -25,6 +25,7 @@ set(SOURCES
src/engine.c
src/animation.c
src/character.c
src/player.c
)
set(ASSETS_cg
@ -32,6 +33,7 @@ set(ASSETS_cg
assets-cg/maps/testCarte.json
assets-cg/spritesheet.png
assets-cg/characters/Tituya.char
assets-cg/characters/Lephenixnoir.char
)
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)

View File

@ -5,6 +5,7 @@
struct game {
struct map *map;
struct player *player;
struct character **characters;
int background;
};
@ -14,4 +15,5 @@ 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_set_background(struct game *game, int color);
void engine_action(struct game const *game, int action);

View File

@ -1,4 +1,12 @@
#pragma once
void play();
int get_inputs(void);
int get_inputs(void);
enum direction {
DIR_DOWN = 0,
DIR_LEFT = 1,
DIR_UP = 2,
DIR_RIGHT = 3,
ACTION_SHIFT = 4
};

View File

@ -1,6 +1,7 @@
#pragma once
#include "animation.h"
#include "engine.h"
struct player {
int x, y;
@ -11,9 +12,4 @@ struct player {
struct anim_data anim;
};
enum direction {
DIR_DOWN = 0,
DIR_LEFT = 1,
DIR_UP = 2,
DIR_RIGHT = 3
};
int player_facing(struct game const *game);

View File

@ -2,7 +2,7 @@
#include <gint/defs/util.h>
#include "animation.h"
#include "engine.h"
#include "player.h"
#include "game.h"
struct sheet
{

View File

@ -4,9 +4,12 @@
#include "character.h"
void draw_dialog(struct character *character) {
dclear(C_WHITE);
dprint(1,20, C_BLACK, "(%d,%d)", character->x, character->y);
dprint(1,40, C_BLACK, "%s", character->name);
dprint(1,60, C_BLACK, "%s", character->dialog);
dupdate();
getkey();
}
struct character* get_character_xy(struct character *characters[], int x, int y) {

View File

@ -6,6 +6,7 @@
#include "player.h"
#include "animation.h"
#include "define.h"
#include "character.h"
#define TILESET_WIDTH 29
@ -130,4 +131,15 @@ int map_walkable(struct map const *map, int x, int y) {
void engine_set_background(struct game *game, int color) {
game->background = color;
}
void engine_action(struct game const *game, int action) {
if(action == ACTION_SHIFT) {
if(player_facing(game) == TILE_CHARACTER) {
int direction = game->player->direction;
int dx = (direction == DIR_RIGHT) - (direction == DIR_LEFT);
int dy = (direction == DIR_DOWN) - (direction == DIR_UP);
draw_dialog(get_character_xy(game->characters, game->player->x + dx, game->player->y + dy));
}
}
}

View File

@ -17,5 +17,6 @@ int get_inputs(void) {
if(key == KEY_RIGHT) return DIR_RIGHT;
if(key == KEY_UP) return DIR_UP;
if(key == KEY_LEFT) return DIR_LEFT;
if(key == KEY_SHIFT) return ACTION_SHIFT;
}
}

View File

@ -17,6 +17,7 @@ struct map *maps[] = {
};
extern struct character character_Tituya;
extern struct character character_Lephenixnoir;
struct character character_default = {
.x = 0,
@ -27,6 +28,7 @@ struct character character_default = {
struct character *characters[] = {
&character_Tituya,
&character_Lephenixnoir,
&character_default,
};
@ -50,6 +52,7 @@ int main(void) {
struct game game = {
.map = maps[0],
.player = &player,
.characters = characters,
.background = C_WHITE
};
@ -64,12 +67,15 @@ int main(void) {
tick = 0;
engine_draw(&game);
draw_dialog(get_character_xy(characters, 39, 30));
dprint(1,20,C_BLACK, "%d", player_facing(&game));
dupdate();
int dir = get_inputs();
if(dir >= 0)
engine_move(&game, dir);
int action = get_inputs();
if(action >= 0 && action <= 3)
engine_move(&game, action);
else if(action >= 4) {
engine_action(&game, action);
}
engine_tick(&game, ENGINE_TICK);
}