Include CURRENT_LEVEL in lua script.

This commit is contained in:
Linus_Probert 2018-01-22 10:12:44 +01:00
parent 38a584f418
commit e61b20f024
5 changed files with 9 additions and 6 deletions

2
.vimrc
View File

@ -1,6 +1,6 @@
nnoremap <F1> :Make<cr>
nnoremap <F2> :Make clean<cr>
au FileType c,h setl makeprg=ninja\ -C\ build
au FileType c,h setl makeprg=make\ -C\ build
let g:syntastic_c_include_dirs = [ 'build' ]

View File

@ -24,6 +24,7 @@ static RoomMatrix *gRoomMatrix = NULL;
static Gui *gGui = NULL;
static GameState gGameState;
static Camera gCamera;
static unsigned int cLevel = 1;
static
bool initSDL(void)
@ -93,7 +94,7 @@ static
bool initGame(void)
{
gSpriteList = linkedlist_create();
gMap = map_lua_generator_run(gRenderer);
gMap = map_lua_generator_run(cLevel, gRenderer);
return gSpriteList == NULL;
}
@ -155,7 +156,7 @@ check_next_level(void)
if (tile->levelExit) {
printf("[**] Building new map\n");
map_destroy(gMap);
gMap = map_lua_generator_run(gRenderer);
gMap = map_lua_generator_run(++cLevel, gRenderer);
gPlayer->sprite->pos = (Position) {
TILE_DIMENSION, TILE_DIMENSION };
}

View File

@ -40,7 +40,6 @@ typedef struct Map_t {
Map* map_create(void);
int map_add_texture(Map*, const char *path, SDL_Renderer*);
void map_add_tile(Map *map, Position *tile_pos, MapTile*);

View File

@ -214,7 +214,7 @@ l_add_monster(lua_State *L)
return 0;
}
Map* map_lua_generator_run(SDL_Renderer *renderer)
Map* map_lua_generator_run(unsigned int level, SDL_Renderer *renderer)
{
int status, result;
char file[] = "data/mapgen.lua";
@ -251,6 +251,9 @@ Map* map_lua_generator_run(SDL_Renderer *renderer)
lua_pushcfunction(L, l_add_monster);
lua_setglobal(L, "add_monster");
lua_pushinteger(L, level);
lua_setglobal(L, "CURRENT_LEVEL");
result = lua_pcall(L, 0, LUA_MULTRET, 0);
if (result) {
fprintf(stderr, "[!!] Failed to run script: %s\n",

View File

@ -3,6 +3,6 @@
#include "map.h"
Map* map_lua_generator_run(SDL_Renderer *renderer);
Map* map_lua_generator_run(unsigned int level, SDL_Renderer *renderer);
#endif // MAP_LUA_H_