#include #include #include #include #include #include #include #include #include "types.h" #include "draw.h" #include "lua_inter.h" extern MapCollec mapcollec; int generate_coll(Game *game, int mapn){ LoadedMap *lmap = &game->map; Map *map = mapcollec.maps[mapn]; Machines *mach = &game->machines; memcpy(lmap->coll, map->layers[1], map->width*map->height); for(int i = 0; i < mach->machine_n; i++){ V2d pos = mach->machine_stack[i].pos; lmap->coll[(int)(pos.y * lmap->width + pos.x)] = 1; lmap->coll[(int)(pos.y * lmap->width + pos.x+1)] = 1; lmap->coll[(int)((pos.y+1) * lmap->width + pos.x)] = 1; lmap->coll[(int)((pos.y+1) * lmap->width + pos.x+1)] = 1; } return 0; } 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; nmap->coll = realloc(nmap->coll, map->width*map->height); if(!nmap->coll) return 1; if(generate_coll(game, mapn)) return 1; lua_onmapload(game, mapn); return 0; } void clean_map(Game *game){ free(game->map.coll); game->map.coll = NULL; }