Map tiled qui marche
This commit is contained in:
parent
461f12e92c
commit
b66b143f1a
6 changed files with 36 additions and 15 deletions
BIN
map/converter
Executable file
BIN
map/converter
Executable file
Binary file not shown.
32
src/draw.c
32
src/draw.c
|
@ -28,9 +28,9 @@ char *tex_files[TEX_N] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
char *tile_files[TILE_N] = {
|
char *tile_files[TILE_N] = {
|
||||||
|
"assets/tile_grass.png",
|
||||||
"assets/tile_grass.png",
|
"assets/tile_grass.png",
|
||||||
"assets/tile_cobble.png",
|
"assets/tile_cobble.png",
|
||||||
"assets/tile_grass.png"
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Texture2D tex_index[TEX_N];
|
Texture2D tex_index[TEX_N];
|
||||||
|
@ -44,28 +44,39 @@ int init_draw(){
|
||||||
|
|
||||||
SetTargetFPS(60);
|
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]);
|
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]);
|
tile_index[i] = LoadImage(tile_files[i]);
|
||||||
|
ImageFormat(&tile_index[i], 4);
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture2D mkmap_img(Map *map){
|
Texture2D mkmap_tex(Map *map){
|
||||||
uint8_t *tiles = map->layers[0];
|
uint8_t *tiles = map->layers[0];
|
||||||
Image mapimg = GenImageColor(map->width*32, map->height*32, BLACK);
|
void *pixels = MemAlloc(3*map->width*32*map->height*32);
|
||||||
for(int x = 0; x < map->width; x++){
|
Image mapimg = {.data = pixels,
|
||||||
for(int y = 0; y < map->height; y++){
|
.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,
|
Rectangle recta = {.x = 0, .y = 0,
|
||||||
.width = map->width*32, .height = map->height*32};
|
.width = 32, .height = 32};
|
||||||
Rectangle rectb = recta;
|
Rectangle rectb = recta;
|
||||||
rectb.x = x;
|
rectb.x = x*32;
|
||||||
rectb.y = y;
|
rectb.y = y*32;
|
||||||
ImageDraw(&mapimg, tile_index[tiles[map->width*y + x]], recta, rectb, WHITE);
|
ImageDraw(&mapimg, tile_index[tiles[map->width*y + x]], recta, rectb, WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Texture2D maptex = LoadTextureFromImage(mapimg);
|
Texture2D maptex = LoadTextureFromImage(mapimg);
|
||||||
|
GenTextureMipmaps(&maptex);
|
||||||
UnloadImage(mapimg);
|
UnloadImage(mapimg);
|
||||||
return maptex;
|
return maptex;
|
||||||
}
|
}
|
||||||
|
@ -101,6 +112,7 @@ void draw_game(Game *game){
|
||||||
ClearBackground(BLACK);
|
ClearBackground(BLACK);
|
||||||
|
|
||||||
BeginMode2D(game->camera);
|
BeginMode2D(game->camera);
|
||||||
|
draw_map(game);
|
||||||
draw_machines(game);
|
draw_machines(game);
|
||||||
draw_workers(game);
|
draw_workers(game);
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
|
|
||||||
int init_draw();
|
int init_draw();
|
||||||
|
|
||||||
|
Texture2D mkmap_tex(Map *map);
|
||||||
|
|
||||||
void draw_game(Game *game);
|
void draw_game(Game *game);
|
||||||
|
|
||||||
void draw(Game *game);
|
void draw(Game *game);
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
#include "map.h"
|
||||||
#include "draw.h"
|
#include "draw.h"
|
||||||
#include "ui.h"
|
#include "ui.h"
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
int init(Game *game){
|
int init(Game *game){
|
||||||
int err = init_draw();
|
int err = init_draw();
|
||||||
err |= init_game(game);
|
err |= init_game(game);
|
||||||
|
load_map(game, 0);
|
||||||
init_ui();
|
init_ui();
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@ -52,8 +54,8 @@ int main(){
|
||||||
|
|
||||||
int c_worker = 0;
|
int c_worker = 0;
|
||||||
|
|
||||||
for(int k = 0; k < 42; k++){
|
for(int k = 0; k < 16; k++){
|
||||||
for(int j = 0; j < 256; j++){
|
for(int j = 0; j < 16; j++){
|
||||||
Machine *coal_mine = add_machine(&game.machines, (V2d){k*250+40,j*400+40});
|
Machine *coal_mine = add_machine(&game.machines, (V2d){k*250+40,j*400+40});
|
||||||
coal_mine->type = MT_CoalMine;
|
coal_mine->type = MT_CoalMine;
|
||||||
Machine *iron_mine = add_machine(&game.machines, (V2d){k*250+40,j*400+240});
|
Machine *iron_mine = add_machine(&game.machines, (V2d){k*250+40,j*400+240});
|
||||||
|
|
|
@ -9,9 +9,14 @@
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
#include "draw.h"
|
||||||
|
|
||||||
extern MapCollec mapcollec;
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,4 +12,4 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
int load_map(Game *game, int mapn);
|
||||||
|
|
Loading…
Add table
Reference in a new issue