This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
include.lua
155 lines (125 loc) · 3.72 KB
/
include.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
gSegment = {}
gLastSegment = 0
gTotalProb = 0.0
function confSegment(name, prob, times)
times = times or 1000
gSegment[#gSegment+1] = {name, prob, times, 0}
gTotalProb = gTotalProb + prob
end
function nextSegment()
s = 0
if #gSegment == 1 then
return gSegment[1][1]
end
repeat
p = 0.0
r = mgRndFloat(0, 1)
for i=1, #gSegment do
p = p + gSegment[i][2]/gTotalProb
if p > r then
if i == gLastSegment or gSegment[i][4] == gSegment[i][3] then
break
else
s = i
break
end
end
end
until s > 0
gLastSegment = s
gSegment[s][4] = gSegment[s][4] + 1
return gSegment[s][1]
end
-- Knot126's LiveSegment Additions
-- Put your package name here!!!
PACKAGE_NAME = "org.knot126.smashhit.oinmg"
function Segment_vecToString(v)
return tostring(v[1]) .. " " .. tostring(v[2]) .. " " .. tostring(v[3])
end
function Segment_vec2ToString(v)
return tostring(v[1]) .. " " .. tostring(v[2])
end
function Segment_box(segment, position, size, colour)
segment.file:write('<box pos="' .. Segment_vecToString(position) .. '" size="' .. Segment_vecToString(size) .. '"/>')
segment.file:write('<obstacle type="stone" pos="' .. Segment_vecToString(position) .. '" param0="color=' .. Segment_vecToString(colour) .. '" param1="sizeX=' .. tostring(size[1]) .. '" param2="sizeY=' .. tostring(size[2]) .. '" param3="sizeZ=' .. tostring(size[3]) .. '" />')
end
function Segment_obstacle(segment, position, kind, params)
segment.file:write('<obstacle ')
segment.file:write('pos="' .. Segment_vecToString(position) .. '" ')
segment.file:write('type="' .. kind .. '" ')
local i = 0
for k, v in pairs(params) do
segment.file:write('param' .. tostring(i) .. '="' .. k .. '=' .. v .. '" ')
i = i + 1
end
segment.file:write('/>')
end
function Segment_decal(segment, position, tile, size, colour)
segment.file:write('<decal ')
segment.file:write('pos="' .. Segment_vecToString(position) .. '" ')
segment.file:write('tile="' .. tostring(tile) .. '" ')
if size ~= nil then
segment.file:write('size="' .. Segment_vec2ToString(size) .. '" ')
end
if colour ~= nil then
segment.file:write('color="' .. Segment_vecToString(colour) .. '" ')
end
segment.file:write('/>')
end
function Segment_powerup(segment, position, kind)
segment.file:write('<powerup ')
segment.file:write('pos="' .. Segment_vecToString(position) .. '" ')
segment.file:write('type="' .. kind .. '" ')
segment.file:write('/>')
end
function Segment_water(segment, position, size)
segment.file:write('<water ')
segment.file:write('pos="' .. Segment_vecToString(position) .. '" ')
segment.file:write('size="' .. Segment_vec2ToString(size) .. '" ')
segment.file:write('/>')
end
function Segment_done(segment)
segment.file:write('</segment>')
segment.file:close()
end
function Segment_path(segment)
return "user://" .. segment.name
end
function Segment(name, length)
if io == nil then
return
end
-- Set up structure
local segment = {}
segment.file = io.open("/data/data/" .. PACKAGE_NAME .. "/files/" .. name .. ".xml", "w")
segment.name = name
segment.size = {12.0, 10.0, length}
-- Initial segment data
segment.file:write('<segment size="' .. Segment_vecToString(segment.size) .. '">')
-- Functions
segment.box = Segment_box
segment.obstacle = Segment_obstacle
segment.decal = Segment_decal
segment.powerup = Segment_powerup
segment.water = Segment_water
segment.done = Segment_done
segment.path = Segment_path
return segment
end
function pumpSegments(targetLen)
l = 0
while l < targetLen do
s = nextSegment()
l = l + mgSegment(s, -l)
end
mgLength(l)
end
function beginRoom(length)
room = Segment("default", length)
room_length = length
end
function endRoom()
room:done()
mgSegment(room:path(), 0)
mgLength(room_length)
end