diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b2875c..1ce4118 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,10 +51,11 @@ set(SOURCES ) # Shared assets, fx-9860G-only assets and fx-CG-50-only assets set(ASSETS - assets/level0.json - assets/level1.json - assets/level2.json - assets/level3.json + #assets/level0.json + #assets/level1.json + #assets/level2.json + #assets/level3.json + assets/WorldRPG.world # ... ) @@ -89,7 +90,7 @@ set(ASSETS_fx_2b # ... ) -fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} ${ASSETS_fx_1b} ${ASSETS_fx_2b} ${ASSETS_cg_2b} ${ASSETS_cg_EGA64} WITH_METADATA) +fxconv_declare_assets(${ASSETS} ${ASSETS_fx} ${ASSETS_cg} ${ASSETS_fx_1b} ${ASSETS_fx_2b} ${ASSETS_cg_2b} ${ASSETS_cg_EGA64} WITH_METADATA) if("${FXSDK_PLATFORM_LONG}" STREQUAL fx9860G) add_executable(myaddin ${SOURCES} ${ASSETS} ${ASSETS_${FXSDK_PLATFORM}} ${ASSETS_${FXSDK_PLATFORM}_${COLORMODE_fx}} ) @@ -146,4 +147,4 @@ elseif("${FXSDK_PLATFORM_LONG}" STREQUAL fxCG50) NAME "Col RPG EGA" ICONS assets-cg/icon-uns.png assets-cg/icon-sel.png) endif() -endif() \ No newline at end of file +endif() diff --git a/assets-cg/levels/not used anymore (backup)/tileset2b_CG.png b/assets-cg/levels/not used anymore (backup)/tileset2b_CG.png deleted file mode 100644 index 2e6b6e6..0000000 Binary files a/assets-cg/levels/not used anymore (backup)/tileset2b_CG.png and /dev/null differ diff --git a/assets-cg/levels/not used anymore (backup)/tilesetEGA64_CG_bak.png b/assets-cg/levels/not used anymore (backup)/tilesetEGA64_CG_bak.png deleted file mode 100644 index 5fd8503..0000000 Binary files a/assets-cg/levels/not used anymore (backup)/tilesetEGA64_CG_bak.png and /dev/null differ diff --git a/assets/converters.py b/assets/converters.py index 7a9cb8b..bdab622 100644 --- a/assets/converters.py +++ b/assets/converters.py @@ -3,15 +3,80 @@ import fxconv import json import pathlib import csv +import os def convert(input, output, params, target): if params["custom-type"] == "map": - convert_map(input, output, params, target) + #convert_map(input, output, params, target) + #return 0 + return 1 + elif params["custom-type"] == "world": + convert_world(input, output, params, target) return 0 else: return 1 + + +def convert_world(input, output, params, target): + print( "WE ARE COMPUTING THE WORLD", input ) + + data = json.load(open(input, "r")) + nbMaps = ["fileName" in i for i in data["maps"]].count(True) + print( "We have to treat ", nbMaps, " maps") + print( "So let's go ... ") + + structWorld = fxconv.Structure() + + for i in range(nbMaps): + nameMap = data["maps"][i]["fileName"].replace(".tmx","") + nameMapFree = nameMap.split("/")[-1] + #count the number of "back" (cd ..) to locate the map on the computer + nbRetour = nameMap.count("..")+1 + #create the map absolute path + + + nameTMX = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".tmx" + nameJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json" + + commandline = 'tiled --export-map json ' + nameTMX + ' ' + nameJSON + print( "TILED COMMAND LINE FOR MAPS : ", commandline ) + os.system( commandline ) + + + mapPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameMap + ".json" + print("Map ", i , " name : ", mapPath ) + + + + xmin = data["maps"][i]["x"] + print( "xmin = ", xmin ) + structWorld += fxconv.u16( xmin ) #xmin parameter + + ymin = data["maps"][i]["y"] + print( "ymin = ", ymin ) + structWorld += fxconv.u16( ymin ) #ymin parameter + + xmax = data["maps"][i]["x"] + data["maps"][i]["width"] + print( "xmax = ", xmax ) + structWorld += fxconv.u16( xmax ) #xmax parameter + + ymax = data["maps"][i]["y"] + data["maps"][i]["height"] + print( "ymax = ", ymax ) + structWorld += fxconv.u16( ymax ) #ymax parameter + + map = convert_map( mapPath, output, params, target ) + print( "Map = ", map ) + structWorld += map + + #generate ! + fxconv.elf(structWorld, output, "_" + params["name"], **target) + + + + def convert_map(input, output, params, target): + print( "WE ARE COMPUTING THE MAP : ", input ) data = json.load(open(input, "r")) #find the tileset in use. it's a relative path (like ../tileset.tsx) @@ -22,9 +87,14 @@ def convert_map(input, output, params, target): #count the number of "back" (cd ..) to locate the tileset on the computer nbRetour = nameTileset.count("..")+1 #create the tileset absolute path - tilesetPath = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json" + tilesetTSX = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".tsx" + tilesetJSON = "/".join(input.split("/")[:-nbRetour]) + "/" + nameTileset + ".json" + + commandline = 'tiled --export-tileset json ' + tilesetTSX + ' ' + tilesetJSON + print( "TILED COMMAND LINE FOR TILESET : ", commandline ) + os.system( commandline ) - tileset = open(tilesetPath, "r") + tileset = open(tilesetJSON, "r") data_tileset = json.load(tileset) tileset_size = data_tileset.get("columns") tileset.close() @@ -45,7 +115,6 @@ def convert_map(input, output, params, target): layer_foreground = 0 layer_background = 0 - #create the structure of the map structMap = fxconv.Structure() @@ -64,7 +133,6 @@ def convert_map(input, output, params, target): elif i==nbTilelayer: printf( "ERROR : No Walkable layer data !!!" ) - walk_data = bytes() layer = data["layers"][layer_walkable] for tile in layer["data"]: @@ -87,7 +155,6 @@ def convert_map(input, output, params, target): elif i==nbTilelayer: printf( "ERROR : No Background layer data !!!" ) - layer_data = bytes() layer = data["layers"][layer_background] for tile in layer["data"]: @@ -95,7 +162,6 @@ def convert_map(input, output, params, target): structMap += fxconv.ptr(layer_data) - #import the foreground layer of the map for i in range(nbTilelayer+1): datavalid = data["layers"][i] @@ -106,7 +172,6 @@ def convert_map(input, output, params, target): elif i==nbTilelayer: printf( "ERROR : No Foreground layer data !!!" ) - layer_data = bytes() layer = data["layers"][layer_foreground] for tile in layer["data"]: @@ -114,9 +179,8 @@ def convert_map(input, output, params, target): structMap += fxconv.ptr(layer_data) - - - #generate ! - fxconv.elf(structMap, output, "_" + params["name"], **target) + #fxconv.elf(structMap, output, "_" + params["name"], **target) + + return structMap diff --git a/assets/fxconv-metadata.txt b/assets/fxconv-metadata.txt index ddb88cb..77b9eb0 100644 --- a/assets/fxconv-metadata.txt +++ b/assets/fxconv-metadata.txt @@ -1,3 +1,8 @@ -*.json: - custom-type: map - name_regex: (.*)\.json map_\1 +# *.json: +# custom-type: map +# name_regex: (.*)\.json map_\1 + + +*.world: + custom-type: world + name: worldRPG diff --git a/clean b/clean new file mode 100755 index 0000000..6cf836c --- /dev/null +++ b/clean @@ -0,0 +1,8 @@ +cd assets +rm -f *.json +cd .. +rm -r build-cg +rm -r build-fx +rm *.g1a +rm *.g3a + diff --git a/src/main.c b/src/main.c index cc72975..2ff45f5 100644 --- a/src/main.c +++ b/src/main.c @@ -21,14 +21,20 @@ #include "game.h" #include "mapdata.h" +#include "mapstruct.h" #include "dialogs.h" extern bopti_image_t player_face_img; +extern World worldRPG[]; + + + + /* Game data (defined in "game.h")*/ Game game = { - &map_level0, + &worldRPG[0].mapdata, {10*PXSIZE, 48*PXSIZE, 0, 0, 100, SPEED}, false, false, false, 0 }; @@ -99,10 +105,13 @@ int main(void) { dgray(DGRAY_ON); #endif + /* showtext_dialog(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, true); int in = showtext_dialog_ask(&game, &player_face_img, "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim sit amet.", true, false, "Lorem\0ipsum", 2, 0); if(in) showtext_dialog(&game, &player_face_img, "You choosed ipsum", false, true); else showtext_dialog(&game, &player_face_img, "You choosed Lorem", false, true); + */ + do{ /* clear screen */ dclear(C_WHITE); diff --git a/src/mapdata.h b/src/mapdata.h index e1ae6a5..5d3a221 100644 --- a/src/mapdata.h +++ b/src/mapdata.h @@ -1,10 +1,10 @@ #ifndef MAPDATA_H #define MAPDATA_H -extern Map map_level0; -extern Map map_level1; -extern Map map_level2; -extern Map map_level3; +#include +#include "mapstruct.h" + +extern World worldRPG[]; #endif diff --git a/src/mapstruct.h b/src/mapstruct.h index 7ac7d9a..c80bf30 100644 --- a/src/mapstruct.h +++ b/src/mapstruct.h @@ -26,21 +26,16 @@ typedef struct { } Map; - typedef struct { - - /* numberof maps in the world */ - uint16_t nbmaps; - /* table of coordinates for each map, each is a table of nbmaps elements */ /* area of map N is given by (xmin[N], ymin[N]) --> (xmax[N], ymax[N]) */ - uint16_t *xmin; - uint16_t *ymin; - uint16_t *xmax; - uint16_t *ymax; + uint16_t xmin; + uint16_t ymin; + uint16_t xmax; + uint16_t ymax; /* pointer to the currentmap*/ - Map *currentmap; + Map mapdata; } World; diff --git a/src/player.c b/src/player.c index b466f56..78330fa 100644 --- a/src/player.c +++ b/src/player.c @@ -28,7 +28,7 @@ extern bopti_image_t demo_player_img; void player_draw(Player *player) { dimage(player->px-P_WIDTH/2, player->py-P_HEIGHT/2, &demo_player_img); - dprint( 10, 10, C_RED, "X= %d - Y= %d", player->x, player->y ); + //dprint( 10, 10, C_RED, "X= %d - Y= %d", player->x, player->y ); } void player_move(Map *map_level, Player *player, Direction direction) {