Adds light tiles to layout files and a shopkeeper

Next step is to add game logic for shopkeeper murderers and
ability to take items after the shopkeeper is dead.
This commit is contained in:
Linus Probert 2019-03-07 20:06:04 +01:00
parent 447c1a773c
commit 3ba33d8852
5 changed files with 55 additions and 30 deletions

View File

@ -2,6 +2,7 @@ local random = map_random
local pits = {} local pits = {}
local walls = {} local walls = {}
local fences = {} local fences = {}
local lights = {}
local function readLayoutFile(file) local function readLayoutFile(file)
local layoutfile = read_file(file) local layoutfile = read_file(file)
@ -29,16 +30,29 @@ local function readLayoutFile(file)
return matrix; return matrix;
end end
local function getTileStateFor(matrix, i, j, c) local function has_value(list, char)
local above = matrix[i][j-1] == c; for _, value in ipairs(list) do
local below = matrix[i][j+1] == c; if value == char then return true end
local left = matrix[i-1][j] == c; end
local right = matrix[i+1][j] == c; return false
end
local above_left = matrix[i-1][j-1] == c; local function getTileStateFor(matrix, i, j, c)
local above_right = matrix[i+1][j-1] == c; local charList
local below_left = matrix[i-1][j+1] == c; if type(c) == "string" then
local below_right = matrix[i+1][j+1] == c; charList = { c }
else
charList = c
end
local above = has_value(charList, matrix[i][j-1])
local below = has_value(charList, matrix[i][j+1])
local left = has_value(charList, matrix[i-1][j])
local right = has_value(charList, matrix[i+1][j])
local above_left = has_value(charList, matrix[i-1][j-1])
local above_right = has_value(charList, matrix[i+1][j-1])
local below_left = has_value(charList, matrix[i-1][j+1])
local below_right = has_value(charList, matrix[i+1][j+1])
return above, below, left, right, above_left, above_right, below_left, below_right return above, below, left, right, above_left, above_right, below_left, below_right
end end
@ -115,6 +129,8 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
local t_pit1 = add_texture(map, "Objects/Pit1.png") local t_pit1 = add_texture(map, "Objects/Pit1.png")
local t_wall = add_texture(map, "Objects/Wall.png") local t_wall = add_texture(map, "Objects/Wall.png")
local t_fence = add_texture(map, "Objects/Fence.png") local t_fence = add_texture(map, "Objects/Fence.png")
local t_decor0 = add_texture(map, "Objects/Decor0.png")
local t_decor1 = add_texture(map, "Objects/Decor1.png")
local yo = (random(5) + random(3)) * (16 * 2) local yo = (random(5) + random(3)) * (16 * 2)
pits = { pits = {
@ -149,7 +165,7 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
bottom_t = { t_wall, nil, xo + 64, yo + 32, true }, bottom_t = { t_wall, nil, xo + 64, yo + 32, true },
} }
yo = 48 yo = 48 * random(3)
fences = { fences = {
topleft = { t_fence, nil, 0, yo, true }, topleft = { t_fence, nil, 0, yo, true },
top = { t_fence, nil, 16, yo, true }, top = { t_fence, nil, 16, yo, true },
@ -165,6 +181,11 @@ function module.load_textures(map, wall_xoffset, wall_yoffset)
right_t = { t_fence, nil, 80, yo + 16, true }, right_t = { t_fence, nil, 80, yo + 16, true },
bottom_t = { t_fence, nil, 64, yo + 32, true }, bottom_t = { t_fence, nil, 64, yo + 32, true },
} }
lights = {
candle0 = { t_decor0, t_decor1, 3 * 16, 8 * 16, true, true },
candle1 = { t_decor0, t_decor1, 1 * 16, 8 * 16, true, true }
}
end end
function draw_layout_to_room(room, matrix, roomx, roomy) function draw_layout_to_room(room, matrix, roomx, roomy)
@ -175,11 +196,16 @@ function draw_layout_to_room(room, matrix, roomx, roomy)
if matrix[i][j] == "p" then if matrix[i][j] == "p" then
setPitTile(room, matrix, i, j); setPitTile(room, matrix, i, j);
elseif matrix[i][j] == "#" then elseif matrix[i][j] == "#" then
setBlockTile(room, matrix, i, j, walls, "#", false) setBlockTile(room, matrix, i, j, walls, {"#", "\""}, false)
elseif matrix[i][j] == "\"" then
setBlockTile(room, matrix, i, j, walls, {"#", "\""}, false)
room.decor[i][j] = lights.candle1
elseif matrix[i][j] == "f" then elseif matrix[i][j] == "f" then
setBlockTile(room, matrix, i, j, fences, "f", true) setBlockTile(room, matrix, i, j, fences, "f", true)
elseif matrix[i][j] == "a" then elseif matrix[i][j] == "a" then
create_shop_artifact(map, (roomx*512) + i*32, (roomy * 384) + j*32) create_shop_artifact(map, (roomx*512) + i*32, (roomy * 384) + j*32)
elseif matrix[i][j] == "l" then
room.decor[i][j] = lights.candle0
end end
end end
end end

