WASD movement and more logical monsters in levels.

This commit is contained in:
Linus Probert 2018-01-30 21:05:33 +01:00
parent a479c6fbee
commit c19fb67279
3 changed files with 45 additions and 3 deletions

View File

@ -43,8 +43,7 @@ local state = {
scared = 2, scared = 2,
} }
local enemies = { local pests = {
-- PESTS -- PESTS
{ texturePaths.pest0, texturePaths.pest1, 0, 0, "A Beetle" }, { texturePaths.pest0, texturePaths.pest1, 0, 0, "A Beetle" },
{ texturePaths.pest0, texturePaths.pest1, 16, 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, 16, 112 },
--{ texturePaths.pest0, texturePaths.pest1, 32, 112 }, --{ texturePaths.pest0, texturePaths.pest1, 32, 112 },
--{ texturePaths.pest0, texturePaths.pest1, 48, 112 }, --{ texturePaths.pest0, texturePaths.pest1, 48, 112 },
}
local undead = {
-- UNDEAD -- UNDEAD
--{ texturePaths.undead0, texturePaths.undead1, 0, 0, "", state.passive, state.agressive }; --{ texturePaths.undead0, texturePaths.undead1, 0, 0, "", state.passive, state.agressive };
--{ texturePaths.undead0, texturePaths.undead1, 16, 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 }; --{ 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) local function repack(data)
return { return {
texturePath1 = data[1], texturePath1 = data[1],
@ -135,6 +154,25 @@ local function repack(data)
} }
end 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) function module.add_monster_to_room(map, roomx, roomy)
local count = random(3) local count = random(3)
for i=0,count do for i=0,count do

View File

@ -22,7 +22,7 @@ static
int l_create_map(lua_State *L) int l_create_map(lua_State *L)
{ {
Map *map = map_create(); Map *map = map_create();
map->level = luaL_checkinteger(L, 1); map->level = (int) luaL_checkinteger(L, 1);
lua_pushlightuserdata(L, map); lua_pushlightuserdata(L, map);
return 1; return 1;
} }

View File

@ -151,18 +151,22 @@ void handle_player_input(Player *player, RoomMatrix *matrix, SDL_Event *event)
switch (event->key.keysym.sym) { switch (event->key.keysym.sym) {
case SDLK_LEFT: case SDLK_LEFT:
case SDLK_h: case SDLK_h:
case SDLK_a:
move_left(player, matrix); move_left(player, matrix);
break; break;
case SDLK_RIGHT: case SDLK_RIGHT:
case SDLK_l: case SDLK_l:
case SDLK_d:
move_right(player, matrix); move_right(player, matrix);
break; break;
case SDLK_UP: case SDLK_UP:
case SDLK_k: case SDLK_k:
case SDLK_w:
move_up(player, matrix); move_up(player, matrix);
break; break;
case SDLK_DOWN: case SDLK_DOWN:
case SDLK_j: case SDLK_j:
case SDLK_s:
move_down(player, matrix); move_down(player, matrix);
break; break;
} }