diff --git a/.gitignore b/.gitignore index f8118b0..e0ea0c7 100644 --- a/.gitignore +++ b/.gitignore @@ -4,9 +4,10 @@ /*.g1a /*.g3a *.json +*~ # Python bytecode - __pycache__/ +__pycache__/ # Common IDE files *.sublime-project diff --git a/CMakeLists.txt b/CMakeLists.txt index f3aa301..a060e14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/engine.h b/include/engine.h index fe394ce..806d0c6 100644 --- a/include/engine.h +++ b/include/engine.h @@ -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); \ No newline at end of file +void engine_set_background(struct game *game, int color); +void engine_action(struct game const *game, int action); \ No newline at end of file diff --git a/include/game.h b/include/game.h index b6a05af..12ab34b 100644 --- a/include/game.h +++ b/include/game.h @@ -1,4 +1,12 @@ #pragma once void play(); -int get_inputs(void); \ No newline at end of file +int get_inputs(void); + +enum direction { + DIR_DOWN = 0, + DIR_LEFT = 1, + DIR_UP = 2, + DIR_RIGHT = 3, + ACTION_SHIFT = 4 +}; \ No newline at end of file diff --git a/include/player.h b/include/player.h index ecb2a20..7c6615b 100644 --- a/include/player.h +++ b/include/player.h @@ -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 -}; \ No newline at end of file +int player_facing(struct game const *game); \ No newline at end of file diff --git a/src/animation.c b/src/animation.c index ca66f6b..098a626 100644 --- a/src/animation.c +++ b/src/animation.c @@ -2,7 +2,7 @@ #include #include "animation.h" #include "engine.h" -#include "player.h" +#include "game.h" struct sheet { diff --git a/src/character.c b/src/character.c index 07d2232..7b628d0 100644 --- a/src/character.c +++ b/src/character.c @@ -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) { diff --git a/src/engine.c b/src/engine.c index 9cd1bef..417e71c 100644 --- a/src/engine.c +++ b/src/engine.c @@ -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)); + } + } } \ No newline at end of file diff --git a/src/game.c b/src/game.c index 43c0029..c31c48a 100644 --- a/src/game.c +++ b/src/game.c @@ -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; } } \ No newline at end of file diff --git a/src/main.c b/src/main.c index 570df92..5c907ad 100644 --- a/src/main.c +++ b/src/main.c @@ -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); }