init main struct + remove unnecessary include

This commit is contained in:
bgiraudr 2021-08-27 02:11:05 +02:00
parent 39648a7353
commit f3dade60bf
19 changed files with 94 additions and 95 deletions

View File

@ -9,14 +9,13 @@ def convert(input, output, params, target):
return 1
def convert_map(input, output, params, target):
TILE_BRIDGE = -1 #only for bridge detection to avoid solid behind
TILE_AIR = 0
TILE_SOLID = 1
TILE_DOOR_IN = 2
TILE_DOOR_OUT = 3
TILE_TALKABLE = 4
TILE_BRIDGE = -1 #only for bridge detection to avoid solid behind
with open(input, "r") as jsonData:
data = json.load(jsonData)
@ -34,41 +33,37 @@ def convert_map(input, output, params, target):
tileset.close()
tile_value = {}
#create a dictionnary between tile id-type
#create a dictionnary {tile id:type}
for i in data_tileset["tiles"]:
try:
id = i["id"]+1
type = i["type"]
id = i["id"]+1
type = i["type"]
if type == "air":
value = TILE_AIR
elif type == "solid":
value = TILE_SOLID
elif type == "door_in":
value = TILE_DOOR_IN
elif type == "door_out":
value = TILE_DOOR_OUT
elif type == "talkable":
value = TILE_TALKABLE
elif type == "bridge":
value = TILE_BRIDGE
else:
value = TILE_AIR
if type == "air":
value = TILE_AIR
elif type == "solid":
value = TILE_SOLID
elif type == "door_in":
value = TILE_DOOR_IN
elif type == "door_out":
value = TILE_DOOR_OUT
elif type == "talkable":
value = TILE_TALKABLE
elif type == "bridge":
value = TILE_BRIDGE
else:
value = TILE_AIR
tile_value[id] = value
except KeyError:
pass
tile_value[id] = value
#Extract from the json the width, height and layers of the map
#Extract from the json the width, height
w, h = data["width"], data["height"]
indexObjectlayer = None
#nbTileLayer is the number of "true" layers (without ObjectsLayer)
nbTilelayer = len(data["layers"])
for i in range(nbTilelayer):
try:
data["layers"][i]["data"]
#nbTileLayer is the number of "true" layers (without ObjectsLayer)
nbTilelayer = i+1
except KeyError:
indexObjectlayer = i
@ -117,7 +112,7 @@ def convert_map(input, output, params, target):
info_map += fxconv.u16(maxValue)
maxValue = 0
bridge = False
structMap += fxconv.ref(info_map)
structMap += fxconv.ptr(info_map)
#generate the array of tiles from the layer
for i in range(nbTilelayer):
@ -126,7 +121,7 @@ def convert_map(input, output, params, target):
for tile in layer["data"]:
layer_data += fxconv.u16(tile)
structMap += fxconv.ref(layer_data)
structMap += fxconv.ptr(layer_data)
#generate !
fxconv.elf(structMap, output, "_" + params["name"], **target)

View File

@ -50,7 +50,8 @@
<object id="25" gid="267" x="112" y="112" width="16" height="16">
<properties>
<property name="name" value="Tituya"/>
<property name="text" value="Salutation !"/>
<property name="text">Salutation !
Ça va ?</property>
</properties>
</object>
</objectgroup>

View File

@ -1,4 +1,5 @@
#pragma once
/*the width of the tileset*/
#define TILESET_WIDTH 29
/*the size of one tile*/
#define TILE_SIZE 16
#define TILE_SIZE 16

View File

