From c19fb67279342326b92910791174adf289a42c24 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Tue, 30 Jan 2018 21:05:33 +0100 Subject: [PATCH] WASD movement and more logical monsters in levels. --- data/monstergen.lua | 42 ++++++++++++++++++++++++++++++++++++++++-- src/map_lua.c | 2 +- src/player.c | 4 ++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/data/monstergen.lua b/data/monstergen.lua index 47817dd..ee45f54 100644 --- a/data/monstergen.lua +++ b/data/monstergen.lua @@ -43,8 +43,7 @@ local state = { scared = 2, } -local enemies = { - +local pests = { -- PESTS { texturePaths.pest0, texturePaths.pest1, 0, 0, "A Beetle" }, { texturePaths.pest0, texturePaths.pest1, 16, 0, "A Beetle" }, @@ -93,7 +92,9 @@ local enemies = { --{ texturePaths.pest0, texturePaths.pest1, 16, 112 }, --{ texturePaths.pest0, texturePaths.pest1, 32, 112 }, --{ texturePaths.pest0, texturePaths.pest1, 48, 112 }, +} +local undead = { -- UNDEAD --{ texturePaths.undead0, texturePaths.undead1, 0, 0, "", state.passive, state.agressive }; --{ texturePaths.undead0, texturePaths.undead1, 16, 0, "", state.passive, state.agressive }; @@ -123,6 +124,24 @@ local enemies = { --{ texturePaths.undead0, texturePaths.undead1, 112, 32, "", state.passive, state.scared }; } +local demon = { + { texturePaths.demon0, texturePaths.demon1, 0, 0, "A Demon", state.agressive, state.agressive }; + { texturePaths.demon0, texturePaths.demon1, 16, 0, "A Demon", state.agressive, state.agressive }; + { texturePaths.demon0, texturePaths.demon1, 32, 0, "A Demon", state.agressive, state.agressive }; + { texturePaths.demon0, texturePaths.demon1, 48, 0, "A Demon", state.agressive, state.agressive }; + { texturePaths.demon0, texturePaths.demon1, 64, 0, "A Demon", state.agressive, state.agressive }; + { texturePaths.demon0, texturePaths.demon1, 80, 0, "A Demon", state.agressive, state.agressive }; + { texturePaths.demon0, texturePaths.demon1, 96, 0, "A Demon", state.agressive, state.agressive }; + { texturePaths.demon0, texturePaths.demon1, 112, 0, "A Demon", state.agressive, state.agressive }; +} + +local function concat(table1, table2) + for i=0,#table2 do + table1[#table1+1] = table2[i] + end + return table1 +end + local function repack(data) return { texturePath1 = data[1], @@ -135,6 +154,25 @@ local function repack(data) } end +-- Begin script +local enemies = {} +print("Current level: " .. CURRENT_LEVEL) +if(CURRENT_LEVEL > 0 and CURRENT_LEVEL < 10) then + if (CURRENT_LEVEL == 1) then + enemies = concat(enemies, pests) + enemies = concat(enemies, undead) + elseif (CURRENT_LEVEL > 2) then + enemies = {} + enemies = concat(enemies, undead) + enemies = concat(enemies, demon) + elseif (CURRENT_LEVEL > 1) then + enemies = {} + enemies = concat(enemies, undead) + end +end + +print("Enemies: " .. #enemies) + function module.add_monster_to_room(map, roomx, roomy) local count = random(3) for i=0,count do diff --git a/src/map_lua.c b/src/map_lua.c index 1caf232..86d569b 100644 --- a/src/map_lua.c +++ b/src/map_lua.c @@ -22,7 +22,7 @@ static int l_create_map(lua_State *L) { Map *map = map_create(); - map->level = luaL_checkinteger(L, 1); + map->level = (int) luaL_checkinteger(L, 1); lua_pushlightuserdata(L, map); return 1; } diff --git a/src/player.c b/src/player.c index db4c272..3a3a76f 100644 --- a/src/player.c +++ b/src/player.c @@ -151,18 +151,22 @@ void handle_player_input(Player *player, RoomMatrix *matrix, SDL_Event *event) switch (event->key.keysym.sym) { case SDLK_LEFT: case SDLK_h: + case SDLK_a: move_left(player, matrix); break; case SDLK_RIGHT: case SDLK_l: + case SDLK_d: move_right(player, matrix); break; case SDLK_UP: case SDLK_k: + case SDLK_w: move_up(player, matrix); break; case SDLK_DOWN: case SDLK_j: + case SDLK_s: move_down(player, matrix); break; }