first map displayed

This commit is contained in:
Shadow15510 2021-08-17 22:14:09 +02:00
parent 69da392400
commit a5c35c6f2b
13 changed files with 236 additions and 8 deletions

3
.gitignore vendored
View File

@ -5,3 +5,6 @@
# Building sources
build-fx/
build-cg/
# Python files
assets-cg/__pycache__/

View File

@ -11,6 +11,7 @@ find_package(Gint 2.1 REQUIRED)
set(SOURCES
src/main.c
src/game_engine.c
# ...
)
# Shared assets, fx-9860G-only assets and fx-CG-50-only assets
@ -20,9 +21,13 @@ set(ASSETS
set(ASSETS_fx
)
set(ASSETS_cg
assets-cg/tileset.png
assets-cg/maps/world.json
)
fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} WITH_METADATA)
fxconv_declare_converters(assets-cg/converters.py)
add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}})
target_compile_options(myaddin PRIVATE -Wall -Wextra -Os)

65
assets-cg/Tiled/carte.tmx Normal file
View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="25" height="25" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="1">
<editorsettings>
<export target="../maps/world.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="tileset.json"/>
<layer id="1" name="Calque de Tuiles 1" width="25" height="25">
<data encoding="csv">
55,55,55,6,55,55,6,6,55,6,59,6,55,6,6,55,55,6,55,6,55,55,6,55,6,
55,6,55,55,6,55,6,59,59,55,55,6,6,6,6,6,55,55,55,6,6,55,6,6,6,
6,6,6,55,6,6,55,55,6,6,55,55,59,55,6,55,6,55,6,6,6,59,6,55,6,
55,6,6,6,59,55,6,3,4,4,4,5,55,55,59,55,55,59,55,6,6,6,55,55,6,
55,55,6,6,55,3,4,100,1076,53,53,54,55,6,55,6,55,55,6,55,55,55,6,6,6,
6,55,6,59,6,52,53,53,53,53,53,99,5,6,6,55,55,55,55,55,55,55,6,55,6,
55,6,6,6,6,101,51,53,53,53,53,53,54,55,55,55,55,55,6,6,59,55,6,6,55,
6,55,6,55,55,55,52,53,53,1078,50,102,103,55,55,55,59,6,6,55,6,55,55,6,6,
55,55,59,6,55,55,101,102,102,102,103,55,6,6,55,6,6,55,6,6,55,55,6,55,6,
55,55,55,55,59,55,55,55,55,6,6,6,6,55,59,6,55,6,6,6,55,55,6,6,55,
55,6,55,6,6,6,6,6,6,55,6,6,6,6,55,6,55,6,6,55,6,6,55,55,55,
55,6,59,55,55,55,6,55,6,6,6,55,6,55,6,55,6,55,55,55,6,6,55,55,55,
55,55,55,55,59,6,6,55,55,55,55,55,55,55,6,6,6,59,55,6,55,6,55,55,6,
6,55,55,55,55,6,6,6,6,55,55,59,6,55,55,55,55,6,55,55,59,6,6,55,55,
55,55,59,55,55,6,55,59,6,6,6,6,6,55,6,55,6,6,6,6,6,6,55,55,55,
6,55,55,55,6,55,55,6,55,55,6,55,55,6,6,6,55,55,55,6,6,55,6,6,6,
55,6,55,55,59,6,6,55,59,6,6,6,6,55,59,55,6,55,6,55,55,6,55,55,6,
6,55,55,6,6,6,6,55,55,6,6,55,55,6,55,6,6,6,6,55,55,6,55,6,55,
6,6,55,6,6,6,6,6,6,55,59,55,55,6,6,55,55,6,55,55,6,6,55,6,55,
6,55,6,6,6,55,55,6,55,55,55,6,6,55,913,914,914,915,55,6,55,55,6,6,55,
55,55,6,55,55,59,6,55,55,6,55,6,6,6,962,963,963,964,55,6,55,55,6,6,55,
6,55,6,6,6,6,55,6,55,55,55,55,6,6,1011,1012,1012,1013,55,55,55,55,6,55,6,
55,6,55,55,6,55,6,55,6,55,6,6,6,6,55,6,55,55,55,6,55,55,6,6,55,
6,55,6,55,6,55,55,55,55,6,55,6,6,6,6,55,55,6,55,6,6,6,55,55,55,
55,55,6,55,55,55,55,6,6,55,6,55,55,55,55,55,55,6,6,55,55,55,55,55,55
</data>
</layer>
<layer id="2" name="Calque de Tuiles 2" width="25" height="25">
<data encoding="csv">
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,514,738,739,739,739,739,739,739,739,739,739,739,740,514,0,289,0,0,0,0,0,0,0,
0,0,563,787,736,837,837,837,837,837,837,837,837,737,789,563,0,0,0,0,0,0,0,0,0,
0,0,0,787,789,0,0,0,0,0,0,0,0,787,789,0,0,0,0,0,289,0,0,0,0,
0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,0,0,0,0,0,0,
0,0,563,787,789,0,0,0,0,0,0,0,0,787,789,563,0,0,0,0,0,0,0,0,0,
0,0,0,787,789,0,0,0,0,0,0,0,0,787,789,0,0,0,0,0,0,0,0,0,0,
0,0,514,787,789,0,0,0,0,0,0,0,0,787,789,514,0,0,0,291,292,532,0,0,0,
0,0,563,787,789,0,0,0,0,0,0,0,0,787,789,563,0,514,0,340,341,532,532,0,0,
0,0,0,787,785,739,739,739,739,739,739,739,739,786,789,0,0,563,313,0,0,0,0,0,0,
0,0,514,836,837,837,837,837,837,837,837,837,837,837,838,514,0,0,0,406,0,359,359,0,0,
0,0,563,0,0,0,0,0,0,0,0,0,0,0,0,563,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,514,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,563,0,0,0,514,0,0,0,0,0,514,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,563,0,0,0,0,0,563,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,514,0,0,0,0,0,0,0,0,0,0,0,909,761,761,910,0,0,0,0,0,0,0,
0,0,563,0,0,0,0,0,0,0,1023,1020,1020,1020,958,761,761,959,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1024,0,0,1007,960,960,1008,0,0,0,16,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1024,0,0,0,383,0,0,0,60,60,109,0,0,0,
0,0,0,0,0,0,0,0,0,0,1023,1019,1020,1020,0,33,0,383,20,256,256,305,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,934,936,0,0,0,0,0,0,0,0,
0,885,886,886,886,886,886,886,886,886,886,886,886,886,886,933,936,0,0,0,0,0,0,0,0,
0,983,984,984,984,984,984,984,984,984,984,984,984,984,984,984,985,0,0,0,0,0,0,0,0
</data>
</layer>
</map>

