From e61b20f024ce03bb0650393e2310602fa53731e1 Mon Sep 17 00:00:00 2001 From: Linus_Probert Date: Mon, 22 Jan 2018 10:12:44 +0100 Subject: [PATCH] Include CURRENT_LEVEL in lua script. --- .vimrc | 2 +- src/main.c | 5 +++-- src/map.h | 1 - src/map_lua.c | 5 ++++- src/map_lua.h | 2 +- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/.vimrc b/.vimrc index e44c008..08ce8a5 100644 --- a/.vimrc +++ b/.vimrc @@ -1,6 +1,6 @@ nnoremap :Make nnoremap :Make clean -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' ] diff --git a/src/main.c b/src/main.c index d7d592d..1dad567 100644 --- a/src/main.c +++ b/src/main.c @@ -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 }; } diff --git a/src/map.h b/src/map.h index 37ebbc1..f9b506a 100644 --- a/src/map.h +++ b/src/map.h @@ -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*); diff --git a/src/map_lua.c b/src/map_lua.c index 7ad326a..15c75cc 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -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", diff --git a/src/map_lua.h b/src/map_lua.h index a8e7096..302b83e 100644 --- a/src/map_lua.h +++ b/src/map_lua.h @@ -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_