Ptit WIP
This commit is contained in:
parent
e8b710df9d
commit
461f12e92c
6 changed files with 100 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,3 +6,4 @@ raylib/
|
|||
*.exe
|
||||
*.swp
|
||||
*.tiled-session
|
||||
map/maps_out.c
|
||||
|
|
15
Makefile
15
Makefile
|
@ -21,13 +21,21 @@ SRC_DIR = src
|
|||
|
||||
OBJS = $(patsubst $(SRC_DIR)/%.c,build-tmp/%.o,$(wildcard $(SRC_DIR)/*.c))
|
||||
|
||||
all: | builddir build builddir2
|
||||
all: | builddir map build builddir2
|
||||
|
||||
windef:
|
||||
$(eval OUTPUT = "$(OUTNAME).exe")
|
||||
$(eval BUILD_DIR = build-win)
|
||||
$(eval LDFLAGS = $(LDFLAGS_WIN))
|
||||
|
||||
converter: map/converter.c
|
||||
$(CC) map/converter.c -o map/converter $(CFLAGS)
|
||||
|
||||
map: converter
|
||||
./map/converter
|
||||
$(CC) -c map/maps_out.c -o build-tmp/maps_out.o $(CFLAGS)
|
||||
$(eval OBJS += build-tmp/maps_out.o)
|
||||
|
||||
builddir:
|
||||
- mkdir $(BUILD_DIR)
|
||||
mkdir build-tmp
|
||||
|
@ -56,6 +64,7 @@ clean:
|
|||
- rm -rf build-win
|
||||
- rm -rf build-tmp
|
||||
- rm "$(OUTNAME).amd64" "$(OUTNAME).exe"
|
||||
- rm map/maps_out.c map/converter
|
||||
|
||||
.NOTPARALLEL: builddir builddir2
|
||||
.PHONY: all test clean win windef builddir builddir2 testwin
|
||||
.NOTPARALLEL: builddir builddir2 converter map
|
||||
.PHONY: all test clean win windef builddir builddir2 testwin converter map
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../src/types.h"
|
||||
|
||||
|
@ -11,26 +12,43 @@
|
|||
|
||||
char *filebuf;
|
||||
|
||||
char *filesig =
|
||||
char filesig[] =
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
|
||||
"<map version=\"1.8\" tiledversion=\"1.8.2\" orientation=\"orthogonal\" renderorder=\"right-down\" width=\"256\" height=\"256\" tilewidth=\"32\" tileheight=\"32\" infinite=\"0\" nextlayerid=\"2\" nextobjectid=\"1\">";
|
||||
"<map version=\"1.8\" tiledversion=\"1.8.2\" orientation=\"orthogonal\" renderorder=\"right-down\" width=\"256\" height=\"256\" tilewidth=\"32\" tileheight=\"32\" infinite=\"0\" nextlayerid=\"2\" nextobjectid=\"1\">\n"
|
||||
" <tileset firstgid=\"1\" source=\"mt_tileset.tsx\"/>\n"
|
||||
" <layer id=\"1\" name=\"Tile Layer 1\" width=\"256\" height=\"256\">\n"
|
||||
" <data encoding=\"csv\">";
|
||||
|
||||
int import_map(MapCollec *mapcollec, FILE *mapfile){
|
||||
char tmpname[256];
|
||||
|
||||
int import_map(FILE *mapfile, FILE *outfile){
|
||||
int32_t fbuf_pos = 0;
|
||||
int32_t fbuf_max = fread(filebuf, 1, FBUF_SIZE, mapfile);
|
||||
if(strncmp(filebuf, filesig, sizeof(filesig))){
|
||||
fread(filebuf, 1, FBUF_SIZE, mapfile);
|
||||
if(strncmp(filebuf, filesig, sizeof(filesig)-1)){
|
||||
printf("Error: Invalid file header.\n");
|
||||
return 1;
|
||||
}
|
||||
fbuf_pos += sizeof(filesig)-1;
|
||||
fprintf(outfile, "uint8_t %s_lyr0[] = {", tmpname);
|
||||
int32_t datlen = strcspn(&filebuf[fbuf_pos], "<");
|
||||
fwrite(&filebuf[fbuf_pos], 1, datlen, outfile);
|
||||
fprintf(outfile, "};\nMap %s = {{%s_lyr0, 0}, 256, 256};\n", tmpname, tmpname);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
FILE *maps[100] = {NULL};
|
||||
|
||||
int import_maps(MapCollec *mapcollec){
|
||||
char tmpname[256];
|
||||
int import_maps(){
|
||||
int i;
|
||||
FILE *outfile = fopen(MAPDIR "maps_out.c", "w+");
|
||||
int nmaps = 0;
|
||||
if(!outfile){
|
||||
printf("Failed to open file \"" MAPDIR "maps_out.c\"\n");
|
||||
printf("Error : %d (%d)\n", errno, EINVAL);
|
||||
return 1;
|
||||
}
|
||||
fprintf(outfile, "#include <stdint.h>\n#include \"../src/types.h\"\n");
|
||||
for(i = 0; i < 100; i++){
|
||||
snprintf(tmpname, 256, MAPDIR MAPNAME "%d.tmx", i);
|
||||
printf("Loading map \"%s\"...\n", tmpname);
|
||||
|
@ -39,9 +57,17 @@ int import_maps(MapCollec *mapcollec){
|
|||
printf("Failed to load map, stopping here\n");
|
||||
break;
|
||||
}
|
||||
if(import_map(mapcollec, maps[i]))
|
||||
snprintf(tmpname, 256, MAPNAME "%d", i);
|
||||
if(import_map(maps[i], outfile))
|
||||
return 0;
|
||||
nmaps++;
|
||||
}
|
||||
fprintf(outfile, "MapCollec mapcollec = {%d,{", nmaps);
|
||||
for(int i = 0; i < nmaps; i++){
|
||||
fprintf(outfile, "&" MAPNAME "%d,", i);
|
||||
}
|
||||
fprintf(outfile, "}};\n");
|
||||
fclose(outfile);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
@ -52,20 +78,18 @@ void clean_maps(){
|
|||
}
|
||||
}
|
||||
|
||||
int export_maps(MapCollec *mapcollec){
|
||||
|
||||
}
|
||||
|
||||
int main(){
|
||||
MapCollec mapcollec;
|
||||
printf("===== Converter output =====\n");
|
||||
filebuf = malloc(FBUF_SIZE);
|
||||
if(!filebuf)
|
||||
return 1;
|
||||
if(!import_maps(&mapcollec))
|
||||
if(!import_maps())
|
||||
return 1;
|
||||
|
||||
clean_maps();
|
||||
free(filebuf);
|
||||
|
||||
printf("===== Converter end =====\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
36
src/draw.c
36
src/draw.c
|
@ -13,6 +13,7 @@
|
|||
#include "ui.h"
|
||||
|
||||
#define TEX_N 9
|
||||
#define TILE_N 3
|
||||
|
||||
char *tex_files[TEX_N] = {
|
||||
"assets/blobbleu1.png",
|
||||
|
@ -26,7 +27,14 @@ char *tex_files[TEX_N] = {
|
|||
"assets/blobvert3.png"
|
||||
};
|
||||
|
||||
char *tile_files[TILE_N] = {
|
||||
"assets/tile_grass.png",
|
||||
"assets/tile_cobble.png",
|
||||
"assets/tile_grass.png"
|
||||
};
|
||||
|
||||
Texture2D tex_index[TEX_N];
|
||||
Image tile_index[TILE_N];
|
||||
|
||||
extern GUIInfo gui_info;
|
||||
|
||||
|
@ -36,12 +44,32 @@ int init_draw(){
|
|||
|
||||
SetTargetFPS(60);
|
||||
|
||||
for(int i = 0; i < TEX_N; i++){
|
||||
for(int i = 0; i < TEX_N; i++)
|
||||
tex_index[i] = LoadTexture(tex_files[i]);
|
||||
}
|
||||
for(int i = 0; i < TILE_N; i++)
|
||||
tile_index[i] = LoadImage(tile_files[i]);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Texture2D mkmap_img(Map *map){
|
||||
uint8_t *tiles = map->layers[0];
|
||||
Image mapimg = GenImageColor(map->width*32, map->height*32, BLACK);
|
||||
for(int x = 0; x < map->width; x++){
|
||||
for(int y = 0; y < map->height; y++){
|
||||
Rectangle recta = {.x = 0, .y = 0,
|
||||
.width = map->width*32, .height = map->height*32};
|
||||
Rectangle rectb = recta;
|
||||
rectb.x = x;
|
||||
rectb.y = y;
|
||||
ImageDraw(&mapimg, tile_index[tiles[map->width*y + x]], recta, rectb, WHITE);
|
||||
}
|
||||
}
|
||||
Texture2D maptex = LoadTextureFromImage(mapimg);
|
||||
UnloadImage(mapimg);
|
||||
return maptex;
|
||||
}
|
||||
|
||||
void draw_workers(Game *game){
|
||||
Workers *workers = &game->workers;
|
||||
for(int i = 0; i < workers->worker_n; i++){
|
||||
|
@ -65,6 +93,10 @@ void draw_machines(Game *game){
|
|||
}
|
||||
}
|
||||
|
||||
void draw_map(Game *game){
|
||||
DrawTextureV(game->map.maptex, (V2d){0,0}, WHITE);
|
||||
}
|
||||
|
||||
void draw_game(Game *game){
|
||||
ClearBackground(BLACK);
|
||||
|
||||
|
|
|
@ -10,3 +10,8 @@
|
|||
|
||||
#include "types.h"
|
||||
|
||||
extern MapCollec mapcollec;
|
||||
|
||||
int load_map(int mapn){
|
||||
|
||||
}
|
||||
|
|
10
src/types.h
10
src/types.h
|
@ -119,10 +119,20 @@ typedef struct {
|
|||
|
||||
} MapCollec;
|
||||
|
||||
typedef struct {
|
||||
|
||||
uint8_t *coll;
|
||||
int32_t width;
|
||||
int32_t height;
|
||||
Texture2D maptex;
|
||||
|
||||
} LoadedMap;
|
||||
|
||||
typedef struct {
|
||||
|
||||
Machines machines;
|
||||
Workers workers;
|
||||
LoadedMap map;
|
||||
|
||||
Camera2D camera;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue