diff --git a/map/converter b/map/converter new file mode 100755 index 0000000..f3e877d Binary files /dev/null and b/map/converter differ diff --git a/src/draw.c b/src/draw.c index 271cb8c..fa4c9a0 100644 --- a/src/draw.c +++ b/src/draw.c @@ -28,9 +28,9 @@ char *tex_files[TEX_N] = { }; char *tile_files[TILE_N] = { + "assets/tile_grass.png", "assets/tile_grass.png", "assets/tile_cobble.png", - "assets/tile_grass.png" }; Texture2D tex_index[TEX_N]; @@ -44,28 +44,39 @@ 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++) + GenTextureMipmaps(&tex_index[i]); + } + for(int i = 0; i < TILE_N; i++){ tile_index[i] = LoadImage(tile_files[i]); + ImageFormat(&tile_index[i], 4); + } return 0; } -Texture2D mkmap_img(Map *map){ +Texture2D mkmap_tex(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++){ + void *pixels = MemAlloc(3*map->width*32*map->height*32); + Image mapimg = {.data = pixels, + .width = map->width*32, + .height = map->height*32, + .mipmaps = 1, + .format = 4 + }; + for(int y = 0; y < map->height; y++){ + for(int x = 0; x < map->width; x++){ Rectangle recta = {.x = 0, .y = 0, - .width = map->width*32, .height = map->height*32}; + .width = 32, .height = 32}; Rectangle rectb = recta; - rectb.x = x; - rectb.y = y; + rectb.x = x*32; + rectb.y = y*32; ImageDraw(&mapimg, tile_index[tiles[map->width*y + x]], recta, rectb, WHITE); } } Texture2D maptex = LoadTextureFromImage(mapimg); + GenTextureMipmaps(&maptex); UnloadImage(mapimg); return maptex; } @@ -101,6 +112,7 @@ void draw_game(Game *game){ ClearBackground(BLACK); BeginMode2D(game->camera); + draw_map(game); draw_machines(game); draw_workers(game); EndMode2D(); diff --git a/src/draw.h b/src/draw.h index add5f10..9d3acbd 100644 --- a/src/draw.h +++ b/src/draw.h @@ -18,6 +18,8 @@ int init_draw(); +Texture2D mkmap_tex(Map *map); + void draw_game(Game *game); void draw(Game *game); diff --git a/src/main.c b/src/main.c index 0a3449e..a4b2722 100644 --- a/src/main.c +++ b/src/main.c @@ -9,6 +9,7 @@ #include "types.h" #include "game.h" +#include "map.h" #include "draw.h" #include "ui.h" @@ -26,6 +27,7 @@ int init(Game *game){ int err = init_draw(); err |= init_game(game); + load_map(game, 0); init_ui(); return err; } @@ -52,8 +54,8 @@ int main(){ int c_worker = 0; - for(int k = 0; k < 42; k++){ - for(int j = 0; j < 256; j++){ + for(int k = 0; k < 16; k++){ + for(int j = 0; j < 16; j++){ Machine *coal_mine = add_machine(&game.machines, (V2d){k*250+40,j*400+40}); coal_mine->type = MT_CoalMine; Machine *iron_mine = add_machine(&game.machines, (V2d){k*250+40,j*400+240}); diff --git a/src/map.c b/src/map.c index 93608fd..aa8ccd2 100644 --- a/src/map.c +++ b/src/map.c @@ -9,9 +9,14 @@ #include #include "types.h" +#include "draw.h" extern MapCollec mapcollec; -int load_map(int mapn){ - +int load_map(Game *game, int mapn){ + LoadedMap *nmap = &game->map; + Map *map = mapcollec.maps[mapn]; + nmap->maptex = mkmap_tex(map); + nmap->width = map->width; + nmap->height = map->height; } diff --git a/src/map.h b/src/map.h index e0ba8e5..f9d5105 100644 --- a/src/map.h +++ b/src/map.h @@ -12,4 +12,4 @@ #pragma once - +int load_map(Game *game, int mapn);