First drawing of the mobile tiled background - no movement yet

This commit is contained in:
Sylvain PILLOT 2023-01-26 22:35:33 +01:00
parent 4e66ba1b80
commit 91b9826625
10 changed files with 238 additions and 29 deletions

View File

@ -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
# ...
)

View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.8" tiledversion="1.8.0" orientation="orthogonal" renderorder="right-down" width="102" height="14" tilewidth="16" tileheight="16" infinite="0" nextlayerid="3" nextobjectid="1">
<editorsettings>
<export target="Level1.json" format="json"/>
</editorsettings>
<tileset firstgid="1" source="Tileset_Space.tsx"/>
<layer id="1" name="Calque de Tuiles 1" width="102" height="14">
<data encoding="csv">
52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,
23,19,94,93,22,23,122,124,23,19,20,21,22,23,122,124,23,19,94,93,22,23,122,124,23,19,20,21,22,23,122,124,23,19,94,93,22,23,122,124,23,19,20,21,22,23,122,124,23,19,94,93,22,23,122,124,23,19,20,21,22,23,122,124,23,19,94,93,22,23,122,124,23,19,20,21,22,23,122,124,23,19,94,93,22,23,122,124,23,19,20,21,22,23,122,124,23,19,94,93,22,23,
50,102,82,83,103,50,0,0,50,28,29,30,31,50,0,0,50,102,82,83,103,50,0,0,50,28,29,30,31,50,0,0,50,102,82,83,103,50,0,0,50,28,29,30,31,50,0,0,50,102,82,83,103,50,0,0,50,28,29,30,31,50,0,0,50,102,82,83,103,50,0,0,50,28,29,30,31,50,0,0,50,102,82,83,103,50,0,0,50,28,29,30,31,50,0,0,50,102,82,83,103,50,
134,0,0,0,0,116,0,0,116,0,0,0,0,116,0,0,116,0,0,0,0,134,0,0,134,0,0,0,0,116,0,0,116,0,0,0,0,116,0,0,116,0,0,0,0,134,0,0,9,0,0,0,0,9,0,0,134,0,0,0,0,116,0,0,116,0,0,0,0,116,0,0,116,0,0,0,0,134,0,0,134,0,0,0,0,116,0,0,116,0,0,0,0,116,0,0,116,0,0,0,0,134,
134,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,134,0,0,134,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,134,0,0,18,0,0,0,0,18,0,0,134,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,134,0,0,134,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,134,
24,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,0,0,0,134,0,0,134,0,0,0,0,116,0,0,116,0,0,0,0,116,0,0,116,0,0,0,0,134,0,0,18,0,0,0,0,18,0,0,134,0,0,0,0,116,0,0,116,0,0,0,0,116,0,0,116,0,0,0,0,134,0,0,134,0,0,0,0,116,0,0,116,0,0,0,0,116,0,0,116,0,0,0,0,134,
23,93,82,83,94,23,0,0,23,37,38,39,40,23,0,0,23,93,82,83,94,23,0,0,23,37,38,39,40,23,0,0,23,93,82,83,94,23,0,0,23,37,38,39,40,23,0,0,23,93,82,83,94,23,0,0,23,37,38,39,40,23,0,0,23,93,82,83,94,23,0,0,23,37,38,39,40,23,0,0,23,93,82,83,94,23,0,0,23,37,38,39,40,23,0,0,23,93,82,83,94,23,
50,46,103,102,49,50,122,124,50,46,47,48,49,50,122,124,50,46,103,102,49,50,122,124,50,46,47,48,49,50,122,124,50,46,103,102,49,50,122,124,50,46,47,48,49,50,122,124,50,46,103,102,49,50,122,124,50,46,47,48,49,50,122,124,50,46,103,102,49,50,122,124,50,46,47,48,49,50,122,124,50,46,103,102,49,50,122,124,50,46,47,48,49,50,122,124,50,46,103,102,49,50,
52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53,52,53
</data>
</layer>
</map>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<tileset version="1.8" tiledversion="1.8.0" name="Level1_Tiles" tilewidth="16" tileheight="16" tilecount="135" columns="9">
<image source="tileset.png" width="144" height="240"/>
</tileset>

View File

@ -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

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

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

@ -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)

8
clean
View File

@ -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 ../..

47
src/background.cpp Normal file
View File

@ -0,0 +1,47 @@
#include "background.h"
#include <azur/azur.h>
#include <azur/gint/render.h>
#include <cstdint>
#include <stdlib.h>
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 )
{
}

38
src/background.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef BACKGROUND_H
#define BACKGROUND_H
#include <cstdint>
#include <stdlib.h>
#include <azur/gint/render.h>
#include <vector>
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

View File

@ -1,4 +1,4 @@
#define DEBUG_MODE 0
#define DEBUG_MODE 1
#include <azur/azur.h>
#include <azur/gint/render.h>
@ -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<Bullet*> MyPlayerBullets;
std::vector<Enemy*> MyEnemies;
std::vector<Impact*> 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
}