@ -12,9 +12,6 @@ struct Game {
int background;
};
/*get the input with a timeout*/
int get_inputs(void);
enum direction {
DIR_DOWN = 0,
DIR_LEFT = 1,
@ -23,3 +20,7 @@ enum direction {
ACTION_SHIFT = 4,
ACTION_ALPHA = 5
};
/*get the input with a timeout*/
int get_inputs(void);
struct Game init_game(struct Player *player);

View File

@ -1,6 +1,5 @@
#pragma once
#include <gint/display.h>
#include <stdbool.h>
#include "engine.h"
struct Map {

View File

@ -24,3 +24,4 @@ struct Player {
/*return the info tile value the player is facing to*/
int player_facing(struct Game const *game);
void set_player_xy(struct Player *player, int x, int y);
struct Player init_player(void);

View File

@ -1,5 +1,6 @@
#pragma once
#include "map.h"
struct Talkable {
/*the position of the tile*/
int x, y;

View File

@ -1,3 +1,4 @@
#pragma once
/*wait for a specified input key*/
void wait_for_input(int input);

View File

@ -10,10 +10,8 @@ struct Vec2f {
float y;
};
#define VEC2(x, y) \
(struct Vec2) { x, y }
#define VEC2F(x, y) \
(struct Vec2f) { x, y }
#define VEC2(x, y) (struct Vec2) { x, y }
#define VEC2F(x, y) (struct Vec2f) { x, y }
#define VEC2Z VEC2(0, 0)
#define VEC2FZ VEC2F(0.0, 0.0)

View File

@ -1,8 +1,8 @@
#include <gint/display.h>
#include <gint/defs/util.h>
#include "animation.h"
#include "engine.h"
#include "game.h"
struct Sheet
{

View File

@ -1,5 +1,4 @@
#include "vec2.h"
#include "define.h"
#include "camera.h"
struct Camera camera_new(struct Vec2f *target) {

View File

@ -1,5 +1,6 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include "engine.h"
#include "game.h"
#include "map.h"

View File

@ -1,7 +1,22 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include "game.h"
#include "player.h"
#include "map.h"
struct Game init_game(struct Player *player) {
extern struct Map *maps[];
struct Game game = {
.map = maps[0],
.player = player,
.camera = camera_new(&player->pos_visual),
.background = C_WHITE
};
return game;
}
/*get the input with a timeout*/
int get_inputs(void) {

View File

@ -1,21 +1,11 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include "game.h"
#include "map.h"
#include "engine.h"
#include "player.h"
#include "animation.h"
#include "camera.h"
#include "define.h"
#include <gint/timer.h>
#include <gint/clock.h>
extern struct Map map_1;
struct Map *maps[] = {
&map_1,
};
#include "game.h"
#include "engine.h"
#include "player.h"
static int callback_tick(volatile int *tick) {
*tick = 1;
@ -24,25 +14,8 @@ static int callback_tick(volatile int *tick) {
int main(void) {
/*Structure definition*/
struct Player player = {
.pos = VEC2(32, 30),
.pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE),
.x_mid = 6,
.y_mid = 1,
.show_x = 12,
.show_y = 7,
.direction = DIR_DOWN,
.anim.function = anim_player_idle,
.anim.dir = DIR_DOWN
};
player.idle = !anim_player_idle(&player.anim, 1);
struct Game game = {
.map = maps[0],
.player = &player,
.camera = camera_new(&player.pos_visual),
.background = C_WHITE
};
struct Player player = init_player();
struct Game game = init_game(&player);
/*Timer*/
static volatile int tick = 1;

View File

@ -1,9 +1,13 @@
#include "map.h"
#include "engine.h"
#include "player.h"
#include "camera.h"
#include "define.h"
extern struct Map map_1;
struct Map *maps[] = {
&map_1,
};
/*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];
@ -16,8 +20,10 @@ int map_get_player_tile(struct Game const *game) {
return game->map->info_map[game->player->pos.x + game->map->w * game->player->pos.y];
}
/*generate the interior*/
void generate_interior_map(struct Game *game) {
extern struct Map in_1;
game->map = &in_1;
set_player_xy(game->player, 3,3);
game->camera.pos.x = in_1.w/2 * TILE_SIZE + game->player->x_mid;

View File

@ -1,8 +1,23 @@
#include "player.h"
#include "define.h"
#include "engine.h"
#include "map.h"
#include "game.h"
struct Player init_player(void) {
struct Player player = {
.pos = VEC2(32, 30),
.pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE),
.x_mid = 6,
.y_mid = 1,
.show_x = 12,
.show_y = 7,
.direction = DIR_DOWN,
.anim.function = anim_player_idle,
.anim.dir = DIR_DOWN
};
player.idle = !anim_player_idle(&player.anim, 1);
return player;
}
/*
return the info tile value the player is facing to
@ -23,7 +38,6 @@ int player_facing(struct Game const *game) {
return TILE_SOLID;
}
/* lol */
void set_player_xy(struct Player *p, int x, int y) {
p->pos.x = x;
p->pos.y = y;

View File

@ -1,9 +1,8 @@
#include <gint/display.h>
#include <gint/keyboard.h>
#include <string.h>
#include "talkable.h"
#include "engine.h"
#include "map.h"
#include "util.h"
struct Talkable default_value = {

View File

@ -1,6 +1,8 @@
#include <gint/keyboard.h>
#include "util.h"
/*wait for a specified input key*/
void wait_for_input(int input) {
int buffer = 1;
while(1) {

View File

@ -1,42 +1,34 @@
#include "vec2.h"
struct Vec2 vec2_add(struct Vec2 v1, struct Vec2 v2)
{
struct Vec2 vec2_add(struct Vec2 v1, struct Vec2 v2) {
return VEC2(v1.x + v2.x, v1.y + v2.y);
}
struct Vec2f vec2f_add(struct Vec2f v1, struct Vec2f v2)
{
struct Vec2f vec2f_add(struct Vec2f v1, struct Vec2f v2) {
return VEC2F(v1.x + v2.x, v1.y + v2.y);
}
struct Vec2 vec2_sub(struct Vec2 v1, struct Vec2 v2)
{
struct Vec2 vec2_sub(struct Vec2 v1, struct Vec2 v2) {
return VEC2(v1.x - v2.x, v1.y - v2.y);
}
struct Vec2f vec2f_sub(struct Vec2f v1, struct Vec2f v2)
{
struct Vec2f vec2f_sub(struct Vec2f v1, struct Vec2f v2) {
return VEC2F(v1.x - v2.x, v1.y - v2.y);
}
struct Vec2 vec2_mul(struct Vec2 v, int scale)
{
struct Vec2 vec2_mul(struct Vec2 v, int scale) {
return VEC2(v.x * scale, v.y * scale);
}
struct Vec2f vec2f_mul(struct Vec2f v, int scale)
{
struct Vec2f vec2f_mul(struct Vec2f v, int scale) {
return VEC2F(v.x * scale, v.y * scale);
}
struct Vec2 vec2f_vec2(struct Vec2f v)
{
struct Vec2 vec2f_vec2(struct Vec2f v) {
return VEC2(v.x, v.y);
}
struct Vec2f vec2_vec2f(struct Vec2 v)
{
struct Vec2f vec2_vec2f(struct Vec2 v) {
return VEC2F(v.x, v.y);
}