View File

@ -128,7 +128,7 @@ local function generate_path ()
for j=1,10 do for j=1,10 do
room = map_matrix[i][j] room = map_matrix[i][j]
if room then if room then
if roomCount > 3 and shopLevel and not shopAdded then if roomCount > 5 and shopLevel and not shopAdded then
room.type = "shop" room.type = "shop"
shopAdded = true shopAdded = true
end end
@ -138,6 +138,8 @@ local function generate_path ()
monster_gen.add_monsters_to_room(room, i-1, j-1) monster_gen.add_monsters_to_room(room, i-1, j-1)
trap_gen.add_traps_to_room(room, i-1, j-1) trap_gen.add_traps_to_room(room, i-1, j-1)
chest_gen.add_chests_to_room(room, i-1, j-1) chest_gen.add_chests_to_room(room, i-1, j-1)
else
monster_gen.add_shopkeeper_to_room(room, i-1, j-1)
end end
if roomCount > 3 and bossLevel and not bossAdded then if roomCount > 3 and bossLevel and not bossAdded then
bossAdded = true bossAdded = true

View File

@ -113,7 +113,7 @@ local stats = {
atk = 2, atk = 2,
def = 0, def = 0,
speed = 1 speed = 1
} },
} }
local function concat(table1, table2) local function concat(table1, table2)
@ -279,11 +279,11 @@ for i=1,#eastereggs do
end end
local shopkeeper = { local shopkeeper = {
texturePaths.humanoid0,
texturePaths.humanoid1, texturePaths.humanoid1,
texturePaths.humanoid2,
stats.shopkeeper, stats.shopkeeper,
12*16,
16, 16,
12*16,
"The Trader", "The Trader",
behaviour.passive behaviour.passive
} }

View File

@ -1,12 +1,12 @@
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++##ffffffff##++ ++##ffffffff##++
++##--------##++ ++#"--------"#++
++f---a--a---f++ ++f---a--a---f++
++-----------f++ ++-----------f++
++-----------f++ ++-----------f++
++f---a--a---f++ ++f---a--a---f++
++##--------##++ ++#"--------"#++
++##ffffffff##++ ++##ffffffff##++
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
@ -15,25 +15,25 @@
++++++++++++++++ ++++++++++++++++
++ffff----ffff++ ++ffff----ffff++
++fppf-a--fppf++ ++fppf-a--fppf++
++ffff----ffff++ ++ffff--l-ffff++
++------a-----++ ++------a-----++
++------------++ ++------------++
++ffff-a--ffff++ ++ffff-a--ffff++
++fppf----fppf++ ++fppf-l--fppf++
++ffff--a-ffff++ ++ffff--a-ffff++
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
++############++ ++###########"++
++#----------#++ ++#----------#++
++#-########-#++ ++#-####"###-#++
++--#aa--aa#-#++ ++--#aa--aa#-#++
++--#--------#++ ++--#--------#++
++#-########-#++ ++#-####"###-#++
++#----------#++ ++#----------#++
++############++ ++"###########++
++++++++++++++++ ++++++++++++++++
++++++++++++++++ ++++++++++++++++
@ -41,10 +41,10 @@
++++++++++++++++ ++++++++++++++++
++--pppppppp--++ ++--pppppppp--++
++--pffffffp--++ ++--pffffffp--++
++--pf---afp--++ ++--pfl--afp--++
++-------afp--++ ++-------afp--++
++-------afp--++ ++-------afp--++
++--pf---afp--++ ++--pfl--afp--++
++--pffffffp--++ ++--pffffffp--++
++--pppppppp--++ ++--pppppppp--++
++++++++++++++++ ++++++++++++++++
@ -55,8 +55,8 @@
++pppppppppppp++ ++pppppppppppp++
++ppffffffffpp++ ++ppffffffffpp++
++fffa----afff++ ++fffa----afff++
++------------++ ++------l-----++
++------------++ ++-----l------++
++fffa----afff++ ++fffa----afff++
++ppffffffffpp++ ++ppffffffffpp++
++pppppppppppp++ ++pppppppppppp++

View File

@ -350,9 +350,6 @@ startGame(void)
if (gPlayer) if (gPlayer)
player_destroy(gPlayer); player_destroy(gPlayer);
gPlayer = player_create(playerClass, gCamera); gPlayer = player_create(playerClass, gCamera);
#ifdef DEBUG
gPlayer->gold = 400;
#endif
mixer_play_music(GAME_MUSIC0 + get_random(2)); mixer_play_music(GAME_MUSIC0 + get_random(2));
resetGame(); resetGame();
skillbar_reset(gSkillBar); skillbar_reset(gSkillBar);