add /apps/demos/crawl
This commit is contained in:
parent
6eb0730c52
commit
bd3b090f6f
24
apps/demos/crawl/data/levels/00.lvl
Normal file
24
apps/demos/crawl/data/levels/00.lvl
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
@map
|
||||||
|
-- Grid of entities defined by @classes.
|
||||||
|
#####
|
||||||
|
#.@.#
|
||||||
|
#...#
|
||||||
|
##.##
|
||||||
|
#...#
|
||||||
|
#...#
|
||||||
|
#####
|
||||||
|
|
||||||
|
|
||||||
|
@classes
|
||||||
|
-- Defines classes under symbols, which could have properties.
|
||||||
|
# wall
|
||||||
|
. void
|
||||||
|
test : this
|
||||||
|
@ player_spawn
|
||||||
|
unique :
|
||||||
|
face : south
|
||||||
|
hold : torch
|
||||||
|
|
||||||
|
@meta
|
||||||
|
-- Arbitrary sections could be defined with values pairs.
|
||||||
|
description : Test Level! Just two square rooms.
|
83
apps/demos/crawl/data/scripts/game.lua
Normal file
83
apps/demos/crawl/data/scripts/game.lua
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
require("string")
|
||||||
|
|
||||||
|
function load_level(file)
|
||||||
|
local f = file_read { file = file }
|
||||||
|
|
||||||
|
local result = {
|
||||||
|
classes = {},
|
||||||
|
glossary = {},
|
||||||
|
grid = {},
|
||||||
|
map = {},
|
||||||
|
}
|
||||||
|
|
||||||
|
-- iterate over lines
|
||||||
|
local section, subsection = "none", "none"
|
||||||
|
local from = 1
|
||||||
|
local start, limit = string.find(f, "\n", from)
|
||||||
|
while start do
|
||||||
|
local line = string.sub(f, from, start - 1)
|
||||||
|
-- skip over
|
||||||
|
if #line == 0 or line:find("^%-%-%s*") then
|
||||||
|
goto skip
|
||||||
|
-- start new section
|
||||||
|
elseif line:find("^@%a+") then
|
||||||
|
section = line:sub(2); subsection = "none"
|
||||||
|
-- decode map one line at a time
|
||||||
|
elseif section == "map" then
|
||||||
|
local l = #result.map + 1
|
||||||
|
result.map[l] = {}
|
||||||
|
for i = 1, #line do
|
||||||
|
result.map[l][i] = line:sub(i,i)
|
||||||
|
end
|
||||||
|
assert(#result.map[1] == #result.map[l])
|
||||||
|
-- templates to expand
|
||||||
|
elseif section == "classes" then
|
||||||
|
-- properties
|
||||||
|
if line:find("^ %a+") then
|
||||||
|
local _, _, property, value = line:find("^ (%a+)%s?:%s?(.*)")
|
||||||
|
result.classes[subsection][property] = value
|
||||||
|
goto skip
|
||||||
|
end
|
||||||
|
local symbol, classname = line:sub(1,1), line:sub(3)
|
||||||
|
result.classes[classname] = {
|
||||||
|
symbol = symbol,
|
||||||
|
}
|
||||||
|
result.glossary[symbol] = classname
|
||||||
|
subsection = classname
|
||||||
|
elseif section ~= "none" then
|
||||||
|
local _, _, property, value = line:find("^(%a+)%s?:%s?(.*)")
|
||||||
|
if result[section] == nil then
|
||||||
|
result[section] = {}
|
||||||
|
end
|
||||||
|
result[section][property] = value
|
||||||
|
end
|
||||||
|
::skip::
|
||||||
|
from = limit + 1
|
||||||
|
start, limit = string.find(f, "\n", from)
|
||||||
|
end
|
||||||
|
-- post process
|
||||||
|
for y = 1, #result.map do
|
||||||
|
result.grid[y] = {}
|
||||||
|
for x = 1, #result.map[y] do
|
||||||
|
local class = result.classes[result.glossary[result.map[y][x]]]
|
||||||
|
if class["unique"] ~= nil then
|
||||||
|
class.position = { x = x, y = y }
|
||||||
|
end
|
||||||
|
result.grid[y][x] = class
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
print(result.meta.description)
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function game_tick()
|
||||||
|
if ctx.udata == nil then
|
||||||
|
ctx.udata = {
|
||||||
|
level = load_level("levels/00.lvl")
|
||||||
|
}
|
||||||
|
log_vec2 { value = ctx.udata.level.classes.player_spawn.position }
|
||||||
|
end
|
||||||
|
end
|
27
apps/demos/crawl/data/twn.toml
Normal file
27
apps/demos/crawl/data/twn.toml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# This file contains everything about the engine and your game that can be
|
||||||
|
# configured before it runs.
|
||||||
|
#
|
||||||
|
# Optional settings are commented out, with their default values shown.
|
||||||
|
# Invalid values in these settings will be ignored.
|
||||||
|
|
||||||
|
# Data about your game as an application
|
||||||
|
[about]
|
||||||
|
title = "Template"
|
||||||
|
developer = "You"
|
||||||
|
app_id = "template"
|
||||||
|
dev_id = "you"
|
||||||
|
|
||||||
|
# Game runtime details
|
||||||
|
[game]
|
||||||
|
resolution = [ 640, 480 ]
|
||||||
|
interpreter = "$TWNROOT/apps/twnlua"
|
||||||
|
#debug = true
|
||||||
|
|
||||||
|
# Engine tweaks. You probably don't need to change these
|
||||||
|
[engine]
|
||||||
|
#ticks_per_second = 60 # minimum of 8
|
||||||
|
#keybind_slots = 3 # minimum of 1
|
||||||
|
#texture_atlas_size = 2048 # minimum of 32
|
||||||
|
#font_texture_size = 2048 # minimum of 1024
|
||||||
|
#font_oversampling = 4 # minimum of 0
|
||||||
|
#font_filtering = "linear" # possible values: "nearest", "linear"
|
Loading…
Reference in New Issue
Block a user