Go で書き直した Ikemen
Revisão | 7337d5b015d2461714203001c68fc134dfea9645 (tree) |
---|---|
Hora | 2016-11-25 00:12:33 |
Autor | SUEHIRO <supersuehiro@user...> |
Commiter | SUEHIRO |
エラーが出たところから順番に実装していくことにした
@@ -1,3 +1,5 @@ | ||
1 | +/chars | |
1 | 2 | /data |
2 | 3 | /go |
3 | 4 | /sound |
5 | +/stages |
@@ -0,0 +1,108 @@ | ||
1 | + | |
2 | +addHotkey('c', true, false, false, 'toggleClsnDraw()') | |
3 | +addHotkey('d', true, false, false, 'toggleDebugDraw()') | |
4 | +addHotkey('s', true, false, false, 'changeSpeed()') | |
5 | +addHotkey('l', true, false, false, 'toggleStatusDraw()') | |
6 | +addHotkey('1', true, false, false, 'toggleAI(1)') | |
7 | +addHotkey('2', true, false, false, 'toggleAI(2)') | |
8 | +addHotkey('3', true, false, false, 'toggleAI(3)') | |
9 | +addHotkey('4', true, false, false, 'toggleAI(4)') | |
10 | +addHotkey('F1', false, false, false, 'kill(2);kill(4)') | |
11 | +addHotkey('F1', true, false, false, 'kill(1);kill(3)') | |
12 | +addHotkey('F2', false, false, false, 'kill(1,1);kill(2,1);kill(3,1);kill(4,1)') | |
13 | +addHotkey('F2', true, false, false, 'kill(1,1);kill(3,1)') | |
14 | +addHotkey('F2', false, false, true, 'kill(2,1);kill(4,1)') | |
15 | +addHotkey('F3', false, false, false, 'powMax(1);powMax(2)') | |
16 | +addHotkey('F4', false, false, false, 'roundReset()') | |
17 | +addHotkey('F4', false, false, true, 'reload()') | |
18 | +addHotkey('F5', false, false, false, 'setTime(0)') | |
19 | +addHotkey( | |
20 | + 'SPACE', false, false, false, | |
21 | + 'full(1);full(2);full(3);full(4);setTime(getRoundTime())') | |
22 | +addHotkey('PAUSE', false, false, false, 'togglePause()') | |
23 | +addHotkey('SCROLLLOCK', false, false, false, 'step()') | |
24 | +addHotkey('i', true, false, false, 'stand(1);stand(2);stand(3);stand(4)') | |
25 | + | |
26 | + | |
27 | +speed = 1.0 | |
28 | + | |
29 | +function changeSpeed() | |
30 | + if speed >= 4 then | |
31 | + speed = 0.25 | |
32 | + else | |
33 | + speed = speed*2.0 | |
34 | + end | |
35 | + setAccel(speed) | |
36 | +end | |
37 | + | |
38 | +function toggleAI(p) | |
39 | + local oldid = id() | |
40 | + if player(p) then | |
41 | + if ailevel() > 0 then | |
42 | + setAILevel(0) | |
43 | + else | |
44 | + setAILevel(8) | |
45 | + end | |
46 | + playerid(oldid) | |
47 | + end | |
48 | +end | |
49 | + | |
50 | +function kill(p, ...) | |
51 | + local oldid = id() | |
52 | + if player(p) then | |
53 | + local n = ... | |
54 | + if not n then n = 0 end | |
55 | + setLife(n) | |
56 | + playerid(oldid) | |
57 | + end | |
58 | +end | |
59 | + | |
60 | +function powMax(p) | |
61 | + local oldid = id() | |
62 | + if player(p) then | |
63 | + setPower(powermax()) | |
64 | + playerid(oldid) | |
65 | + end | |
66 | +end | |
67 | + | |
68 | +function full(p) | |
69 | + local oldid = id() | |
70 | + if player(p) then | |
71 | + setLife(lifemax()) | |
72 | + setPower(powermax()) | |
73 | + playerid(oldid) | |
74 | + end | |
75 | +end | |
76 | + | |
77 | +function stand(p) | |
78 | + local oldid = id() | |
79 | + if player(p) then | |
80 | + selfState(0) | |
81 | + playerid(oldid) | |
82 | + end | |
83 | +end | |
84 | + | |
85 | +function info() | |
86 | + puts( | |
87 | + string.format( | |
88 | + 'name:%s state:%d>%d %s move:%s physics:%s', | |
89 | + name(), prevstateno(), stateno(), statetype(), movetype(), physics())) | |
90 | + puts( | |
91 | + string.format( | |
92 | + 'anim:%d %d elem:%d %d pos:%.3f,%.3f vel:%.3f,%.3f', | |
93 | + anim(), animtime(), animelemno(0), animelemtime(animelemno(0)), | |
94 | + posX(), posY(), velX(), velY())) | |
95 | +end | |
96 | + | |
97 | +function status(p) | |
98 | + local oldid = id() | |
99 | + if not player(p) then return false end | |
100 | + ret = | |
101 | + string.format( | |
102 | + 'STA:%s%s%s%6d(%d) ANI:%6d(%d)%2d LIF:%5d POW:%5d TIM:%d', | |
103 | + statetype(), movetype(), physics(), stateno(), stateOwner(), | |
104 | + anim(), animOwner(), animelemno(0), life(), power(), time()) | |
105 | + playerid(oldid) | |
106 | + return ret; | |
107 | +end | |
108 | + |
@@ -1,44 +1,687 @@ | ||
1 | -snd=sndNew('data/test.snd') | |
2 | -playBGM('sound/test.ogg') | |
3 | -sndPlay(snd,2,0) | |
4 | -sndPlay(snd,0,1) | |
5 | -sndPlay(snd,1,0) | |
6 | -sff=sffNew('data/test.sff') | |
7 | -sffv2=sffNew('data/testv2.sff') | |
8 | -anim=animNew(sffv2,[[ | |
9 | -Clsn2Default: 2 | |
10 | - Clsn2[0] = -52,0,64,-316 | |
11 | - Clsn2[1] = 20,-316,-28,-372 | |
12 | -0,0,0,0, 10 | |
13 | -0,1,0,0, 7 | |
14 | -0,2,0,0, 7 | |
15 | -0,3,0,0, 7 | |
16 | -0,4,0,0, 7 | |
17 | -0,5,0,0, 45 | |
18 | -0,4,0,0, 7 | |
19 | -0,3,0,0, 7 | |
20 | -0,2,0,0, 7 | |
21 | -0,1,0,0, 7 | |
22 | -0,0,0,0, 40,,,-0.5,0.5,90 | |
23 | -]]) | |
24 | -animSetPos(anim,80,60) | |
25 | -animAddPos(anim,80,60) | |
26 | -animSetTile(anim,1,1) | |
27 | -animSetColorKey(anim,-1) | |
28 | -animSetAlpha(anim,128,128) | |
29 | -animSetScale(anim,0.5,0.5) | |
30 | -animSetWindow(anim,10,10,300,220) | |
31 | -fnt=fontNew('data/test.fnt') | |
32 | -txt=textImgNew() | |
33 | -textImgSetFont(txt,fnt) | |
34 | -textImgSetBank(txt,1) | |
35 | -textImgSetAlign(txt,0) | |
36 | -textImgSetText(txt,'Test') | |
37 | -textImgSetPos(txt,160,120) | |
38 | -textImgSetScale(txt,5,2) | |
39 | -while true do | |
40 | - animUpdate(anim) | |
41 | - animDraw(anim) | |
42 | - textImgDraw(txt) | |
43 | - refresh() | |
44 | -end | |
1 | + | |
2 | +setRoundTime(999 * 6)--frames | |
3 | +setLifeMul(1.0) | |
4 | +setTeam1VS2Life(1.0) | |
5 | +setTurnsRecoveryRate(1.0 / 300.0) | |
6 | + | |
7 | +setZoom(false) | |
8 | +setZoomMin(0.25) | |
9 | +setZoomMax(1.0) | |
10 | +setZoomSpeed(1.0) | |
11 | + | |
12 | +loadLifebar('data/gms_lifebar/fight.def') | |
13 | +loadDebugFont('data/gms_lifebar/font2.fnt') | |
14 | +setDebugScript('script/debug.lua') | |
15 | + | |
16 | +selectColumns = 10 | |
17 | + | |
18 | + | |
19 | +require('script.randomtest') | |
20 | + | |
21 | +function addWithRefresh(addFn, text) | |
22 | + local nextRefresh = os.clock() + 0.02 | |
23 | + for i, c | |
24 | + in ipairs(script.randomtest.strsplit('\n', | |
25 | + text:gsub('^%s*(.-)%s*$', '%1'))) | |
26 | + do | |
27 | + addFn(c) | |
28 | + if os.clock() >= nextRefresh then | |
29 | + refresh() | |
30 | + nextRefresh = os.clock() + 0.02 | |
31 | + end | |
32 | + end | |
33 | +end | |
34 | + | |
35 | +orgAddChar = addChar | |
36 | +orgAddStage = addStage | |
37 | + | |
38 | +function addChar(text) | |
39 | + addWithRefresh(orgAddChar, text) | |
40 | +end | |
41 | + | |
42 | +function addStage(text) | |
43 | + addWithRefresh(orgAddStage, text) | |
44 | +end | |
45 | + | |
46 | +assert(loadfile('script/select.lua'))() | |
47 | + | |
48 | + | |
49 | +math.randomseed(os.time()) | |
50 | + | |
51 | +------------------------------------------------------------ | |
52 | +sysSff = sffNew('script/system.sff') | |
53 | +sysSnd = sndNew('script/system.snd') | |
54 | +jgFnt = fontNew('data/gms_lifebar/font2.fnt') | |
55 | + | |
56 | +bgm = '' | |
57 | +playBGM(bgm) | |
58 | + | |
59 | +------------------------------------------------------------ | |
60 | +function setCommand(c) | |
61 | + commandAdd(c, 'u', '$U') | |
62 | + commandAdd(c, 'd', '$D') | |
63 | + commandAdd(c, 'l', '$B') | |
64 | + commandAdd(c, 'r', '$F') | |
65 | + commandAdd(c, 'a', 'a') | |
66 | + commandAdd(c, 'b', 'b') | |
67 | + commandAdd(c, 'c', 'c') | |
68 | + commandAdd(c, 'x', 'x') | |
69 | + commandAdd(c, 'y', 'y') | |
70 | + commandAdd(c, 'z', 'z') | |
71 | + commandAdd(c, 's', 's') | |
72 | + commandAdd(c, 'holds', '/s') | |
73 | + commandAdd(c, 'su', '/s, U') | |
74 | + commandAdd(c, 'sd', '/s, D') | |
75 | +end | |
76 | + | |
77 | +p1Cmd = commandNew() | |
78 | +setCommand(p1Cmd) | |
79 | + | |
80 | +p2Cmd = commandNew() | |
81 | +setCommand(p2Cmd) | |
82 | + | |
83 | +------------------------------------------------------------ | |
84 | +selectRows = math.floor(selectColumns * 2 / 5.0) | |
85 | + | |
86 | +setRandomSpr(sysSff, 151, 0, 5.0/selectColumns, 5.0/selectColumns) | |
87 | +setSelColRow(selectColumns, selectRows) | |
88 | +setSelCellSize(29*5.0/selectColumns, 29*5.0/selectColumns) | |
89 | +setSelCellScale(5.0/selectColumns, 5.0/selectColumns) | |
90 | + | |
91 | +function init() | |
92 | + p1TeamMode = 0 | |
93 | + p1NumTurns = 2 | |
94 | + p1SelOffset = 0 | |
95 | + p1SelX = 0 | |
96 | + p1SelY = 0 | |
97 | + p1Portrait = nil | |
98 | + | |
99 | + p2TeamMode = 0 | |
100 | + p2NumTurns = 2 | |
101 | + p2SelOffset = 0 | |
102 | + p2SelX = 0 | |
103 | + p2SelY = 0 | |
104 | + p2Portrait = nil | |
105 | + | |
106 | + stageNo = 0 | |
107 | + setStage(0) | |
108 | +end | |
109 | + | |
110 | +init() | |
111 | + | |
112 | +function noTask() | |
113 | +end | |
114 | + | |
115 | + | |
116 | +function animPosDraw(a, x, y) | |
117 | + animSetPos(a, x, y) | |
118 | + animDraw(a) | |
119 | +end | |
120 | + | |
121 | +function textImgPosDraw(ti, x, y) | |
122 | + textImgSetPos(ti, x, y) | |
123 | + textImgDraw(ti) | |
124 | +end | |
125 | + | |
126 | +function createTextImg(font, bank, aline, text, x, y) | |
127 | + local ti = textImgNew() | |
128 | + textImgSetFont(ti, font) | |
129 | + textImgSetBank(ti, bank) | |
130 | + textImgSetAlign(ti, aline) | |
131 | + textImgSetText(ti, text) | |
132 | + textImgSetPos(ti, x, y) | |
133 | + return ti | |
134 | +end | |
135 | + | |
136 | +function btnPalNo(cmd) | |
137 | + local s = 0 | |
138 | + if commandGetState(cmd, 'holds') then s = 6 end | |
139 | + if commandGetState(cmd, 'a') then return 1 + s end | |
140 | + if commandGetState(cmd, 'b') then return 2 + s end | |
141 | + if commandGetState(cmd, 'c') then return 3 + s end | |
142 | + if commandGetState(cmd, 'x') then return 4 + s end | |
143 | + if commandGetState(cmd, 'y') then return 5 + s end | |
144 | + if commandGetState(cmd, 'z') then return 6 + s end | |
145 | + return 0 | |
146 | +end | |
147 | + | |
148 | +------------------------------------------------------------ | |
149 | +p1SelTmTxt = createTextImg(jgFnt, 0, 1, 'Team Mode', 20, 30) | |
150 | +p1SingleTxt = createTextImg(jgFnt, 0, 1, 'Single', 20, 50) | |
151 | +p1SimulTxt = createTextImg(jgFnt, 0, 1, 'Simul', 20, 65) | |
152 | +p1TurnsTxt = createTextImg(jgFnt, 0, 1, 'Turns', 20, 80) | |
153 | + | |
154 | +p1TmCursor = animNew(sysSff, [[ | |
155 | +180,0, 0,0, -1 | |
156 | +]]) | |
157 | + | |
158 | +p1TmIcon = animNew(sysSff, [[ | |
159 | +181,0, 0,0, -1 | |
160 | +]]) | |
161 | + | |
162 | +function p1TmSub() | |
163 | + if commandGetState(p1Cmd, 'u') then | |
164 | + sndPlay(sysSnd, 100, 0) | |
165 | + p1TeamMode = p1TeamMode - 1 | |
166 | + if p1TeamMode < 0 then p1TeamMode = 2 end | |
167 | + elseif commandGetState(p1Cmd, 'd') then | |
168 | + sndPlay(sysSnd, 100, 0) | |
169 | + p1TeamMode = p1TeamMode + 1 | |
170 | + if p1TeamMode > 2 then p1TeamMode = 0 end | |
171 | + elseif p1TeamMode == 2 then | |
172 | + if commandGetState(p1Cmd, 'l') then | |
173 | + sndPlay(sysSnd, 100, 0) | |
174 | + p1NumTurns = p1NumTurns - 1 | |
175 | + if p1NumTurns < 1 then p1NumTurns = 1 end | |
176 | + elseif commandGetState(p1Cmd, 'r') then | |
177 | + sndPlay(sysSnd, 100, 0) | |
178 | + p1NumTurns = p1NumTurns + 1 | |
179 | + if p1NumTurns > 4 then p1NumTurns = 4 end | |
180 | + end | |
181 | + end | |
182 | + textImgDraw(p1SelTmTxt) | |
183 | + textImgDraw(p1SingleTxt) | |
184 | + textImgDraw(p1SimulTxt) | |
185 | + textImgDraw(p1TurnsTxt) | |
186 | + animUpdate(p1TmIcon) | |
187 | + animPosDraw(p1TmIcon, 80, 66) | |
188 | + animPosDraw(p1TmIcon, 86, 66) | |
189 | + for i = 1, p1NumTurns do | |
190 | + animPosDraw(p1TmIcon, 74 + i*6, 81) | |
191 | + end | |
192 | + animUpdate(p1TmCursor) | |
193 | + animPosDraw(p1TmCursor, 10, 47 + p1TeamMode*15) | |
194 | + if btnPalNo(p1Cmd) > 0 then | |
195 | + sndPlay(sysSnd, 100, 1) | |
196 | + setTeamMode(1, p1TeamMode, p1NumTurns) | |
197 | + p1Selected = {} | |
198 | + p1SelEnd = false | |
199 | + p1Task = p1SelSub | |
200 | + end | |
201 | +end | |
202 | + | |
203 | + | |
204 | +------------------------------------------------------------ | |
205 | +p2SelTmTxt = createTextImg(jgFnt, 0, -1, 'Team Mode', 300, 30) | |
206 | +p2SingleTxt = createTextImg(jgFnt, 0, -1, 'Single', 300, 50) | |
207 | +p2SimulTxt = createTextImg(jgFnt, 0, -1, 'Simul', 300, 65) | |
208 | +p2TurnsTxt = createTextImg(jgFnt, 0, -1, 'Turns', 300, 80) | |
209 | + | |
210 | +p2TmCursor = animNew(sysSff, [[ | |
211 | +190,0, 0,0, -1 | |
212 | +]]) | |
213 | + | |
214 | +p2TmIcon = animNew(sysSff, [[ | |
215 | +191,0, 0,0, -1 | |
216 | +]]) | |
217 | + | |
218 | +function p2TmSub() | |
219 | + if commandGetState(p2Cmd, 'u') then | |
220 | + sndPlay(sysSnd, 100, 0) | |
221 | + p2TeamMode = p2TeamMode - 1 | |
222 | + if p2TeamMode < 0 then p2TeamMode = 2 end | |
223 | + elseif commandGetState(p2Cmd, 'd') then | |
224 | + sndPlay(sysSnd, 100, 0) | |
225 | + p2TeamMode = p2TeamMode + 1 | |
226 | + if p2TeamMode > 2 then p2TeamMode = 0 end | |
227 | + elseif p2TeamMode == 2 then | |
228 | + if commandGetState(p2Cmd, 'r') then | |
229 | + sndPlay(sysSnd, 100, 0) | |
230 | + p2NumTurns = p2NumTurns - 1 | |
231 | + if p2NumTurns < 1 then p2NumTurns = 1 end | |
232 | + elseif commandGetState(p2Cmd, 'l') then | |
233 | + sndPlay(sysSnd, 100, 0) | |
234 | + p2NumTurns = p2NumTurns + 1 | |
235 | + if p2NumTurns > 4 then p2NumTurns = 4 end | |
236 | + end | |
237 | + end | |
238 | + textImgDraw(p2SelTmTxt) | |
239 | + textImgDraw(p2SingleTxt) | |
240 | + textImgDraw(p2SimulTxt) | |
241 | + textImgDraw(p2TurnsTxt) | |
242 | + animUpdate(p2TmIcon) | |
243 | + animPosDraw(p2TmIcon, 240, 66) | |
244 | + animPosDraw(p2TmIcon, 234, 66) | |
245 | + for i = 1, p2NumTurns do | |
246 | + animPosDraw(p2TmIcon, 246 - i*6, 81) | |
247 | + end | |
248 | + animUpdate(p2TmCursor) | |
249 | + animPosDraw(p2TmCursor, 310, 47 + p2TeamMode*15) | |
250 | + if btnPalNo(p2Cmd) > 0 then | |
251 | + sndPlay(sysSnd, 100, 1) | |
252 | + setTeamMode(2, p2TeamMode, p2NumTurns) | |
253 | + p2Selected = {} | |
254 | + p2SelEnd = false | |
255 | + p2Task = p2SelSub | |
256 | + end | |
257 | +end | |
258 | + | |
259 | + | |
260 | +------------------------------------------------------------ | |
261 | +p1Cursor = animNew(sysSff, [[ | |
262 | +160,0, 0,0, -1 | |
263 | +]]) | |
264 | +animSetScale(p1Cursor, 5.0/selectColumns, 5.0/selectColumns) | |
265 | + | |
266 | +p1NameTxt = createTextImg(jgFnt, 0, 1, '', 0, 0) | |
267 | +textImgSetScale(p1NameTxt, 0.5, 0.5) | |
268 | + | |
269 | +function p1DrawSelectName() | |
270 | + local y = 162 | |
271 | + for i = 1, #p1Selected do | |
272 | + textImgSetText(p1NameTxt, getCharName(p1Selected[i])) | |
273 | + textImgPosDraw(p1NameTxt, 10, y) | |
274 | + y = y + 7 | |
275 | + end | |
276 | + return y | |
277 | +end | |
278 | + | |
279 | +function p1SelSub() | |
280 | + local n = p1SelOffset + p1SelX + selectColumns*p1SelY | |
281 | + p1Portrait = n | |
282 | + local y = p1DrawSelectName() | |
283 | + if not p1SelEnd then | |
284 | + if commandGetState(p1Cmd, 'su') then | |
285 | + sndPlay(sysSnd, 100, 0) | |
286 | + p1SelY = p1SelY - 20 | |
287 | + elseif commandGetState(p1Cmd, 'sd') then | |
288 | + sndPlay(sysSnd, 100, 0) | |
289 | + p1SelY = p1SelY + 20 | |
290 | + elseif commandGetState(p1Cmd, 'u') then | |
291 | + sndPlay(sysSnd, 100, 0) | |
292 | + p1SelY = p1SelY - 1 | |
293 | + elseif commandGetState(p1Cmd, 'd') then | |
294 | + sndPlay(sysSnd, 100, 0) | |
295 | + p1SelY = p1SelY + 1 | |
296 | + elseif commandGetState(p1Cmd, 'l') then | |
297 | + sndPlay(sysSnd, 100, 0) | |
298 | + p1SelX = p1SelX - 1 | |
299 | + elseif commandGetState(p1Cmd, 'r') then | |
300 | + sndPlay(sysSnd, 100, 0) | |
301 | + p1SelX = p1SelX + 1 | |
302 | + end | |
303 | + if p1SelY < 0 then | |
304 | + p1SelOffset = p1SelOffset + selectColumns*p1SelY | |
305 | + p1SelY = 0 | |
306 | + elseif p1SelY >= selectRows then | |
307 | + p1SelOffset = p1SelOffset + selectColumns*(p1SelY - (selectRows - 1)) | |
308 | + p1SelY = selectRows - 1 | |
309 | + end | |
310 | + if p1SelX < 0 then | |
311 | + p1SelX = selectColumns - 1 | |
312 | + elseif p1SelX >= selectColumns then | |
313 | + p1SelX = 0 | |
314 | + end | |
315 | + animUpdate(p1Cursor) | |
316 | + animPosDraw( | |
317 | + p1Cursor, 10 + 29*p1SelX*5.0/selectColumns, | |
318 | + 170 + 29*p1SelY*5.0/selectColumns) | |
319 | + textImgSetText(p1NameTxt, getCharName(n)) | |
320 | + textImgPosDraw(p1NameTxt, 10, y) | |
321 | + local selval = selectChar(1, n, btnPalNo(p1Cmd)) | |
322 | + if selval > 0 then | |
323 | + sndPlay(sysSnd, 100, 1) | |
324 | + p1Selected[#p1Selected+1] = n | |
325 | + end | |
326 | + if selval == 2 then | |
327 | + p1SelEnd = true | |
328 | + if p2In == 1 then | |
329 | + p2Task = p2TmSub | |
330 | + commandBufReset(p2Cmd, p2In) | |
331 | + end | |
332 | + end | |
333 | + end | |
334 | +end | |
335 | + | |
336 | + | |
337 | +------------------------------------------------------------ | |
338 | +p2Cursor = animNew(sysSff, [[ | |
339 | +170,0, 0,0, -1 | |
340 | +]]) | |
341 | +animSetScale(p2Cursor, 5.0/selectColumns, 5.0/selectColumns) | |
342 | + | |
343 | +p2NameTxt = createTextImg(jgFnt, 0, -1, '', 0, 0) | |
344 | +textImgSetScale(p2NameTxt, 0.5, 0.5) | |
345 | + | |
346 | +function p2DrawSelectName() | |
347 | + local y = 162 | |
348 | + for i = 1, #p2Selected do | |
349 | + textImgSetText(p2NameTxt, getCharName(p2Selected[i])) | |
350 | + textImgPosDraw(p2NameTxt, 310, y) | |
351 | + y = y + 7 | |
352 | + end | |
353 | + return y | |
354 | +end | |
355 | + | |
356 | +function p2SelSub() | |
357 | + local n = p2SelOffset + p2SelX + selectColumns*p2SelY | |
358 | + p2Portrait = n | |
359 | + local y = p2DrawSelectName() | |
360 | + if not p2SelEnd then | |
361 | + if commandGetState(p2Cmd, 'su') then | |
362 | + sndPlay(sysSnd, 100, 0) | |
363 | + p2SelY = p2SelY - 20 | |
364 | + elseif commandGetState(p2Cmd, 'sd') then | |
365 | + sndPlay(sysSnd, 100, 0) | |
366 | + p2SelY = p2SelY + 20 | |
367 | + elseif commandGetState(p2Cmd, 'u') then | |
368 | + sndPlay(sysSnd, 100, 0) | |
369 | + p2SelY = p2SelY - 1 | |
370 | + elseif commandGetState(p2Cmd, 'd') then | |
371 | + sndPlay(sysSnd, 100, 0) | |
372 | + p2SelY = p2SelY + 1 | |
373 | + elseif commandGetState(p2Cmd, 'l') then | |
374 | + sndPlay(sysSnd, 100, 0) | |
375 | + p2SelX = p2SelX - 1 | |
376 | + elseif commandGetState(p2Cmd, 'r') then | |
377 | + sndPlay(sysSnd, 100, 0) | |
378 | + p2SelX = p2SelX + 1 | |
379 | + end | |
380 | + if p2SelY < 0 then | |
381 | + p2SelOffset = p2SelOffset + selectColumns*p2SelY | |
382 | + p2SelY = 0 | |
383 | + elseif p2SelY >= selectRows then | |
384 | + p2SelOffset = p2SelOffset + selectColumns*(p2SelY - (selectRows - 1)) | |
385 | + p2SelY = selectRows - 1 | |
386 | + end | |
387 | + if p2SelX < 0 then | |
388 | + p2SelX = selectColumns - 1 | |
389 | + elseif p2SelX >= selectColumns then | |
390 | + p2SelX = 0 | |
391 | + end | |
392 | + animUpdate(p2Cursor) | |
393 | + animPosDraw( | |
394 | + p2Cursor, 169 + 29*p2SelX*5.0/selectColumns, | |
395 | + 170 + 29*p2SelY*5.0/selectColumns) | |
396 | + textImgSetText(p2NameTxt, getCharName(n)) | |
397 | + textImgPosDraw(p2NameTxt, 310, y) | |
398 | + local selval = selectChar(2, n, btnPalNo(p2Cmd)) | |
399 | + if selval > 0 then | |
400 | + sndPlay(sysSnd, 100, 1) | |
401 | + p2Selected[#p2Selected+1] = n | |
402 | + end | |
403 | + if selval == 2 then | |
404 | + p2SelEnd = true | |
405 | + if p1In == 2 then | |
406 | + p1Task = p1TmSub | |
407 | + commandBufReset(p1Cmd, p1In) | |
408 | + end | |
409 | + end | |
410 | + end | |
411 | +end | |
412 | + | |
413 | + | |
414 | +------------------------------------------------------------ | |
415 | +selStageTxt = createTextImg(jgFnt, 0, 0, '', 160, 237) | |
416 | +textImgSetScale(selStageTxt, 0.5, 0.5) | |
417 | + | |
418 | +function selStageSub() | |
419 | + if commandGetState(p1Cmd, 'l') then | |
420 | + sndPlay(sysSnd, 100, 0) | |
421 | + stageNo = setStage(stageNo - 1) | |
422 | + elseif commandGetState(p1Cmd, 'r') then | |
423 | + sndPlay(sysSnd, 100, 0) | |
424 | + stageNo = setStage(stageNo + 1) | |
425 | + elseif commandGetState(p1Cmd, 'u') then | |
426 | + sndPlay(sysSnd, 100, 0) | |
427 | + stageNo = setStage(stageNo - 10) | |
428 | + elseif commandGetState(p1Cmd, 'd') then | |
429 | + sndPlay(sysSnd, 100, 0) | |
430 | + stageNo = setStage(stageNo + 10) | |
431 | + end | |
432 | + textImgSetText( | |
433 | + selStageTxt, 'Stage ' .. stageNo .. ': ' .. getStageName(stageNo)) | |
434 | + textImgDraw(selStageTxt) | |
435 | + if btnPalNo(p1Cmd) > 0 then | |
436 | + selectStage(stageNo) | |
437 | + selMode = false | |
438 | + end | |
439 | +end | |
440 | + | |
441 | + | |
442 | +------------------------------------------------------------ | |
443 | +selBG = animNew(sysSff, [[ | |
444 | +100,0, 0,0, -1 | |
445 | +]]) | |
446 | +animSetTile(selBG, 1, 1) | |
447 | +animSetColorKey(selBG, -1) | |
448 | +animSetScale(selBG, 0.5, 0.5) | |
449 | + | |
450 | +selBox = animNew(sysSff, [[ | |
451 | +100,1, 0,0, -1 | |
452 | +]]) | |
453 | +animSetTile(selBox, 1, 0) | |
454 | +animSetColorKey(selBox, -1) | |
455 | +animSetAlpha(selBox, 1, 255) | |
456 | +animSetPos(selBox, 0, 166) | |
457 | +animSetWindow(selBox, 5, 0, 151, 240) | |
458 | + | |
459 | +selBox2 = animNew(sysSff, [[ | |
460 | +100,1, 0,0, -1 | |
461 | +]]) | |
462 | +animSetTile(selBox2, 1, 0) | |
463 | +animSetColorKey(selBox2, -1) | |
464 | +animSetAlpha(selBox2, 1, 255) | |
465 | +animSetPos(selBox2, 0, 166) | |
466 | +animSetWindow(selBox2, 164, 0, 151, 240) | |
467 | + | |
468 | +function bgSub() | |
469 | + animAddPos(selBG, 1, 1) | |
470 | + animUpdate(selBG) | |
471 | + animDraw(selBG) | |
472 | + animAddPos(selBox, 1, 0) | |
473 | + animUpdate(selBox) | |
474 | + animDraw(selBox) | |
475 | + animAddPos(selBox2, 1, 0) | |
476 | + animUpdate(selBox2) | |
477 | + animDraw(selBox2) | |
478 | +end | |
479 | + | |
480 | + | |
481 | +------------------------------------------------------------ | |
482 | +watchMode = createTextImg(jgFnt, 0, 1, 'Watch Mode', 100, 80) | |
483 | +p1VsComTxt = createTextImg(jgFnt, 0, 1, '1P vs. Com', 100, 100) | |
484 | +p1VsP2 = createTextImg(jgFnt, 0, 1, '1P vs. 2P', 100, 120) | |
485 | +netplay = createTextImg(jgFnt, 0, 1, 'Netplay', 100, 140) | |
486 | +portChange = createTextImg(jgFnt, 0, 1, '', 100, 160) | |
487 | +replay = createTextImg(jgFnt, 0, 1, 'Replay', 100, 180) | |
488 | +comVsP1 = createTextImg(jgFnt, 0, 1, 'Com vs. 1P', 100, 200) | |
489 | +autoRandomTest = createTextImg(jgFnt, 0, 1, 'Auto Random Test', 100, 220) | |
490 | + | |
491 | +connecting = createTextImg(jgFnt, 0, 1, '', 10, 140) | |
492 | +loading = createTextImg(jgFnt, 0, 1, 'Loading...', 100, 210) | |
493 | + | |
494 | +inputdia = inputDialogNew() | |
495 | + | |
496 | +function cmdInput() | |
497 | + commandInput(p1Cmd, p1In) | |
498 | + commandInput(p2Cmd, p2In) | |
499 | +end | |
500 | + | |
501 | +function main() | |
502 | + while true do | |
503 | + p1Selected = {} | |
504 | + p1SelEnd = false | |
505 | + p1Portrait = nil | |
506 | + | |
507 | + p2Selected = {} | |
508 | + p2SelEnd = false | |
509 | + p2Portrait = nil | |
510 | + | |
511 | + if gameMode == 6 then | |
512 | + p1Task = noTask | |
513 | + p2Task = p2TmSub | |
514 | + else | |
515 | + p1Task = p1TmSub | |
516 | + p2Task = noTask | |
517 | + if gameMode > 1 then p2Task = p2TmSub end | |
518 | + end | |
519 | + | |
520 | + refresh() | |
521 | + | |
522 | + commandBufReset(p1Cmd, p1In) | |
523 | + commandBufReset(p2Cmd, p2In) | |
524 | + | |
525 | + selMode = true | |
526 | + selectStart() | |
527 | + | |
528 | + ------------------------------------------------------------ | |
529 | + --メインループ | |
530 | + ------------------------------------------------------------ | |
531 | + while selMode do | |
532 | + if esc() then return end | |
533 | + bgSub() | |
534 | + if p1Portrait then drawPortrait(p1Portrait, 18, 13, 1, 1) end | |
535 | + if p2Portrait then drawPortrait(p2Portrait, 302, 13, -1, 1) end | |
536 | + drawFace(10, 170, p1SelOffset) | |
537 | + drawFace(169, 170, p2SelOffset) | |
538 | + if p1SelEnd and p2SelEnd then selStageSub() end | |
539 | + p2Task() | |
540 | + p1Task() | |
541 | + cmdInput() | |
542 | + refresh() | |
543 | + end | |
544 | + for i = 1, 20 do | |
545 | + animDraw(selBG) | |
546 | + local k = 0 | |
547 | + for j = 1, #p1Selected do | |
548 | + local scl = 10000.0 / (10000.0 - k*i) | |
549 | + local tmp = i*k / 20 | |
550 | + drawPortrait(p1Selected[j], 18 - tmp, 13 + tmp/3, scl, scl) | |
551 | + k = k + 48 | |
552 | + end | |
553 | + k = 0 | |
554 | + for j = 1, #p2Selected do | |
555 | + local scl = 10000.0 / (10000.0 - k*i) | |
556 | + local tmp = i*k / 20 | |
557 | + drawPortrait(p2Selected[j], 302 + tmp, 13 + tmp/3, -scl, scl) | |
558 | + k = k + 48 | |
559 | + end | |
560 | + p1DrawSelectName() | |
561 | + p2DrawSelectName() | |
562 | + textImgDraw(loading) | |
563 | + refresh() | |
564 | + end | |
565 | + game() | |
566 | + playBGM(bgm) | |
567 | + end | |
568 | +end | |
569 | + | |
570 | +function modeSel() | |
571 | + while true do | |
572 | + exitNetPlay() | |
573 | + exitReplay() | |
574 | + | |
575 | + gameMode = 0 | |
576 | + p1In = 1 | |
577 | + p2In = 1 | |
578 | + | |
579 | + for i = 1, 8 do | |
580 | + setCom(i, 8) | |
581 | + end | |
582 | + setAutoLevel(false) | |
583 | + setMatchNo(1) | |
584 | + setHomeTeam(1) | |
585 | + resetRemapInput() | |
586 | + | |
587 | + textImgSetText(portChange, 'Port Change(' .. getListenPort() .. ')') | |
588 | + | |
589 | + refresh() | |
590 | + commandBufReset(p1Cmd, 1) | |
591 | + | |
592 | + while btnPalNo(p1Cmd) <= 0 do | |
593 | + if commandGetState(p1Cmd, 'u') then | |
594 | + sndPlay(sysSnd, 100, 0) | |
595 | + gameMode = gameMode - 1 | |
596 | + elseif commandGetState(p1Cmd, 'd') then | |
597 | + sndPlay(sysSnd, 100, 0) | |
598 | + gameMode = gameMode + 1 | |
599 | + end | |
600 | + if gameMode < 0 then | |
601 | + gameMode = 7 | |
602 | + elseif gameMode > 7 then | |
603 | + gameMode = 0 | |
604 | + end | |
605 | + textImgDraw(watchMode) | |
606 | + textImgDraw(p1VsComTxt) | |
607 | + textImgDraw(p1VsP2) | |
608 | + textImgDraw(netplay) | |
609 | + textImgDraw(portChange) | |
610 | + textImgDraw(replay) | |
611 | + textImgDraw(comVsP1) | |
612 | + textImgDraw(autoRandomTest) | |
613 | + animUpdate(p1TmCursor) | |
614 | + animPosDraw(p1TmCursor, 95, 77 + 20*gameMode) | |
615 | + cmdInput() | |
616 | + refresh() | |
617 | + end | |
618 | + sndPlay(sysSnd, 100, 1) | |
619 | + | |
620 | + local cancel = false | |
621 | + | |
622 | + if gameMode == 0 then | |
623 | + elseif gameMode == 1 then | |
624 | + setCom(1, 0) | |
625 | + elseif gameMode == 2 then | |
626 | + p2In = 2 | |
627 | + setCom(1, 0) | |
628 | + setCom(2, 0) | |
629 | + elseif gameMode == 3 then | |
630 | + p2In = 2 | |
631 | + setCom(1, 0) | |
632 | + setCom(2, 0) | |
633 | + inputDialogPopup(inputdia, 'Input Server') | |
634 | + while not inputDialogIsDone(inputdia) do | |
635 | + refresh() | |
636 | + end | |
637 | + textImgSetText( | |
638 | + connecting, | |
639 | + 'Now connecting.. ' .. inputDialogGetStr(inputdia) | |
640 | + .. ' ' .. getListenPort()) | |
641 | + enterNetPlay(inputDialogGetStr(inputdia)) | |
642 | + while not connected() do | |
643 | + if esc() then | |
644 | + cancel = true | |
645 | + break | |
646 | + end | |
647 | + textImgDraw(connecting) | |
648 | + refresh() | |
649 | + end | |
650 | + if not cancel then | |
651 | + init() | |
652 | + synchronize() | |
653 | + math.randomseed(sszRandom()) | |
654 | + end | |
655 | + elseif gameMode == 4 then | |
656 | + inputDialogPopup(inputdia, 'Input Port') | |
657 | + while not inputDialogIsDone(inputdia) do | |
658 | + refresh() | |
659 | + end | |
660 | + setListenPort(inputDialogGetStr(inputdia)) | |
661 | + cancel = true | |
662 | + elseif gameMode == 5 then | |
663 | + p2In = 2 | |
664 | + setCom(1, 0) | |
665 | + setCom(2, 0) | |
666 | + enterReplay('replay/netplay.replay') | |
667 | + init() | |
668 | + synchronize() | |
669 | + math.randomseed(sszRandom()) | |
670 | + elseif gameMode == 6 then | |
671 | + remapInput(1, 2) | |
672 | + remapInput(2, 1) | |
673 | + p1In = 2 | |
674 | + p2In = 2 | |
675 | + setCom(2, 0) | |
676 | + elseif gameMode == 7 then | |
677 | + script.randomtest.run() | |
678 | + cancel = true | |
679 | + end | |
680 | + if not cancel then | |
681 | + main() | |
682 | + end | |
683 | + end | |
684 | +end | |
685 | + | |
686 | +modeSel() | |
687 | + |
@@ -0,0 +1,291 @@ | ||
1 | + | |
2 | +module(..., package.seeall) | |
3 | + | |
4 | +function strsplit(delimiter, text) | |
5 | + local list = {} | |
6 | + local pos = 1 | |
7 | + if string.find('', delimiter, 1) then | |
8 | + if string.len(text) == 0 then | |
9 | + table.insert(list, text) | |
10 | + else | |
11 | + for i = 1, string.len(text) do | |
12 | + table.insert(list, string.sub(text, i, i)) | |
13 | + end | |
14 | + end | |
15 | + else | |
16 | + while true do | |
17 | + local first, last = string.find(text, delimiter, pos) | |
18 | + if first then | |
19 | + table.insert(list, string.sub(text, pos, first-1)) | |
20 | + pos = last+1 | |
21 | + else | |
22 | + table.insert(list, string.sub(text, pos)) | |
23 | + break | |
24 | + end | |
25 | + end | |
26 | + end | |
27 | + return list | |
28 | +end | |
29 | + | |
30 | +function strtrim(s) | |
31 | + return string.match(s,'^()%s*$') and '' or string.match(s,'^%s*(.*%S)') | |
32 | +end | |
33 | + | |
34 | +function map(func, table) | |
35 | + local dest = {} | |
36 | + for k, v in pairs(table) do | |
37 | + dest[k] = func(v) | |
38 | + end | |
39 | + return dest | |
40 | +end | |
41 | + | |
42 | + | |
43 | +tuyoiBorder = 0 | |
44 | +juuni = 12 | |
45 | +moudeta = {} | |
46 | +rank = 0 | |
47 | +saikyou = false | |
48 | +roster = {} | |
49 | +debugText = '' | |
50 | +numChars = 0 | |
51 | +nextChar = 1 | |
52 | + | |
53 | +function addMoudeta(rank) | |
54 | + moudeta[#moudeta + 1] = rank | |
55 | + local max = | |
56 | + math.floor( | |
57 | + numChars / (math.min(numChars / (juuni*10) + 3, juuni)*juuni)) | |
58 | + while #moudeta > max do | |
59 | + table.remove(moudeta, 1) | |
60 | + end | |
61 | +end | |
62 | +function randRank() | |
63 | + local r = 0 | |
64 | + while true do | |
65 | + r = math.random(1, tuyoiBorder + juuni - 2); | |
66 | + local notbroken = true | |
67 | + for i = 1, #moudeta do | |
68 | + if math.abs(moudeta[i] - r) <= math.floor(juuni/3) then | |
69 | + notbroken = false | |
70 | + break | |
71 | + end | |
72 | + end | |
73 | + if notbroken then | |
74 | + break | |
75 | + end | |
76 | + end | |
77 | + return r | |
78 | +end | |
79 | + | |
80 | +function eachAllChars(f) | |
81 | + for cel = 0, numSelCells()-1 do | |
82 | + if getCharFileName(cel) ~= 'randomselect' and getCharName(cel) ~= '' then | |
83 | + f(cel) | |
84 | + end | |
85 | + end | |
86 | +end | |
87 | + | |
88 | +function rakuBenry() | |
89 | + local alf = 'autolevel.txt' | |
90 | + local veljnz = {} | |
91 | + local winct = {} | |
92 | + local buf = '\239\187\191' | |
93 | + local fp = io.open(alf, 'r') | |
94 | + if fp then | |
95 | + for line in fp:lines() do | |
96 | + local tmp = strsplit(',', line) | |
97 | + if #tmp >= 2 then | |
98 | + for i = 1, 4 do | |
99 | + if i == 4 then | |
100 | + tmp[1] = string.sub(tmp[1], 4) | |
101 | + else | |
102 | + if string.byte(tmp[1], i) ~= string.byte(buf, i) then break end | |
103 | + end | |
104 | + end | |
105 | + winct[tmp[1]] = map(tonumber, strsplit(' ', strtrim(tmp[2]))) | |
106 | + end | |
107 | + end | |
108 | + io.close(fp) | |
109 | + end | |
110 | + numChars = 0 | |
111 | + eachAllChars(function(cel) | |
112 | + numChars = numChars + 1 | |
113 | + end) | |
114 | + local tuyoninzu = math.floor(numChars / (juuni*10)) | |
115 | + if tuyoninzu < juuni - 1 then | |
116 | + tuyoiBorder = math.floor(numChars / (tuyoninzu + 1)) | |
117 | + tuyoninzu = juuni - 1 | |
118 | + else | |
119 | + tuyoiBorder = math.floor(numChars / juuni) | |
120 | + end | |
121 | + local total = 0 | |
122 | + local zero ={} | |
123 | + local tsuyoshi = {} | |
124 | + local rand = {} | |
125 | + local kai = {} | |
126 | + local bimyou = {} | |
127 | + local tuyocnt = 0 | |
128 | + local ran = randRank() | |
129 | + eachAllChars(function(cel) | |
130 | + if #veljnz < cel*12 then | |
131 | + for i = #veljnz + 1, cel*12 do | |
132 | + veljnz[i] = 0 | |
133 | + end | |
134 | + end | |
135 | + local wins = winct[getCharFileName(cel)] | |
136 | + local tmp = 0 | |
137 | + for j = 1, 12 do | |
138 | + if wins and j <= #wins then | |
139 | + total = total + wins[j] | |
140 | + veljnz[cel*12 + j] = wins[j] | |
141 | + tmp = tmp + wins[j] | |
142 | + else | |
143 | + veljnz[cel*12 + j] = 0 | |
144 | + end | |
145 | + end | |
146 | + if tmp >= tuyoiBorder then tuyocnt = tuyocnt + 1 end | |
147 | + if tmp >= tuyoiBorder - juuni then table.insert(tsuyoshi, cel) end | |
148 | + if tmp >= 1 and tmp <= juuni then table.insert(bimyou, cel) end | |
149 | + if tmp > ran-juuni and tmp <= ran then table.insert(rand, cel) end | |
150 | + if tmp == 0 then table.insert(zero, cel) end | |
151 | + if tmp < 0 then table.insert(kai, cel) end | |
152 | + end) | |
153 | + function charAdd(cList, numAdd) | |
154 | + if numAdd <= 0 then return end | |
155 | + for i = 1, numAdd do | |
156 | + if #cList == 0 then break end | |
157 | + local cidx = math.random(1, #cList) | |
158 | + table.insert(roster, cList[cidx]) | |
159 | + table.remove(cList, cidx) | |
160 | + end | |
161 | + end | |
162 | + roster = {} | |
163 | + nextChar = 1 | |
164 | + debugText = '' | |
165 | + local numZero = #zero | |
166 | + if numZero > 0 then | |
167 | + charAdd(zero, numZero) | |
168 | + charAdd(kai, tuyoninzu - numZero) | |
169 | + rank = 0 | |
170 | + elseif #bimyou >= math.max(tuyoninzu*20, math.floor((numChars*3)/20)) then | |
171 | + charAdd(bimyou, #bimyou) | |
172 | + rank = juuni | |
173 | + else | |
174 | + for n = 1, 3 do | |
175 | + if #rand >= tuyoninzu then break end | |
176 | + rand = {} | |
177 | + ran = randRank() | |
178 | + eachAllChars(function(cel) | |
179 | + local tmp = 0 | |
180 | + for j = 1, 12 do | |
181 | + tmp = tmp + veljnz[cel*12 + j] | |
182 | + end | |
183 | + if tmp > ran-juuni and tmp <= ran then table.insert(rand, cel) end | |
184 | + end) | |
185 | + end | |
186 | + debugText = ran .. ' ' .. #rand | |
187 | + if #rand >= tuyoninzu then | |
188 | + charAdd(rand, #rand) | |
189 | + rank = ran | |
190 | + addMoudeta(rank) | |
191 | + elseif tuyocnt >= tuyoninzu then | |
192 | + charAdd(tsuyoshi, #tsuyoshi) | |
193 | + rank = tuyoiBorder+juuni-1 | |
194 | + else | |
195 | + addMoudeta(tuyoiBorder + (juuni-2) - math.floor(juuni/3)) | |
196 | + charAdd(kai, #kai) | |
197 | + rank = -1 | |
198 | + end | |
199 | + end | |
200 | + if numZero == 0 then | |
201 | + while total ~= 0 do | |
202 | + local i = math.random(1, #veljnz) | |
203 | + if total > 0 then | |
204 | + veljnz[i] = veljnz[i] - 1 | |
205 | + total = total - 1 | |
206 | + else | |
207 | + veljnz[i] = veljnz[i] + 1 | |
208 | + total = total + 1 | |
209 | + end | |
210 | + end | |
211 | + end | |
212 | + eachAllChars(function(cel) | |
213 | + buf = buf .. getCharFileName(cel) .. ',' | |
214 | + for j = 1, 12 do | |
215 | + buf = buf .. ' ' .. veljnz[cel*12 + j] | |
216 | + end | |
217 | + buf = buf .. '\r\n' | |
218 | + end) | |
219 | + local alv = io.open(alf, 'wb') | |
220 | + alv:write(buf) | |
221 | + io.close(alv) | |
222 | +end | |
223 | + | |
224 | +function randSel(pno, winner) | |
225 | + if winner > 0 and (pno == winner) == not saikyou then return end | |
226 | + local team | |
227 | + if rank == 0 or rank == 12 or saikyou then | |
228 | + team = 0 | |
229 | + elseif rank < 0 then | |
230 | + team = math.random(0, 2) | |
231 | + else | |
232 | + team = math.random(0, 1)*2 | |
233 | + end | |
234 | + setTeamMode(pno, team, math.random(1, 4)) | |
235 | + local tmp = 0 | |
236 | + while tmp < 2 do | |
237 | + tmp = selectChar(pno, roster[nextChar], math.random(1, 12)) | |
238 | + nextChar = nextChar + 1 | |
239 | + if nextChar > #roster then nextChar = 1 end | |
240 | + end | |
241 | +end | |
242 | + | |
243 | +function rosterTxt() | |
244 | + local str = "Rank: " .. rank .. ' ' .. debugText | |
245 | + for i = 1, #roster do | |
246 | + str = str .. '\n' .. getCharFileName(roster[i]) | |
247 | + end | |
248 | + dscr = io.open('script/randomroster.txt', 'w') | |
249 | + dscr:write(str) | |
250 | + io.close(dscr) | |
251 | +end | |
252 | + | |
253 | + | |
254 | +function init() | |
255 | + for i = 1, 8 do | |
256 | + setCom(i, 8) | |
257 | + end | |
258 | + setAutoLevel(true) | |
259 | + setMatchNo(1) | |
260 | + selectStage(0) | |
261 | + rakuBenry() | |
262 | + winner = 0 | |
263 | + wins = 0 | |
264 | + rosterTxt() | |
265 | + nextChar = 1 | |
266 | + saikyou = rank == tuyoiBorder+juuni-1 | |
267 | +end | |
268 | + | |
269 | +function run() | |
270 | + init() | |
271 | + refresh() | |
272 | + while not esc() do | |
273 | + randSel(1, winner) | |
274 | + randSel(2, winner) | |
275 | + loadStart() | |
276 | + local oldwinner = winner | |
277 | + winner = game() | |
278 | + if winner < 0 or esc() then break end | |
279 | + oldwins = wins | |
280 | + wins = wins + 1 | |
281 | + if winner ~= oldwinner then | |
282 | + wins = 1 | |
283 | + setHomeTeam(winner == 1 and 2 or 1) | |
284 | + end | |
285 | + setMatchNo(wins) | |
286 | + if winner <= 0 or wins >= 20 or wins == oldwins then | |
287 | + init() | |
288 | + end | |
289 | + refresh() | |
290 | + end | |
291 | +end |
@@ -263,6 +263,27 @@ func ReadAnimation(sff *Sff, lines []string, i *int) *Animation { | ||
263 | 263 | } |
264 | 264 | return a |
265 | 265 | } |
266 | +func ReadAction(sff *Sff, lines []string, i *int) (no int32, a *Animation) { | |
267 | + var name, subname string | |
268 | + for ; *i < len(lines); (*i)++ { | |
269 | + name, subname = SectionName(lines[*i]) | |
270 | + if len(name) > 0 { | |
271 | + break | |
272 | + } | |
273 | + } | |
274 | + if name != "begin " { | |
275 | + return | |
276 | + } | |
277 | + spi := strings.Index(subname, " ") | |
278 | + if spi < 0 { | |
279 | + return | |
280 | + } | |
281 | + if strings.ToLower(subname[:spi+1]) != "action " { | |
282 | + return | |
283 | + } | |
284 | + (*i)++ | |
285 | + return Atoi(subname[spi+1:]), ReadAnimation(sff, lines, i) | |
286 | +} | |
266 | 287 | func (a *Animation) AnimTime() int32 { |
267 | 288 | return a.sumtime - a.totaltime |
268 | 289 | } |
@@ -468,6 +489,52 @@ func (a *Animation) Draw(window *[4]int32, x, y, xcs, ycs, xs, xbs, ys, | ||
468 | 489 | rcx, rcy, pfx) |
469 | 490 | } |
470 | 491 | |
492 | +type AnimationTable struct{ table map[int32]*Animation } | |
493 | + | |
494 | +func NewAnimationTable() *AnimationTable { | |
495 | + return &AnimationTable{table: make(map[int32]*Animation)} | |
496 | +} | |
497 | +func (al *AnimationTable) NewAnimation(no int32, | |
498 | + sff *Sff, lines []string, i *int) *Animation { | |
499 | + a := ReadAnimation(sff, lines, i) | |
500 | + al.table[no] = a | |
501 | + return a | |
502 | +} | |
503 | +func (al *AnimationTable) readActionSub(sff *Sff, | |
504 | + lines []string, i *int) *Animation { | |
505 | + for *i < len(lines) { | |
506 | + no, a := ReadAction(sff, lines, i) | |
507 | + if a != nil { | |
508 | + if al.table[no] == nil { | |
509 | + al.table[no] = a | |
510 | + for len(a.frames) == 0 { | |
511 | + a2 := al.readActionSub(sff, lines, i) | |
512 | + if a2 != nil { | |
513 | + *a = *a2 | |
514 | + } | |
515 | + } | |
516 | + } | |
517 | + return a | |
518 | + } else { | |
519 | + (*i)++ | |
520 | + } | |
521 | + } | |
522 | + return nil | |
523 | +} | |
524 | +func (al *AnimationTable) ReadAction(sff *Sff, lines []string, i *int) { | |
525 | + for al.readActionSub(sff, lines, i) != nil { | |
526 | + } | |
527 | +} | |
528 | +func (al *AnimationTable) get(no int32) *Animation { | |
529 | + a := al.table[no] | |
530 | + if a == nil { | |
531 | + return a | |
532 | + } | |
533 | + ret := &Animation{} | |
534 | + *ret = *a | |
535 | + return ret | |
536 | +} | |
537 | + | |
471 | 538 | type Anim struct { |
472 | 539 | anim *Animation |
473 | 540 | window [4]int32 |
@@ -1,6 +1,7 @@ | ||
1 | 1 | package main |
2 | 2 | |
3 | 3 | import ( |
4 | + "io/ioutil" | |
4 | 5 | "math" |
5 | 6 | "strings" |
6 | 7 | ) |
@@ -151,6 +152,17 @@ func AsciiToString(ascii []byte) string { | ||
151 | 152 | } |
152 | 153 | return string(buf) |
153 | 154 | } |
155 | +func LoadText(filename string) (string, error) { | |
156 | + bytes, err := ioutil.ReadFile(filename) | |
157 | + if err != nil { | |
158 | + return "", err | |
159 | + } | |
160 | + if len(bytes) >= 3 && | |
161 | + bytes[0] == 0xef && bytes[1] == 0xbb && bytes[2] == 0xbf { | |
162 | + return string(bytes[3:]), nil | |
163 | + } | |
164 | + return AsciiToString(bytes), nil | |
165 | +} | |
154 | 166 | func SplitAndTrim(str, sep string) (ss []string) { |
155 | 167 | ss = strings.Split(str, sep) |
156 | 168 | for i, s := range ss { |
@@ -170,7 +182,7 @@ func SectionName(sec string) (string, string) { | ||
170 | 182 | var name string |
171 | 183 | i := strings.Index(sec, " ") |
172 | 184 | if i >= 0 { |
173 | - name = sec[:i] | |
185 | + name = sec[:i+1] | |
174 | 186 | sec = sec[i+1:] |
175 | 187 | } else { |
176 | 188 | name = sec |
@@ -868,8 +868,10 @@ func (c *Command) bufTest(cbuf *CommandBuffer, ai bool, | ||
868 | 868 | if c.tamei != c.cmdi { |
869 | 869 | if c.cmd[c.cmdi].tametime > 1 { |
870 | 870 | for _, k := range c.cmd[c.cmdi].key { |
871 | - ks:=cbuf.State(k) | |
872 | - if ks>0{return ai} | |
871 | + ks := cbuf.State(k) | |
872 | + if ks > 0 { | |
873 | + return ai | |
874 | + } | |
873 | 875 | if func() bool { |
874 | 876 | if ai { |
875 | 877 | return Rand(0, c.cmd[c.cmdi].tametime) != 0 |
@@ -947,3 +949,15 @@ func (c *Command) Step(cbuf *CommandBuffer, ai, hitpause bool, buftime int32) { | ||
947 | 949 | c.curbuftime = c.buftime + buftime |
948 | 950 | } |
949 | 951 | } |
952 | + | |
953 | +type CommandList struct { | |
954 | + Buffer []CommandBuffer | |
955 | + Names map[string]int | |
956 | + Commands [][]Command | |
957 | + DefaultTime int32 | |
958 | + DefaultBufferTime int32 | |
959 | +} | |
960 | + | |
961 | +func NewCommandList() *CommandList { | |
962 | + return &CommandList{Names: make(map[string]int)} | |
963 | +} |
@@ -0,0 +1,13 @@ | ||
1 | +package main | |
2 | + | |
3 | +type Lifebar struct{ aniTbl *AnimationTable } | |
4 | + | |
5 | +func LoadLifebar(deffile string) (*Lifebar, error) { | |
6 | + l := &Lifebar{aniTbl: NewAnimationTable()} | |
7 | + str, err := LoadText(deffile) | |
8 | + if err != nil { | |
9 | + return nil, err | |
10 | + } | |
11 | + lines := SplitAndTrim(str, "\n") | |
12 | + return l, nil | |
13 | +} |
@@ -14,9 +14,13 @@ var gameWidth, gameHeight int32 = 320, 240 | ||
14 | 14 | var widthScale, heightScale float32 = 1, 1 |
15 | 15 | var window *glfw.Window |
16 | 16 | var gameEnd, frameSkip = false, false |
17 | -var redrawWait = struct{ nextTime, lastDraw time.Time }{} | |
18 | -var brightness = int32(256) | |
19 | -var introTime = int32(0) | |
17 | +var redrawWait struct{ nextTime, lastDraw time.Time } | |
18 | +var brightness int32 = 256 | |
19 | +var introTime, roundTime int32 = 0, -1 | |
20 | +var lifeMul, team1VS2Life float32 = 1, 1 | |
21 | +var turnsRecoveryRate float32 = 1.0 / 300 | |
22 | +var zoomEnable = false | |
23 | +var zoomMin, zoomMax, zoomSpeed float32 = 1, 1, 1 | |
20 | 24 | |
21 | 25 | func init() { |
22 | 26 | runtime.LockOSThread() |
@@ -12,24 +12,31 @@ func luaRegister(l *lua.State, name string, f func(*lua.State) int) { | ||
12 | 12 | func strArg(l *lua.State, argi int) string { |
13 | 13 | str, ok := l.ToString(argi) |
14 | 14 | if !ok { |
15 | - panic(lua.RuntimeError( | |
16 | - fmt.Sprintf("%d番目の引数が文字列ではありません。", argi))) | |
15 | + lua.Errorf(l, "%d番目の引数が文字列ではありません。", argi) | |
17 | 16 | } |
18 | 17 | return str |
19 | 18 | } |
20 | 19 | func numArg(l *lua.State, argi int) float64 { |
21 | 20 | num, ok := l.ToNumber(argi) |
22 | 21 | if !ok { |
23 | - panic(lua.RuntimeError( | |
24 | - fmt.Sprintf("%d番目の引数が数ではありません。", argi))) | |
22 | + lua.Errorf(l, "%d番目の引数が数ではありません。", argi) | |
25 | 23 | } |
26 | 24 | return num |
27 | 25 | } |
26 | +func boolArg(l *lua.State, argi int) bool { | |
27 | + if !l.IsBoolean(argi) { | |
28 | + lua.Errorf(l, "%d番目の引数が論理値ではありません。", argi) | |
29 | + } | |
30 | + return l.ToBoolean(argi) | |
31 | +} | |
32 | +func userDataError(l *lua.State, argi int, udtype interface{}) { | |
33 | + lua.Errorf(l, fmt.Sprintf("%d番目の引数が%Tではありません。", argi, udtype)) | |
34 | +} | |
28 | 35 | func scriptCommonInit(l *lua.State) { |
29 | 36 | luaRegister(l, "sffNew", func(l *lua.State) int { |
30 | 37 | sff, err := LoadSff(strArg(l, 1), false) |
31 | 38 | if err != nil { |
32 | - panic(lua.RuntimeError(err.Error())) | |
39 | + lua.Errorf(l, err.Error()) | |
33 | 40 | } |
34 | 41 | l.PushUserData(sff) |
35 | 42 | return 1 |
@@ -37,7 +44,7 @@ func scriptCommonInit(l *lua.State) { | ||
37 | 44 | luaRegister(l, "sndNew", func(l *lua.State) int { |
38 | 45 | snd, err := LoadSnd(strArg(l, 1)) |
39 | 46 | if err != nil { |
40 | - panic(lua.RuntimeError(err.Error())) | |
47 | + lua.Errorf(l, err.Error()) | |
41 | 48 | } |
42 | 49 | l.PushUserData(snd) |
43 | 50 | return 1 |
@@ -45,26 +52,31 @@ func scriptCommonInit(l *lua.State) { | ||
45 | 52 | luaRegister(l, "fontNew", func(l *lua.State) int { |
46 | 53 | fnt, err := LoadFnt(strArg(l, 1)) |
47 | 54 | if err != nil { |
48 | - panic(lua.RuntimeError(err.Error())) | |
55 | + lua.Errorf(l, err.Error()) | |
49 | 56 | } |
50 | 57 | l.PushUserData(fnt) |
51 | 58 | return 1 |
52 | 59 | }) |
53 | 60 | luaRegister(l, "sndPlay", func(l *lua.State) int { |
54 | - ud := l.ToUserData(1) | |
55 | - switch ud.(type) { | |
56 | - case *Snd: | |
57 | - default: | |
58 | - panic(lua.RuntimeError("1番目の引数がSndではありません。")) | |
61 | + s, ok := l.ToUserData(1).(*Snd) | |
62 | + if !ok { | |
63 | + userDataError(l, 1, s) | |
59 | 64 | } |
60 | - ud.(*Snd).Play(int32(numArg(l, 2)), int32(numArg(l, 3))) | |
65 | + s.Play(int32(numArg(l, 2)), int32(numArg(l, 3))) | |
61 | 66 | return 0 |
62 | 67 | }) |
63 | 68 | luaRegister(l, "playBGM", func(l *lua.State) int { |
64 | 69 | bgm.Open(strArg(l, 1)) |
65 | 70 | return 0 |
66 | 71 | }) |
72 | + luaRegister(l, "setRoundTime", func(l *lua.State) int { | |
73 | + roundTime = int32(numArg(l, 1)) | |
74 | + return 0 | |
75 | + }) | |
67 | 76 | } |
77 | + | |
78 | +// System Script | |
79 | + | |
68 | 80 | func systemScriptInit(l *lua.State) { |
69 | 81 | scriptCommonInit(l) |
70 | 82 | luaRegister(l, "textImgNew", func(*lua.State) int { |
@@ -72,195 +84,188 @@ func systemScriptInit(l *lua.State) { | ||
72 | 84 | return 1 |
73 | 85 | }) |
74 | 86 | luaRegister(l, "textImgSetFont", func(*lua.State) int { |
75 | - ud := l.ToUserData(1) | |
76 | - switch ud.(type) { | |
77 | - case *TextSprite: | |
78 | - default: | |
79 | - panic(lua.RuntimeError("1番目の引数がTextSpriteではありません。")) | |
87 | + ts, ok := l.ToUserData(1).(*TextSprite) | |
88 | + if !ok { | |
89 | + userDataError(l, 1, ts) | |
80 | 90 | } |
81 | - fnt := l.ToUserData(2) | |
82 | - switch fnt.(type) { | |
83 | - case *Fnt: | |
84 | - default: | |
85 | - panic(lua.RuntimeError("2番目の引数がFntではありません。")) | |
91 | + fnt, ok2 := l.ToUserData(2).(*Fnt) | |
92 | + if !ok2 { | |
93 | + userDataError(l, 2, fnt) | |
86 | 94 | } |
87 | - ud.(*TextSprite).fnt = fnt.(*Fnt) | |
95 | + ts.fnt = fnt | |
88 | 96 | return 0 |
89 | 97 | }) |
90 | 98 | luaRegister(l, "textImgSetBank", func(*lua.State) int { |
91 | - ud := l.ToUserData(1) | |
92 | - switch ud.(type) { | |
93 | - case *TextSprite: | |
94 | - default: | |
95 | - panic(lua.RuntimeError("1番目の引数がTextSpriteではありません。")) | |
99 | + ts, ok := l.ToUserData(1).(*TextSprite) | |
100 | + if !ok { | |
101 | + userDataError(l, 1, ts) | |
96 | 102 | } |
97 | - ud.(*TextSprite).bank = int32(numArg(l, 2)) | |
103 | + ts.bank = int32(numArg(l, 2)) | |
98 | 104 | return 0 |
99 | 105 | }) |
100 | 106 | luaRegister(l, "textImgSetAlign", func(*lua.State) int { |
101 | - ud := l.ToUserData(1) | |
102 | - switch ud.(type) { | |
103 | - case *TextSprite: | |
104 | - default: | |
105 | - panic(lua.RuntimeError("1番目の引数がTextSpriteではありません。")) | |
107 | + ts, ok := l.ToUserData(1).(*TextSprite) | |
108 | + if !ok { | |
109 | + userDataError(l, 1, ts) | |
106 | 110 | } |
107 | - ud.(*TextSprite).align = int32(numArg(l, 2)) | |
111 | + ts.align = int32(numArg(l, 2)) | |
108 | 112 | return 0 |
109 | 113 | }) |
110 | 114 | luaRegister(l, "textImgSetText", func(*lua.State) int { |
111 | - ud := l.ToUserData(1) | |
112 | - switch ud.(type) { | |
113 | - case *TextSprite: | |
114 | - default: | |
115 | - panic(lua.RuntimeError("1番目の引数がTextSpriteではありません。")) | |
115 | + ts, ok := l.ToUserData(1).(*TextSprite) | |
116 | + if !ok { | |
117 | + userDataError(l, 1, ts) | |
116 | 118 | } |
117 | - ud.(*TextSprite).text = strArg(l, 2) | |
119 | + ts.text = strArg(l, 2) | |
118 | 120 | return 0 |
119 | 121 | }) |
120 | 122 | luaRegister(l, "textImgSetPos", func(*lua.State) int { |
121 | - ud := l.ToUserData(1) | |
122 | - switch ud.(type) { | |
123 | - case *TextSprite: | |
124 | - default: | |
125 | - panic(lua.RuntimeError("1番目の引数がTextSpriteではありません。")) | |
123 | + ts, ok := l.ToUserData(1).(*TextSprite) | |
124 | + if !ok { | |
125 | + userDataError(l, 1, ts) | |
126 | 126 | } |
127 | - ud.(*TextSprite).x = float32(numArg(l, 2)) | |
128 | - ud.(*TextSprite).y = float32(numArg(l, 3)) | |
127 | + ts.x, ts.y = float32(numArg(l, 2)), float32(numArg(l, 3)) | |
129 | 128 | return 0 |
130 | 129 | }) |
131 | 130 | luaRegister(l, "textImgSetScale", func(*lua.State) int { |
132 | - ud := l.ToUserData(1) | |
133 | - switch ud.(type) { | |
134 | - case *TextSprite: | |
135 | - default: | |
136 | - panic(lua.RuntimeError("1番目の引数がTextSpriteではありません。")) | |
131 | + ts, ok := l.ToUserData(1).(*TextSprite) | |
132 | + if !ok { | |
133 | + userDataError(l, 1, ts) | |
137 | 134 | } |
138 | - ud.(*TextSprite).xscl = float32(numArg(l, 2)) | |
139 | - ud.(*TextSprite).yscl = float32(numArg(l, 3)) | |
135 | + ts.xscl, ts.yscl = float32(numArg(l, 2)), float32(numArg(l, 3)) | |
140 | 136 | return 0 |
141 | 137 | }) |
142 | 138 | luaRegister(l, "textImgDraw", func(*lua.State) int { |
143 | - ud := l.ToUserData(1) | |
144 | - switch ud.(type) { | |
145 | - case *TextSprite: | |
146 | - default: | |
147 | - panic(lua.RuntimeError("1番目の引数がTextSpriteではありません。")) | |
139 | + ts, ok := l.ToUserData(1).(*TextSprite) | |
140 | + if !ok { | |
141 | + userDataError(l, 1, ts) | |
148 | 142 | } |
149 | - ud.(*TextSprite).Draw() | |
143 | + ts.Draw() | |
150 | 144 | return 0 |
151 | 145 | }) |
152 | 146 | luaRegister(l, "animNew", func(*lua.State) int { |
153 | - ud := l.ToUserData(1) | |
154 | - switch ud.(type) { | |
155 | - case *Sff: | |
156 | - default: | |
157 | - panic(lua.RuntimeError("1番目の引数がSffではありません。")) | |
147 | + s, ok := l.ToUserData(1).(*Sff) | |
148 | + if !ok { | |
149 | + userDataError(l, 1, s) | |
158 | 150 | } |
159 | 151 | act := strArg(l, 2) |
160 | - anim := NewAnim(ud.(*Sff), act) | |
152 | + anim := NewAnim(s, act) | |
161 | 153 | if anim == nil { |
162 | - panic(lua.RuntimeError(fmt.Sprintf( | |
163 | - "\n%s\n\nデータの読み込みに失敗しました。", act))) | |
154 | + lua.Errorf(l, "\n%s\n\nデータの読み込みに失敗しました。", act) | |
164 | 155 | } |
165 | 156 | l.PushUserData(anim) |
166 | 157 | return 1 |
167 | 158 | }) |
168 | 159 | luaRegister(l, "animSetPos", func(*lua.State) int { |
169 | - ud := l.ToUserData(1) | |
170 | - switch ud.(type) { | |
171 | - case *Anim: | |
172 | - default: | |
173 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
160 | + a, ok := l.ToUserData(1).(*Anim) | |
161 | + if !ok { | |
162 | + userDataError(l, 1, a) | |
174 | 163 | } |
175 | - ud.(*Anim).SetPos(float32(numArg(l, 2)), float32(numArg(l, 3))) | |
164 | + a.SetPos(float32(numArg(l, 2)), float32(numArg(l, 3))) | |
176 | 165 | return 0 |
177 | 166 | }) |
178 | 167 | luaRegister(l, "animAddPos", func(*lua.State) int { |
179 | - ud := l.ToUserData(1) | |
180 | - switch ud.(type) { | |
181 | - case *Anim: | |
182 | - default: | |
183 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
168 | + a, ok := l.ToUserData(1).(*Anim) | |
169 | + if !ok { | |
170 | + userDataError(l, 1, a) | |
184 | 171 | } |
185 | - ud.(*Anim).AddPos(float32(numArg(l, 2)), float32(numArg(l, 3))) | |
172 | + a.AddPos(float32(numArg(l, 2)), float32(numArg(l, 3))) | |
186 | 173 | return 0 |
187 | 174 | }) |
188 | 175 | luaRegister(l, "animSetTile", func(*lua.State) int { |
189 | - ud := l.ToUserData(1) | |
190 | - switch ud.(type) { | |
191 | - case *Anim: | |
192 | - default: | |
193 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
176 | + a, ok := l.ToUserData(1).(*Anim) | |
177 | + if !ok { | |
178 | + userDataError(l, 1, a) | |
194 | 179 | } |
195 | - ud.(*Anim).SetTile(int32(numArg(l, 2)), int32(numArg(l, 3))) | |
180 | + a.SetTile(int32(numArg(l, 2)), int32(numArg(l, 3))) | |
196 | 181 | return 0 |
197 | 182 | }) |
198 | 183 | luaRegister(l, "animSetColorKey", func(*lua.State) int { |
199 | - ud := l.ToUserData(1) | |
200 | - switch ud.(type) { | |
201 | - case *Anim: | |
202 | - default: | |
203 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
184 | + a, ok := l.ToUserData(1).(*Anim) | |
185 | + if !ok { | |
186 | + userDataError(l, 1, a) | |
204 | 187 | } |
205 | - ud.(*Anim).SetColorKey(int16(numArg(l, 2))) | |
188 | + a.SetColorKey(int16(numArg(l, 2))) | |
206 | 189 | return 0 |
207 | 190 | }) |
208 | 191 | luaRegister(l, "animSetAlpha", func(*lua.State) int { |
209 | - ud := l.ToUserData(1) | |
210 | - switch ud.(type) { | |
211 | - case *Anim: | |
212 | - default: | |
213 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
192 | + a, ok := l.ToUserData(1).(*Anim) | |
193 | + if !ok { | |
194 | + userDataError(l, 1, a) | |
214 | 195 | } |
215 | - ud.(*Anim).SetAlpha(int16(numArg(l, 2)), int16(numArg(l, 3))) | |
196 | + a.SetAlpha(int16(numArg(l, 2)), int16(numArg(l, 3))) | |
216 | 197 | return 0 |
217 | 198 | }) |
218 | 199 | luaRegister(l, "animSetScale", func(*lua.State) int { |
219 | - ud := l.ToUserData(1) | |
220 | - switch ud.(type) { | |
221 | - case *Anim: | |
222 | - default: | |
223 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
200 | + a, ok := l.ToUserData(1).(*Anim) | |
201 | + if !ok { | |
202 | + userDataError(l, 1, a) | |
224 | 203 | } |
225 | - ud.(*Anim).SetScale(float32(numArg(l, 2)), float32(numArg(l, 3))) | |
204 | + a.SetScale(float32(numArg(l, 2)), float32(numArg(l, 3))) | |
226 | 205 | return 0 |
227 | 206 | }) |
228 | 207 | luaRegister(l, "animSetWindow", func(*lua.State) int { |
229 | - ud := l.ToUserData(1) | |
230 | - switch ud.(type) { | |
231 | - case *Anim: | |
232 | - default: | |
233 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
208 | + a, ok := l.ToUserData(1).(*Anim) | |
209 | + if !ok { | |
210 | + userDataError(l, 1, a) | |
234 | 211 | } |
235 | - ud.(*Anim).SetWindow(float32(numArg(l, 2)), float32(numArg(l, 3)), | |
212 | + a.SetWindow(float32(numArg(l, 2)), float32(numArg(l, 3)), | |
236 | 213 | float32(numArg(l, 4)), float32(numArg(l, 5))) |
237 | 214 | return 0 |
238 | 215 | }) |
239 | 216 | luaRegister(l, "animUpdate", func(*lua.State) int { |
240 | - ud := l.ToUserData(1) | |
241 | - switch ud.(type) { | |
242 | - case *Anim: | |
243 | - default: | |
244 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
217 | + a, ok := l.ToUserData(1).(*Anim) | |
218 | + if !ok { | |
219 | + userDataError(l, 1, a) | |
245 | 220 | } |
246 | - ud.(*Anim).Update() | |
221 | + a.Update() | |
247 | 222 | return 0 |
248 | 223 | }) |
249 | 224 | luaRegister(l, "animDraw", func(*lua.State) int { |
250 | - ud := l.ToUserData(1) | |
251 | - switch ud.(type) { | |
252 | - case *Anim: | |
253 | - default: | |
254 | - panic(lua.RuntimeError("1番目の引数がAnimではありません。")) | |
225 | + a, ok := l.ToUserData(1).(*Anim) | |
226 | + if !ok { | |
227 | + userDataError(l, 1, a) | |
255 | 228 | } |
256 | - ud.(*Anim).Draw() | |
229 | + a.Draw() | |
257 | 230 | return 0 |
258 | 231 | }) |
259 | 232 | luaRegister(l, "refresh", func(*lua.State) int { |
260 | 233 | await(60) |
261 | 234 | if gameEnd { |
262 | - panic(lua.RuntimeError("<game end>")) | |
235 | + lua.Errorf(l, "<game end>") | |
263 | 236 | } |
264 | 237 | return 0 |
265 | 238 | }) |
239 | + luaRegister(l, "loadLifebar", func(l *lua.State) int { | |
240 | + lua.Errorf(l, strArg(l, 1)) | |
241 | + return 0 | |
242 | + }) | |
243 | + luaRegister(l, "setLifeMul", func(l *lua.State) int { | |
244 | + lifeMul = float32(numArg(l, 1)) | |
245 | + return 0 | |
246 | + }) | |
247 | + luaRegister(l, "setTeam1VS2Life", func(l *lua.State) int { | |
248 | + team1VS2Life = float32(numArg(l, 1)) | |
249 | + return 0 | |
250 | + }) | |
251 | + luaRegister(l, "setTurnsRecoveryRate", func(l *lua.State) int { | |
252 | + turnsRecoveryRate = float32(numArg(l, 1)) | |
253 | + return 0 | |
254 | + }) | |
255 | + luaRegister(l, "setZoom", func(l *lua.State) int { | |
256 | + zoomEnable = boolArg(l, 1) | |
257 | + return 0 | |
258 | + }) | |
259 | + luaRegister(l, "setZoomMin", func(l *lua.State) int { | |
260 | + zoomMin = float32(numArg(l, 1)) | |
261 | + return 0 | |
262 | + }) | |
263 | + luaRegister(l, "setZoomMax", func(l *lua.State) int { | |
264 | + zoomMax = float32(numArg(l, 1)) | |
265 | + return 0 | |
266 | + }) | |
267 | + luaRegister(l, "setZoomSpeed", func(l *lua.State) int { | |
268 | + zoomSpeed = float32(numArg(l, 1)) | |
269 | + return 0 | |
270 | + }) | |
266 | 271 | } |