View File

@ -0,0 +1,14 @@
{ "columns":49,
"image":"..\/tileset.png",
"imageheight":373,
"imagewidth":832,
"margin":0,
"name":"tileset",
"spacing":1,
"tilecount":1078,
"tiledversion":"1.7.1",
"tileheight":16,
"tilewidth":16,
"type":"tileset",
"version":"1.6"
}

33
assets-cg/converters.py Normal file
View File

@ -0,0 +1,33 @@
import fxconv
import json
def convert(input_name, output, params, target):
if params["custom-type"] == "map":
convert_map(input_name, output, params, target)
return 0
else:
return 1
def convert_map(input_name, output, params, target):
with open(input_name, "r") as file:
json_data = json.load(file)
data = fxconv.ObjectData()
data += fxconv.u32(json_data["width"]) + fxconv.u32(json_data["height"]) + fxconv.u32(len(json_data["layers"]))
for layer in json_data["layers"]:
layer_data = bytes()
for tile in layer["data"]:
layer_data += fxconv.u16(tile)
data += fxconv.ref(layer_data)
fxconv.elf(data, output, "_" + params["name"], **target)

View File

@ -1,4 +1,4 @@
*.png:
type: bopti-image
profile: p8
name_regex: (*)\.png img_\1
name_regex: (.*)\.png img_\1

View File

@ -0,0 +1,3 @@
*.json:
custom-type: map
name_regex: (.*)\.json map_\1

44
assets-cg/maps/world.json Normal file
View File

