mirror of https://github.com/bgiraudr/Adoranda.git
PascalCase struct names
This commit is contained in:
parent
a8edfa9091
commit
512adabfda
|
@ -1,13 +1,13 @@
|
|||
#pragma once
|
||||
#include <gint/display.h>
|
||||
|
||||
struct anim_data;
|
||||
struct AnimData;
|
||||
|
||||
typedef int (anim_function_t)(struct anim_data *data, int init);
|
||||
typedef int (anim_function_t)(struct AnimData *data, int init);
|
||||
anim_function_t anim_player_walking;
|
||||
anim_function_t anim_player_idle;
|
||||
|
||||
struct anim_frame
|
||||
struct AnimFrame
|
||||
{
|
||||
/*the image*/
|
||||
bopti_image_t *source;
|
||||
|
@ -17,12 +17,12 @@ struct anim_frame
|
|||
int w, h;
|
||||
};
|
||||
|
||||
struct anim_data
|
||||
struct AnimData
|
||||
{
|
||||
/*the function to call to update the frame*/
|
||||
anim_function_t *function;
|
||||
/*the anim frame*/
|
||||
struct anim_frame img;
|
||||
struct AnimFrame img;
|
||||
/*if the animation needs to move*/
|
||||
int dx, dy;
|
||||
/*the direction*/
|
||||
|
@ -34,8 +34,8 @@ struct anim_data
|
|||
};
|
||||
|
||||
/*draw the frame*/
|
||||
void dframe(int x, int y, struct anim_frame const frame);
|
||||
void dframe(int x, int y, struct AnimFrame const frame);
|
||||
/*animation for player walking*/
|
||||
int anim_player_walking(struct anim_data *data, int init);
|
||||
int anim_player_walking(struct AnimData *data, int init);
|
||||
/*animation for player doing nothing*/
|
||||
int anim_player_idle(struct anim_data *data, int init);
|
||||
int anim_player_idle(struct AnimData *data, int init);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
struct character {
|
||||
struct Character {
|
||||
/*the position of the character*/
|
||||
int x, y;
|
||||
/*the name*/
|
||||
|
@ -10,8 +10,8 @@ struct character {
|
|||
};
|
||||
|
||||
/*draw the dialog of a specified character*/
|
||||
void draw_dialog(struct character *character);
|
||||
void draw_dialog(struct Character *character);
|
||||
/*find the character using the player's position*/
|
||||
struct character* get_character_xy(struct character *characters[], int x, int y);
|
||||
struct Character* get_character_xy(struct Character *characters[], int x, int y);
|
||||
/*get the characters for a specified map*/
|
||||
struct character** get_map_characters(int id);
|
||||
struct Character** get_map_characters(int id);
|
||||
|
|
|
@ -2,30 +2,30 @@
|
|||
|
||||
#define ENGINE_TICK 35
|
||||
|
||||
struct game {
|
||||
struct Game {
|
||||
/*the current map to display*/
|
||||
struct map *map;
|
||||
struct Map *map;
|
||||
/*the player*/
|
||||
struct player *player;
|
||||
struct Player *player;
|
||||
/*list of all the characters on the map*/
|
||||
struct character **characters;
|
||||
struct Character **characters;
|
||||
/*the background color*/
|
||||
int background;
|
||||
};
|
||||
|
||||
/*draw the current state of the game*/
|
||||
void engine_draw(struct game const *game);
|
||||
void engine_draw(struct Game const *game);
|
||||
/*draw the map around the player*/
|
||||
void engine_draw_map_around_player(struct game const *game);
|
||||
void engine_draw_map_around_player(struct Game const *game);
|
||||
/*draw the player*/
|
||||
void engine_draw_player(struct player const *player);
|
||||
void engine_draw_player(struct Player const *player);
|
||||
/*move the player to the direction*/
|
||||
int engine_move(struct game *game, int direction);
|
||||
int engine_move(struct Game *game, int direction);
|
||||
/*update the player animation*/
|
||||
void engine_tick(struct game *game, int dt);
|
||||
void engine_tick(struct Game *game, int dt);
|
||||
/*set the background color*/
|
||||
void engine_set_background(struct game *game, int color);
|
||||
void engine_set_background(struct Game *game, int color);
|
||||
/*make an interaction with something*/
|
||||
void engine_action(struct game const *game, int action);
|
||||
void engine_action(struct Game const *game, int action);
|
||||
/*check the current position of the player. To perform action depends of his location*/
|
||||
void engine_check_position(struct game *game);
|
||||
void engine_check_position(struct Game *game);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <gint/display.h>
|
||||
#include "engine.h"
|
||||
|
||||
struct map {
|
||||
struct Map {
|
||||
/*width, height and the number of layer of the map (max 2)*/
|
||||
int w, h, nb_layer;
|
||||
/*the tileset to use*/
|
||||
|
@ -24,6 +24,6 @@ enum map_state {
|
|||
};
|
||||
|
||||
/*check if a tile is walkable*/
|
||||
int map_walkable(struct map const *map, int x, int y);
|
||||
int map_walkable(struct Map const *map, int x, int y);
|
||||
/*get the tile under the player*/
|
||||
int map_get_player_tile(struct game const *game);
|
||||
int map_get_player_tile(struct Game const *game);
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "animation.h"
|
||||
#include "engine.h"
|
||||
|
||||
struct player {
|
||||
struct Player {
|
||||
/*current position of the player on the map*/
|
||||
int x, y;
|
||||
/*the direction the player facing to*/
|
||||
|
@ -14,8 +14,8 @@ struct player {
|
|||
int show_x, show_y;
|
||||
/*the current animation*/
|
||||
int idle;
|
||||
struct anim_data anim;
|
||||
struct AnimData anim;
|
||||
};
|
||||
|
||||
/*return the info tile value the player is facing to*/
|
||||
int player_facing(struct game const *game);
|
||||
int player_facing(struct Game const *game);
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "engine.h"
|
||||
#include "game.h"
|
||||
|
||||
struct sheet
|
||||
struct Sheet
|
||||
{
|
||||
/*the sheet image of the animation*/
|
||||
bopti_image_t *img;
|
||||
|
@ -15,14 +15,14 @@ struct sheet
|
|||
};
|
||||
|
||||
extern bopti_image_t img_spritesheet;
|
||||
struct sheet const anim_player = {
|
||||
struct Sheet const anim_player = {
|
||||
.img = &img_spritesheet,
|
||||
.frame_w = 16,
|
||||
.frame_h = 21,
|
||||
};
|
||||
|
||||
static struct anim_frame anim_frame(struct sheet const *sheet, int col, int row) {
|
||||
struct anim_frame f = {
|
||||
static struct AnimFrame anim_frame(struct Sheet const *sheet, int col, int row) {
|
||||
struct AnimFrame f = {
|
||||
.source = sheet->img,
|
||||
.left = sheet->frame_w * col,
|
||||
.top = sheet->frame_h * row,
|
||||
|
@ -33,13 +33,13 @@ static struct anim_frame anim_frame(struct sheet const *sheet, int col, int row)
|
|||
}
|
||||
|
||||
/*draw the frame*/
|
||||
void dframe(int x, int y, struct anim_frame const frame) {
|
||||
void dframe(int x, int y, struct AnimFrame const frame) {
|
||||
dsubimage(x, y, frame.source, frame.left, frame.top, frame.w, frame.h,
|
||||
DIMAGE_NONE);
|
||||
}
|
||||
|
||||
/*animation for player walking*/
|
||||
int anim_player_walking(struct anim_data *data, int init) {
|
||||
int anim_player_walking(struct AnimData *data, int init) {
|
||||
if(init) {
|
||||
data->function = anim_player_walking;
|
||||
data->frame = 0;
|
||||
|
@ -66,7 +66,7 @@ int anim_player_walking(struct anim_data *data, int init) {
|
|||
}
|
||||
|
||||
/*animation for player doing nothing*/
|
||||
int anim_player_idle(struct anim_data *data, int init) {
|
||||
int anim_player_idle(struct AnimData *data, int init) {
|
||||
if(init) {
|
||||
data->function = anim_player_idle;
|
||||
data->frame = 0;
|
||||
|
@ -80,4 +80,4 @@ int anim_player_idle(struct anim_data *data, int init) {
|
|||
data->dy = 0;
|
||||
data->img = anim_frame(&anim_player, data->dir, data->frame);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
#include "engine.h"
|
||||
#include "map.h"
|
||||
|
||||
struct character character_default = {
|
||||
struct Character character_default = {
|
||||
.x = 0,
|
||||
.y = 0,
|
||||
.name = "default name",
|
||||
|
@ -13,7 +13,7 @@ struct character character_default = {
|
|||
};
|
||||
|
||||
/*draw the dialog of a specified character*/
|
||||
void draw_dialog(struct character *character) {
|
||||
void draw_dialog(struct Character *character) {
|
||||
drect(20,10,370,80,C_WHITE);
|
||||
dprint(25,20, C_BLACK, "(%d,%d)", character->x, character->y);
|
||||
dprint(25,40, C_BLACK, "%s", character->name);
|
||||
|
@ -31,7 +31,7 @@ void draw_dialog(struct character *character) {
|
|||
}
|
||||
|
||||
/*find the character using the player's position*/
|
||||
struct character* get_character_xy(struct character *characters[], int x, int y) {
|
||||
struct Character* get_character_xy(struct Character *characters[], int x, int y) {
|
||||
int i = 0;
|
||||
while(strcmp(characters[i]->name,"default name") != 0) {
|
||||
if(characters[i]->x == x && characters[i]->y == y) return characters[i];
|
||||
|
@ -41,16 +41,16 @@ struct character* get_character_xy(struct character *characters[], int x, int y)
|
|||
}
|
||||
|
||||
/*get the characters for a specified map*/
|
||||
struct character** get_map_characters(int id) {
|
||||
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;
|
||||
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[] = {
|
||||
static struct Character *characters[] = {
|
||||
&character_Tituya,
|
||||
&character_Lephenixnoir,
|
||||
&character_Massena,
|
||||
|
@ -61,6 +61,6 @@ struct character** get_map_characters(int id) {
|
|||
};
|
||||
return characters;
|
||||
}
|
||||
static struct character *characters[] = {};
|
||||
static struct Character *characters[] = {};
|
||||
return characters;
|
||||
}
|
||||
}
|
||||
|
|
18
src/engine.c
18
src/engine.c
|
@ -9,14 +9,14 @@
|
|||
#include "character.h"
|
||||
|
||||
/*draw the current state of the game*/
|
||||
void engine_draw(struct game const *game) {
|
||||
void engine_draw(struct Game const *game) {
|
||||
dclear(game->background);
|
||||
engine_draw_map_around_player(game);
|
||||
engine_draw_player(game->player);
|
||||
}
|
||||
|
||||
/*draw the map around the player*/
|
||||
void engine_draw_map_around_player(struct game const *game) {
|
||||
void engine_draw_map_around_player(struct Game const *game) {
|
||||
const int level_width = game->map->w;
|
||||
const int taillemap = game->map->w * game->map->h;
|
||||
const int posx = game->player->show_x;
|
||||
|
@ -90,13 +90,13 @@ void engine_draw_map_around_player(struct game const *game) {
|
|||
}
|
||||
|
||||
/*draw the player*/
|
||||
void engine_draw_player(struct player const *player) {
|
||||
void engine_draw_player(struct Player const *player) {
|
||||
dframe(player->show_x * 16, player->show_y * 16 - 5, player->anim.img); //draw the player 5 pixel up
|
||||
dprint(1,1,C_BLACK,"%d:%d",player->x, player->y);
|
||||
}
|
||||
|
||||
/*move the player to the direction*/
|
||||
int engine_move(struct game *game, int direction) {
|
||||
int engine_move(struct Game *game, int direction) {
|
||||
int dx = (direction == DIR_RIGHT) - (direction == DIR_LEFT);
|
||||
int dy = (direction == DIR_DOWN) - (direction == DIR_UP);
|
||||
|
||||
|
@ -119,7 +119,7 @@ int engine_move(struct game *game, int direction) {
|
|||
}
|
||||
|
||||
/*update the player animation*/
|
||||
void engine_tick(struct game *game, int dt) {
|
||||
void engine_tick(struct Game *game, int dt) {
|
||||
game->player->anim.duration -= dt;
|
||||
|
||||
if(game->player->anim.duration <= 0) {
|
||||
|
@ -128,12 +128,12 @@ void engine_tick(struct game *game, int dt) {
|
|||
}
|
||||
|
||||
/*set the background color*/
|
||||
void engine_set_background(struct game *game, int color) {
|
||||
void engine_set_background(struct Game *game, int color) {
|
||||
game->background = color;
|
||||
}
|
||||
|
||||
/*make an interaction with something*/
|
||||
void engine_action(struct game const *game, int action) {
|
||||
void engine_action(struct Game const *game, int action) {
|
||||
if(action == ACTION_SHIFT) {
|
||||
if(player_facing(game) == TILE_CHARACTER) {
|
||||
int direction = game->player->direction;
|
||||
|
@ -145,11 +145,11 @@ void engine_action(struct game const *game, int action) {
|
|||
}
|
||||
|
||||
/*check the current position of the player. To perform action depends of his location*/
|
||||
void engine_check_position(struct game *game) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,4 +24,4 @@ int get_inputs(void) {
|
|||
if(key == KEY_SHIFT) return ACTION_SHIFT;
|
||||
if(key == KEY_ALPHA) return ACTION_ALPHA;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
src/main.c
10
src/main.c
|
@ -10,9 +10,9 @@
|
|||
#include <gint/timer.h>
|
||||
#include <gint/clock.h>
|
||||
|
||||
extern struct map map_1;
|
||||
extern struct Map map_1;
|
||||
|
||||
struct map *maps[] = {
|
||||
struct Map *maps[] = {
|
||||
&map_1,
|
||||
};
|
||||
|
||||
|
@ -23,7 +23,7 @@ static int callback_tick(volatile int *tick) {
|
|||
|
||||
int main(void) {
|
||||
/*Structure definition*/
|
||||
struct player player = {
|
||||
struct Player player = {
|
||||
.x = 32,
|
||||
.y = 30,
|
||||
.show_x = 12,
|
||||
|
@ -34,7 +34,7 @@ int main(void) {
|
|||
};
|
||||
player.idle = !anim_player_idle(&player.anim, 1);
|
||||
|
||||
struct game game = {
|
||||
struct Game game = {
|
||||
.map = maps[0],
|
||||
.player = &player,
|
||||
.background = C_WHITE
|
||||
|
@ -67,4 +67,4 @@ int main(void) {
|
|||
|
||||
if(t >= 0) timer_stop(t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,13 +3,13 @@
|
|||
#include "player.h"
|
||||
|
||||
/*check if a tile is walkable*/
|
||||
int map_walkable(struct map const *map, int x, int y) {
|
||||
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);
|
||||
}
|
||||
|
||||
/*get the tile under the player*/
|
||||
int map_get_player_tile(struct game const *game) {
|
||||
int map_get_player_tile(struct Game const *game) {
|
||||
return game->map->info_map[game->player->x + game->map->w * game->player->y];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
return the info tile value the player is facing to
|
||||
TILE_SOLID by default (out of bound)
|
||||
*/
|
||||
int player_facing(struct game const *game) {
|
||||
int player_facing(struct Game const *game) {
|
||||
int direction = game->player->direction;
|
||||
int dx = (direction == DIR_RIGHT) - (direction == DIR_LEFT);
|
||||
int dy = (direction == DIR_DOWN) - (direction == DIR_UP);
|
||||
|
@ -20,4 +20,4 @@ int player_facing(struct game const *game) {
|
|||
return game->map->info_map[index];
|
||||
}
|
||||
return TILE_SOLID;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue