diff --git a/CMakeLists.txt b/CMakeLists.txt
index e2fdfe4..d3ef66e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -11,6 +11,22 @@ find_package(Azur 0.1 REQUIRED)
find_package(Gint 2.9 REQUIRED)
find_package(LibProf 2.4 REQUIRED)
+
+fxconv_declare_converters(assets-cg/converters.py)
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_LIST_DIR}/assets-cg/Levels/Level1.json"
+ COMMENT "Convert Tiled TMX map to usable JSON file"
+ COMMAND tiled --export-tileset json Tileset_Space.tsx Tileset_Space.json
+ COMMAND find | grep .*.tmx | sed 's/.tmx//g' | xargs -l bash -c 'tiled --export-map json $$0.tmx $$0.json'
+ WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/assets-cg/Levels/
+ DEPENDS assets-cg/Levels/Level1.tmx
+ assets-cg/converters.py
+ assets-cg/Levels/tileset.png
+ assets-cg/Levels/Tileset_Space.tsx)
+
+
+
set(SOURCES
src/main.cpp
src/collections.cpp
@@ -21,6 +37,7 @@ set(SOURCES
src/bullet.cpp
src/enemy.cpp
src/starfieldshader.cpp
+ src/background.cpp
src/point2D.cpp
src/trajectory.cpp
@@ -45,6 +62,9 @@ set(ASSETS_cg
assets-cg/Sprites/Enemies/Enemy_Blue_Lvl1.png
assets-cg/Sprites/Enemies/Enemy_Red_Lvl1.png
+ assets-cg/Levels/tileset.png
+ assets-cg/Levels/Level1.json
+# assets-cg/Levels/Tileset_Space.json
# ...
)
diff --git a/assets-cg/Levels/Level1.tmx b/assets-cg/Levels/Level1.tmx
new file mode 100644
index 0000000..f2f368c
--- /dev/null
+++ b/assets-cg/Levels/Level1.tmx
@@ -0,0 +1,25 @@
+
+
diff --git a/assets-cg/Levels/Tileset_Space.tsx b/assets-cg/Levels/Tileset_Space.tsx
new file mode 100644
index 0000000..7a6f31e
--- /dev/null
+++ b/assets-cg/Levels/Tileset_Space.tsx
@@ -0,0 +1,4 @@
+
+
+
+
diff --git a/assets-cg/Levels/fxconv-metadata.txt b/assets-cg/Levels/fxconv-metadata.txt
new file mode 100644
index 0000000..9a29571
--- /dev/null
+++ b/assets-cg/Levels/fxconv-metadata.txt
@@ -0,0 +1,8 @@
+*.json:
+ custom-type: map
+ name_regex: (.*)\.json map_\1
+
+tileset.png:
+ type: bopti-image
+ name: img_Tileset_Space
+ profile: p8_rgb565a
diff --git a/assets-cg/Levels/tileset.png b/assets-cg/Levels/tileset.png
new file mode 100644
index 0000000..dd5e72f
Binary files /dev/null and b/assets-cg/Levels/tileset.png differ
diff --git a/assets-cg/converters.py b/assets-cg/converters.py
new file mode 100644
index 0000000..d012faf
--- /dev/null
+++ b/assets-cg/converters.py
@@ -0,0 +1,56 @@
+from random import randint
+import fxconv
+import json
+import pathlib
+import csv
+
+def convert(input, output, params, target):
+ if params["custom-type"] == "map":
+ convert_map(input, output, params, target)
+ return 0
+ else:
+ return 1
+
+def convert_map(input, output, params, target):
+ data = json.load(open(input, "r"))
+
+ #find the tileset in use. it's a relative path (like ../tileset.tsx)
+ nameTileset = data["tilesets"][0]["source"].replace(".tsx","")
+ print(nameTileset)
+ #the name of the tileset without the .something
+ nameTilesetFree = nameTileset.split("/")[-1]
+ #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"
+
+ tileset = open(tilesetPath, "r")
+ data_tileset = json.load(tileset)
+ tileset_size = data_tileset.get("columns")
+ tileset.close()
+
+
+ #Extract from the json the width, height
+ w, h = data["width"], data["height"]
+
+ #nbTileLayer is the number of "true" layers (without ObjectsLayer)
+ nbTilelayer = ["data" in i for i in data["layers"]].count(True)
+
+ structMap = fxconv.Structure()
+
+ structMap += fxconv.u32(w) + fxconv.u32(h)
+ structMap += fxconv.ref(f"img_{nameTilesetFree}")
+ structMap += fxconv.u32(tileset_size)
+
+ #generate the array of tiles from the layer
+ for i in range(nbTilelayer):
+ layer_data = bytes()
+ layer = data["layers"][i]
+ for tile in layer["data"]:
+ layer_data += fxconv.u16(tile)
+
+ structMap += fxconv.ptr(layer_data)
+
+ #generate !
+ fxconv.elf(structMap, output, "_" + params["name"], **target)
+
diff --git a/clean b/clean
index 5e7f250..30d6c3f 100755
--- a/clean
+++ b/clean
@@ -2,3 +2,11 @@ rm -r build-cg/
rm -r build-fx
rm *.g3a
rm *.g1a
+
+cd assets-cg
+rm -r __pycache__
+
+cd Levels
+rm *.json
+
+cd ../..
diff --git a/src/background.cpp b/src/background.cpp
new file mode 100644
index 0000000..872c57a
--- /dev/null
+++ b/src/background.cpp
@@ -0,0 +1,47 @@
+#include "background.h"
+#include
+#include
+
+#include
+#include
+
+
+
+extern struct Map map_Level1;
+
+
+Background::Background( )
+{
+
+}
+
+Background::~Background( )
+{
+
+}
+
+void Background::Render( void )
+{
+
+ for(int i=0; i<25; i++)
+ {
+ for(int j=0; j<14; j++)
+ {
+ uint16_t index = j * map_Level1.w + i;
+ uint16_t currentTile = map_Level1.layers[ index ];
+ if (currentTile!=0)
+ {
+ uint16_t xtile = ((currentTile % 9)-1) * 16;
+ uint16_t ytile = (currentTile / 9) * 16;
+ azrp_subimage_p8( i*16, j*16, map_Level1.tileset, xtile, ytile, 16, 16, DIMAGE_NONE );
+ }
+ }
+ }
+
+
+}
+
+void Background::Update( float dt )
+{
+
+}
\ No newline at end of file
diff --git a/src/background.h b/src/background.h
new file mode 100644
index 0000000..66b25ce
--- /dev/null
+++ b/src/background.h
@@ -0,0 +1,38 @@
+#ifndef BACKGROUND_H
+#define BACKGROUND_H
+
+
+#include
+#include
+
+#include
+
+#include
+
+
+struct Map {
+ /*width, height and the number of layer of the map*/
+ int w, h;
+
+ /*the tileset to use*/
+ bopti_image_t *tileset;
+ int tileset_size;
+
+ /*list of all the tiles*/
+ short *layers;
+};
+
+
+class Background
+{
+ public:
+ Background( );
+ ~Background( );
+
+ void Update( float dt );
+ void Render( );
+};
+
+
+
+#endif
diff --git a/src/main.cpp b/src/main.cpp
index e3ce2d5..b782407 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,4 +1,4 @@
-#define DEBUG_MODE 0
+#define DEBUG_MODE 1
#include
#include
@@ -32,6 +32,7 @@
#include "enemy.h"
#include "MyAzurShaders.h"
#include "impact.h"
+#include "background.h"
#include "trajectory.h"
@@ -73,6 +74,8 @@ std::vector MyPlayerBullets;
std::vector MyEnemies;
std::vector MyImpacts;
+Background MyBackground;
+
Starfield *MyStarField;
Player *MyPlayer;
@@ -181,40 +184,40 @@ static void update( float dt )
static void render( void )
{
- #if(BIAS)
- if (texttodraw>=1) Azur_draw_text(1,01, "FPS = %.0f", (float) (1000000.0f / elapsedTime) );
- if (texttodraw>=1) Azur_draw_text(1,11, "Part.= %d - Bull.= %d", MyParticles.size(), MyPlayerBullets.size() );
- if (texttodraw>=1 && !MyEnemies.empty()) Azur_draw_text(1,21, "Ennmy Life= %d", MyEnemies[0]->life );
- if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.0f mc secs", (float) time_update );
- if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.0f mc secs", (float) time_render );
- if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f );
- if (texttodraw>=2) Azur_draw_text(1,61, ">Total = %.0f seconds", (float) elapsedTime );
-
- if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory);
- if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory);
- if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory );
-
- if (texttodraw>=3) Azur_draw_text(1,121, "Size of Particles : %d bytes", sizeof(Particle) );
- if (texttodraw>=3) Azur_draw_text(1,131, "Size of Bullets : %d bytes", sizeof(Bullet) );
-
- #endif
+ azrp_starfield();
- azrp_starfield();
-
- for(auto& b : MyPlayerBullets)
- b->Render();
+ MyBackground.Render( );
- for(auto& e : MyEnemies)
- e->Render();
+ for(auto& b : MyPlayerBullets)
+ b->Render();
- for( auto& i : MyImpacts)
- i->Render();
+ for(auto& e : MyEnemies)
+ e->Render();
- for(auto& p : MyParticles)
- p->Render();
+ for( auto& i : MyImpacts)
+ i->Render();
- MyPlayer->Render();
+ for(auto& p : MyParticles)
+ p->Render();
+
+ MyPlayer->Render();
+
+
+ #if(BIAS)
+ if (texttodraw>=1) Azur_draw_text(1,01, "FPS = %.0f", (float) (1000000.0f / elapsedTime) );
+ if (texttodraw>=1) Azur_draw_text(1,11, "Part.= %d - Bull.= %d", MyParticles.size(), MyPlayerBullets.size() );
+ if (texttodraw>=1 && !MyEnemies.empty()) Azur_draw_text(1,21, "Ennmy Life= %d", MyEnemies[0]->life );
+ if (texttodraw>=2) Azur_draw_text(1,31, "Update = %.0f mc secs", (float) time_update );
+ if (texttodraw>=2) Azur_draw_text(1,41, "Render = %.0f mc secs", (float) time_render );
+ if (texttodraw>=2) Azur_draw_text(1,51, ">Total = %.3f ml secs", (float) elapsedTime / 1000.0f );
+ if (texttodraw>=2) Azur_draw_text(1,61, ">Total = %.0f seconds", (float) elapsedTime );
+ if (texttodraw>=3) Azur_draw_text(1,81, "Mem Used : %d", _uram_stats->used_memory + extram_stats->used_memory);
+ if (texttodraw>=3) Azur_draw_text(1,91, "Mem Free : %d", _uram_stats->free_memory + extram_stats->free_memory);
+ if (texttodraw>=3) Azur_draw_text(1,101, "Mem Peak Used : %d", _uram_stats->peak_used_memory + extram_stats->peak_used_memory );
+ if (texttodraw>=3) Azur_draw_text(1,121, "Size of Particles : %d bytes", sizeof(Particle) );
+ if (texttodraw>=3) Azur_draw_text(1,131, "Size of Bullets : %d bytes", sizeof(Bullet) );
+ #endif
}