@ -0,0 +1,44 @@
{ "compressionlevel":-1,
"height":25,
"infinite":false,
"layers":[
{
"data":[55, 55, 55, 6, 55, 55, 6, 6, 55, 6, 59, 6, 55, 6, 6, 55, 55, 6, 55, 6, 55, 55, 6, 55, 6, 55, 6, 55, 55, 6, 55, 6, 59, 59, 55, 55, 6, 6, 6, 6, 6, 55, 55, 55, 6, 6, 55, 6, 6, 6, 6, 6, 6, 55, 6, 6, 55, 55, 6, 6, 55, 55, 59, 55, 6, 55, 6, 55, 6, 6, 6, 59, 6, 55, 6, 55, 6, 6, 6, 59, 55, 6, 3, 4, 4, 4, 5, 55, 55, 59, 55, 55, 59, 55, 6, 6, 6, 55, 55, 6, 55, 55, 6, 6, 55, 3, 4, 100, 1076, 53, 53, 54, 55, 6, 55, 6, 55, 55, 6, 55, 55, 55, 6, 6, 6, 6, 55, 6, 59, 6, 52, 53, 53, 53, 53, 53, 99, 5, 6, 6, 55, 55, 55, 55, 55, 55, 55, 6, 55, 6, 55, 6, 6, 6, 6, 101, 51, 53, 53, 53, 53, 53, 54, 55, 55, 55, 55, 55, 6, 6, 59, 55, 6, 6, 55, 6, 55, 6, 55, 55, 55, 52, 53, 53, 1078, 50, 102, 103, 55, 55, 55, 59, 6, 6, 55, 6, 55, 55, 6, 6, 55, 55, 59, 6, 55, 55, 101, 102, 102, 102, 103, 55, 6, 6, 55, 6, 6, 55, 6, 6, 55, 55, 6, 55, 6, 55, 55, 55, 55, 59, 55, 55, 55, 55, 6, 6, 6, 6, 55, 59, 6, 55, 6, 6, 6, 55, 55, 6, 6, 55, 55, 6, 55, 6, 6, 6, 6, 6, 6, 55, 6, 6, 6, 6, 55, 6, 55, 6, 6, 55, 6, 6, 55, 55, 55, 55, 6, 59, 55, 55, 55, 6, 55, 6, 6, 6, 55, 6, 55, 6, 55, 6, 55, 55, 55, 6, 6, 55, 55, 55, 55, 55, 55, 55, 59, 6, 6, 55, 55, 55, 55, 55, 55, 55, 6, 6, 6, 59, 55, 6, 55, 6, 55, 55, 6, 6, 55, 55, 55, 55, 6, 6, 6, 6, 55, 55, 59, 6, 55, 55, 55, 55, 6, 55, 55, 59, 6, 6, 55, 55, 55, 55, 59, 55, 55, 6, 55, 59, 6, 6, 6, 6, 6, 55, 6, 55, 6, 6, 6, 6, 6, 6, 55, 55, 55, 6, 55, 55, 55, 6, 55, 55, 6, 55, 55, 6, 55, 55, 6, 6, 6, 55, 55, 55, 6, 6, 55, 6, 6, 6, 55, 6, 55, 55, 59, 6, 6, 55, 59, 6, 6, 6, 6, 55, 59, 55, 6, 55, 6, 55, 55, 6, 55, 55, 6, 6, 55, 55, 6, 6, 6, 6, 55, 55, 6, 6, 55, 55, 6, 55, 6, 6, 6, 6, 55, 55, 6, 55, 6, 55, 6, 6, 55, 6, 6, 6, 6, 6, 6, 55, 59, 55, 55, 6, 6, 55, 55, 6, 55, 55, 6, 6, 55, 6, 55, 6, 55, 6, 6, 6, 55, 55, 6, 55, 55, 55, 6, 6, 55, 913, 914, 914, 915, 55, 6, 55, 55, 6, 6, 55, 55, 55, 6, 55, 55, 59, 6, 55, 55, 6, 55, 6, 6, 6, 962, 963, 963, 964, 55, 6, 55, 55, 6, 6, 55, 6, 55, 6, 6, 6, 6, 55, 6, 55, 55, 55, 55, 6, 6, 1011, 1012, 1012, 1013, 55, 55, 55, 55, 6, 55, 6, 55, 6, 55, 55, 6, 55, 6, 55, 6, 55, 6, 6, 6, 6, 55, 6, 55, 55, 55, 6, 55, 55, 6, 6, 55, 6, 55, 6, 55, 6, 55, 55, 55, 55, 6, 55, 6, 6, 6, 6, 55, 55, 6, 55, 6, 6, 6, 55, 55, 55, 55, 55, 6, 55, 55, 55, 55, 6, 6, 55, 6, 55, 55, 55, 55, 55, 55, 6, 6, 55, 55, 55, 55, 55, 55],
"height":25,
"id":1,
"name":"Calque de Tuiles 1",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":25,
"x":0,
"y":0
},
{
"data":[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 738, 739, 739, 739, 739, 739, 739, 739, 739, 739, 739, 740, 514, 0, 289, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 736, 837, 837, 837, 837, 837, 837, 837, 837, 737, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 289, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 514, 0, 0, 0, 291, 292, 532, 0, 0, 0, 0, 0, 563, 787, 789, 0, 0, 0, 0, 0, 0, 0, 0, 787, 789, 563, 0, 514, 0, 340, 341, 532, 532, 0, 0, 0, 0, 0, 787, 785, 739, 739, 739, 739, 739, 739, 739, 739, 786, 789, 0, 0, 563, 313, 0, 0, 0, 0, 0, 0, 0, 0, 514, 836, 837, 837, 837, 837, 837, 837, 837, 837, 837, 837, 838, 514, 0, 0, 0, 406, 0, 359, 359, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 514, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 514, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 909, 761, 761, 910, 0, 0, 0, 0, 0, 0, 0, 0, 0, 563, 0, 0, 0, 0, 0, 0, 0, 1023, 1020, 1020, 1020, 958, 761, 761, 959, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 1007, 960, 960, 1008, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1024, 0, 0, 0, 383, 0, 0, 0, 60, 60, 109, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1023, 1019, 1020, 1020, 0, 33, 0, 383, 20, 256, 256, 305, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 934, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 885, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 886, 933, 936, 0, 0, 0, 0, 0, 0, 0, 0, 0, 983, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 984, 985, 0, 0, 0, 0, 0, 0, 0, 0],
"height":25,
"id":2,
"name":"Calque de Tuiles 2",
"opacity":1,
"type":"tilelayer",
"visible":true,
"width":25,
"x":0,
"y":0
}],
"nextlayerid":3,
"nextobjectid":1,
"orientation":"orthogonal",
"renderorder":"right-down",
"tiledversion":"1.7.2",
"tileheight":16,
"tilesets":[
{
"firstgid":1,
"source":"..\/Tiled\/tileset.json"
}],
"tilewidth":16,
"type":"map",
"version":"1.6",
"width":25
}

