Map tiled qui marche

This commit is contained in:
attilavs2 2025-03-19 20:26:54 +01:00
parent 461f12e92c
commit b66b143f1a
6 changed files with 36 additions and 15 deletions

BIN
map/converter Executable file

Binary file not shown.

View file

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

View file

@ -18,6 +18,8 @@
int init_draw();
Texture2D mkmap_tex(Map *map);
void draw_game(Game *game);
void draw(Game *game);

View file

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

View file

@ -9,9 +9,14 @@
#include <raymath.h>
#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;
}

View file

@ -12,4 +12,4 @@
#pragma once
int load_map(Game *game, int mapn);