-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.lua
104 lines (104 loc) · 2.42 KB
/
generator.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
function generate(width,offset,offsetMean,oldLine,timePassed)
if timePassed==nil then
timePassed=0
end
permaW=width
permaO=offset
permaM=offsetMean
local edge = true
local line = {}
success=false
local inc = 0
while success == false do
newOffset = love.math.randomNormal( 1, offsetMean )
if newOffset >0 then
newOffset = math.ceil(newOffset)
else
newOffset=math.floor(newOffset)
end
width = love.math.randomNormal( .5, width )
while width>5 or width<.5 do
width = love.math.randomNormal( .5, width )
end
while math.abs(newOffset)>10 do
newOffset = love.math.randomNormal( 1, offsetMean )
if newOffset >0 then
newOffset = math.ceil(newOffset)
else
newOffset=math.floor(newOffset)
end
end
local offset=newOffset
for x=-15,15 do
if x ~= offset then
line[x]=math.floor(math.log((math.abs(x-offset))/width))
if line[x]>1 then
line[x]=1
elseif line[x]<0 then
line[x]=0
end
--Check if tile is at the edge of floor tiles
if (math.floor(math.log(math.abs((x+1-offset)/width)))==0 or math.log(math.abs((x+1-offset)/width))<0) and edge==true then
line[x]=2
if love.math.random(1, 100)<=math.ceil(10/(1+math.exp(-timePassed/100))-5) then
line[x]=4
end
edge=false
elseif (math.floor(math.log((math.abs(x+1-offset))/width))==1 or math.floor(math.log((math.abs(x+1-offset))/width))>1) and edge==false then
line[x]=3
if love.math.random(1, 100)<=math.ceil(10/(1+math.exp(-timePassed/100))-5) then
line[x]=5
end
edge=true
elseif line[x]<0 then
line[x]=0
end
else
line[x]=0
end
end
if line[15] == 0 then
line[15]=3
if love.math.random(1, 100)<=math.ceil(10/(1+math.exp(-timePassed/100))-5) then
line[15]=5
end
elseif line[-15]==0 then
line[-15]=2
if love.math.random(1, 100)<=math.ceil(10/(1+math.exp(-timePassed/100))-5) then
line[15]=4
end
end
if oldLine~=nil then
for i=-15,15 do
if oldLine[i]==0 and line[i]==0 then
success=true
end
end
else
success=true
end
if success==false then
inc=inc+1
width=permaW
offset=permaO
offsetMean=permaM
end
if inc>3 then
success=true
end
end
return width, newOffset, line
end
function updateMap(map,line)
local v=0
for row=1,22 do
for x=-15,15 do
v=map:getTile(x+16,row+1)
map:setTile(x+16,row,v)
end
end
for x=-15,15 do
map:setTile(x+16,23,line[x]+1)
end
return map
end