-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
127 additions
and
117 deletions.
There are no files selected for viewing
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
local division = require "pcg.algorithms.division" | ||
local scut = require "themes.scut" | ||
local pcg_map = require "pcg.map" | ||
local tiles = require "pcg.tiles" | ||
|
||
local LAYER_LEVEL = hash("level") | ||
local LAYER_SHADOWS = hash("shadow") | ||
|
||
function init(self) | ||
math.randomseed(os.time()) math.random() | ||
msg.post(".", "acquire_input_focus") | ||
msg.post("#", "generate") | ||
end | ||
|
||
|
||
function on_input(self, action_id, action) | ||
if action_id == hash("generate") and action.released then | ||
msg.post("#", "generate") | ||
end | ||
end | ||
|
||
|
||
function on_message(self, message_id, message, sender) | ||
if message_id == hash("generate") then | ||
local map = pcg_map.create("#map", { LAYER_LEVEL, LAYER_SHADOWS }) | ||
map.clear(LAYER_LEVEL) | ||
map.clear(LAYER_SHADOWS) | ||
map.fill(LAYER_LEVEL, tiles.WALL) | ||
division.divide(map, LAYER_LEVEL, { | ||
floor = tiles.FLOOR, | ||
wall = tiles.WALL, | ||
door = tiles.FLOOR, | ||
wall_thickness = 2, | ||
}) | ||
scut.apply(map, LAYER_LEVEL, LAYER_SHADOWS) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
local tiles = require "pcg.tiles" | ||
|
||
local M = {} | ||
|
||
|
||
|
||
function M.divide(map, layer, config) | ||
assert(map, "You must provide a map") | ||
assert(layer, "You must provide a layer") | ||
|
||
config = config or {} | ||
config.floor = config.floor or tiles.FLOOR | ||
config.wall = config.wall or tiles.WALL | ||
config.door = config.door or tiles.DOOR | ||
config.wall_thickness = config.wall_thickness or 1 | ||
|
||
pprint(config) | ||
|
||
local FLOOR = config.floor | ||
local WALL = config.wall | ||
local DOOR = config.door | ||
|
||
local threshold = config.wall_thickness + 1 | ||
local divide_horisontal | ||
local divide_vertical | ||
divide_horisontal = function(x, y, w, h) | ||
local ratio = math.random(2, 8) / 10 | ||
local w1 = math.floor(w * ratio) | ||
local w2 = w - 1 - w1 | ||
if w1 >= threshold and w2 >= threshold then | ||
map.fill(layer, FLOOR, x, y, w1, h) -- left area | ||
map.fill(layer, FLOOR, x + w1 + 1, y, w2, h) -- right area | ||
|
||
divide_vertical(x, y, w1, h) | ||
divide_vertical(x + w1 + 1, y, w2, h) | ||
|
||
map.fill(layer, WALL, x + w1, y, config.wall_thickness, h) -- separator wall | ||
|
||
|
||
local dx = x + w1 | ||
local dy = math.random(y, y + h - 1) | ||
map.fill(layer, DOOR, dx, dy, 1, config.wall_thickness) -- door | ||
map.fill(layer, FLOOR, dx - 1, dy, 1, config.wall_thickness) -- floor next to door | ||
map.fill(layer, FLOOR, dx + 1, dy, 1, config.wall_thickness) -- floor next to door | ||
end | ||
end | ||
|
||
divide_vertical = function(x, y, w, h) | ||
local ratio = math.random(2, 8) / 10 | ||
local h1 = math.floor(h * ratio) | ||
local h2 = h - 1 - h1 | ||
if h1 >= threshold and h2 >= threshold then | ||
map.fill(layer, FLOOR, x, y, w, h1) -- bottom area | ||
map.fill(layer, FLOOR, x, y + h1 + 1, w, h2) -- top area | ||
|
||
divide_horisontal(x, y, w, h1) | ||
divide_horisontal(x, y + h1 + 1, w, h2) | ||
|
||
map.fill(layer, WALL, x, y + h1, w, config.wall_thickness) -- separator wall | ||
|
||
local dx = math.random(x, x + w - 1) | ||
local dy = y + h1 | ||
map.fill(layer, DOOR, dx, dy, config.wall_thickness, 1) -- door | ||
map.fill(layer, FLOOR, dx, dy - 1, config.wall_thickness, 1) -- floor next to door | ||
map.fill(layer, FLOOR, dx, dy + 1, config.wall_thickness, 1) -- floor next to door | ||
end | ||
end | ||
|
||
divide_horisontal(map.x + 1, map.y + 1, map.w - 2, map.h - 2) | ||
end | ||
|
||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ local M = {} | |
|
||
M.WALL = 0 | ||
M.FLOOR = 1 | ||
M.DOOR = 2 | ||
|
||
return M |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters