Skip to content
Snippets Groups Projects
Commit 1b236d5b authored by dg's avatar dg
Browse files

fractal forest

git-svn-id: http://svn.net-core.org/repos/t-engine4@255 51575b47-30f0-44d4-a5cc-537603b46e54
parent 134aa9b8
No related branches found
No related tags found
No related merge requests found
......@@ -8,12 +8,16 @@ module(..., package.seeall, class.make)
tiles = engine.Tiles.new(16, 16)
--- Requests a simple, press any key, dialog
function _M:simplePopup(title, text, fct)
function _M:simplePopup(title, text, fct, no_leave)
local font = core.display.newFont("/data/font/Vera.ttf", 12)
local w, h = font:size(text)
local d = new(title, w + 8, h + 25, nil, nil, nil, font)
d:keyCommands{__DEFAULT=function() game:unregisterDialog(d) if fct then fct() end end}
d:mouseZones{{x=0, y=0, w=game.w, h=game.h, fct=function(b) if b ~= "none" then game:unregisterDialog(d) if fct then fct() end end end, norestrict=true}}
if no_leave then
d:keyCommands{}
else
d:keyCommands{__DEFAULT=function() game:unregisterDialog(d) if fct then fct() end end}
d:mouseZones{{x=0, y=0, w=game.w, h=game.h, fct=function(b) if b ~= "none" then game:unregisterDialog(d) if fct then fct() end end end, norestrict=true}}
end
d.drawDialog = function(self, s)
s:drawColorStringCentered(self.font, text, 2, 2, self.iw - 2, self.ih - 2)
end
......
......@@ -8,11 +8,12 @@ _M.max = 100000
_M.min = 0
--- Creates the fractal generator for the specified heightmap size
function _M:init(w, h, roughness)
function _M:init(w, h, roughness, start)
self.w = w
self.h = h
self.roughness = roughness or 1.2
self.hmap = {}
self.start = start or {}
print("Making heightmap", w, h)
......@@ -30,23 +31,11 @@ function _M:generate()
local rects = {}
-- Init the four corners
-- self.hmap[1][1] = rng.range(self.min, self.max / 10)
-- self.hmap[1][self.h] = rng.range(self.min, self.max / 10)
-- self.hmap[self.w][1] = rng.range(self.min, self.max / 10)
-- self.hmap[self.w][self.h] = rng.range(self.min, self.max / 10)
-- self.hmap[1][1] = rng.range(self.min, self.max)
-- self.hmap[1][self.h] = rng.range(self.min, self.max)
-- self.hmap[self.w][1] = rng.range(self.min, self.max)
-- self.hmap[self.w][self.h] = rng.range(self.min, self.max)
-- self.hmap[1][1] = 0
-- self.hmap[1][self.h] = 0
-- self.hmap[self.w][1] = 0
-- self.hmap[self.w][self.h] = 0
self.hmap[1][1] = self.max
self.hmap[1][self.h] = self.max
self.hmap[self.w][1] = self.max
self.hmap[self.w][self.h] = self.max
rects[#rects+1] = {1, 1, self.w, self.h, force_middle=0}
self.hmap[1][1] = self.start.up_left or rng.range(self.min, self.max)
self.hmap[1][self.h] = self.start.down_left or rng.range(self.min, self.max)
self.hmap[self.w][1] = self.start.up_right or rng.range(self.min, self.max)
self.hmap[self.w][self.h] = self.start.down_right or rng.range(self.min, self.max)
rects[#rects+1] = {1, 1, self.w, self.h, force_middle=self.start.middle}
-- While we have subzones to handle, handle them
while #rects > 0 do
......
require "engine.class"
local Dialog = require "engine.Dialog"
--- Savefile code
-- T-Engine4 savefiles are direct serialization of in game objects<br/>
......@@ -83,12 +84,17 @@ function _M:saveGame(game)
self:saveObject(game, zip)
zip:close()
local popup = Dialog:simplePopup("Saving game", "Please wait while saving the game...")
core.display.forceRedraw()
local desc = game:getSaveDescription()
local f = fs.open(self.save_dir.."desc.lua", "w")
f:write(("name = %q\n"):format(desc.name))
f:write(("short_name = %q\n"):format(self.short_name))
f:write(("description = %q\n"):format(desc.description))
f:close()
game:unregisterDialog(popup)
end
--- Save a level
......@@ -141,6 +147,9 @@ function _M:loadGame()
fs.mount(path, self.load_dir)
local popup = Dialog:simplePopup("Loading game", "Please wait while loading the game...")
core.display.forceRedraw()
local loadedGame = self:loadReal("main")
-- Delay loaded must run
......@@ -150,6 +159,9 @@ function _M:loadGame()
end
fs.umount(path)
game:unregisterDialog(popup)
return loadedGame
end
......
......@@ -48,15 +48,6 @@ key:setCurrent()
-- Load the game module
game = false
require "engine.Heightmap"
do
local f = engine.Heightmap.new(10,10,3.5)
f:generate()
f:displayDebug(" #")
os.exit()
end
engine.Game:setResolution(config.settings.window.size)
util.showMainMenu()
local Heightmap = require "engine.Heightmap"
return function(gen, id)
local w = rng.range(5, 12)
local h = rng.range(5, 12)
return { name="forest_clearing"..w.."x"..h, w=w, h=h, generator = function(self, x, y, is_lit)
-- make the fractal heightmap
local hm = Heightmap.new(self.w, self.h, 2, {middle=Heightmap.min, up_left=Heightmap.max, down_left=Heightmap.max, up_right=Heightmap.max, down_right=Heightmap.max})
hm:generate()
for i = 1, self.w do
for j = 1, self.h do
if i == 1 or i == self.w or j == 1 or j == self.h then
if hm.hmap[i][j] >= Heightmap.max * 5 / 6 then
gen.room_map[i-1+x][j-1+y].can_open = true
gen.map(i-1+x, j-1+y, Map.TERRAIN, gen.grid_list[gen:resolve('#')])
else
......
load("/data/general/npcs/baer.lua")
load("/data/general/npcs/bear.lua")
load("/data/general/npcs/vermin.lua")
load("/data/general/npcs/wolf.lua")
load("/data/general/npcs/snake.lua")
......
......@@ -12,7 +12,7 @@ return {
class = "engine.generator.map.Roomer",
nb_rooms = 10,
edge_entrances = {6,4},
rooms = {"simple", "pilar"},
rooms = {"forest_clearing"},
['.'] = "GRASS_DARK1",
['#'] = "TREE_DARK1",
up = "UP",
......
......@@ -12,7 +12,7 @@ return {
class = "engine.generator.map.Roomer",
nb_rooms = 10,
edge_entrances = {4,6},
rooms = {"simple", "pilar"},
rooms = {"forest_clearing"},
['.'] = function() if rng.chance(20) then return "FLOWER" else return "GRASS" end end,
['#'] = "TREE",
up = "UP",
......
......@@ -547,7 +547,7 @@ static void draw_textured_quad(int x, int y, int w, int h) {
while (realw < w) realw *= 2;
while (realh < h) realh *= 2;
GLfloat texw = (GLfloat)w/realw;
GLfloat texh = (GLfloat)h/realh;
......@@ -747,8 +747,16 @@ static int sdl_set_window_size(lua_State *L)
return 1;
}
extern void on_redraw();
static int sdl_redraw_screen(lua_State *L)
{
on_redraw();
return 0;
}
static const struct luaL_reg displaylib[] =
{
{"forceRedraw", sdl_redraw_screen},
{"fullscreen", sdl_fullscreen},
{"size", sdl_screen_size},
{"newFont", sdl_new_font},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment