Include CURRENT_LEVEL in lua script.
This commit is contained in:
parent
38a584f418
commit
e61b20f024
2
.vimrc
2
.vimrc
|
@ -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' ]
|
||||
|
|
|
@ -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 };
|
||||
}
|
||||
|
|
|
@ -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*);
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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_
|
||||
|
|
Loading…
Reference in New Issue