1
src/display_engine.c Normal file
View File

@ -0,0 +1 @@
#include "display_engine.h"

5
src/display_engine.h Normal file
View File

@ -0,0 +1,5 @@
#ifndef _DISPLAY_ENGINE_H
#define _DISPLAY_ENGINE_H
#endif /* _DISPLAY_ENGINE_H */

3
src/game_engine.c Normal file
View File

@ -0,0 +1,3 @@
#include "game_engine.h"

14
src/game_engine.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef _GAME_ENGINE_H
#define _GAME_ENGINE_H
#include <gint/keyboard.h>
struct map
{
int width, height, nb_layers;
// to get a cell : layers[layer_number][y*width+x]
uint16_t *layers[];
};
#endif /* _GAME_ENGINE_H */

View File

@ -1,12 +1,50 @@
#include <gint/display.h>
/*
Name : Odyssée Game Engine
Version : dev
code provided with licence :
GNU General Public Licence v3.0
*/
#include <gint/keyboard.h>
#include <gint/display.h>
#include "game_engine.h"
#define TILE_SIZE 16
#define TILESET_WIDTH 49
#define SCREEN_WIDTH 24
#define SCREEN_HEIGHT 14
int main(void)
{
dclear(C_WHITE);
dtext(1, 1, C_BLACK, "Sample fxSDK add-in.");
dupdate();
extern const struct map map_world;
extern const bopti_image_t img_tileset;
getkey();
return 1;
}
dclear(C_WHITE);
for (int layer = 0 ; layer < map_world.nb_layers; layer++)
{
for (int y = 0 ; y <= SCREEN_HEIGHT; y ++)
{
for (int x = 0 ; x <= SCREEN_WIDTH; x ++)
{
unsigned int tile_id = map_world.layers[layer][y * map_world.width + x];
if (tile_id != 0)
{
tile_id --;
unsigned int tile_x = (TILE_SIZE + 1) * (tile_id % TILESET_WIDTH);
unsigned int tile_y = (TILE_SIZE + 1) * (tile_id / TILESET_WIDTH);
dsubimage(x * TILE_SIZE, y * TILE_SIZE, &img_tileset, tile_x, tile_y, TILE_SIZE, TILE_SIZE, DIMAGE_NONE);
}
}
}
}
// dprint(2, 2, C_BLACK, "%d", map_world.layers[0][0]);
dupdate();
getkey();
return 0;
}