Go で書き直した Ikemen
修订版 | d9002f424c499e26beabf3757d7baf62ff2cacb9 (tree) |
---|---|
时间 | 2016-12-04 00:11:31 |
作者 | SUEHIRO <supersuehiro@user...> |
Commiter | SUEHIRO |
キャラクターを選択する画面まで
@@ -364,8 +364,8 @@ func systemScriptInit(l *lua.LState) { | ||
364 | 364 | return 0 |
365 | 365 | }) |
366 | 366 | luaRegister(l, "setSelColRow", func(*lua.LState) int { |
367 | - sys.sel.columns = int32(numArg(l, 1)) | |
368 | - sys.sel.rows = int32(numArg(l, 2)) | |
367 | + sys.sel.columns = int(numArg(l, 1)) | |
368 | + sys.sel.rows = int(numArg(l, 2)) | |
369 | 369 | return 0 |
370 | 370 | }) |
371 | 371 | luaRegister(l, "setSelCellSize", func(*lua.LState) int { |
@@ -381,6 +381,59 @@ func systemScriptInit(l *lua.LState) { | ||
381 | 381 | l.Push(lua.LNumber(sys.sel.SetStageNo(int(numArg(l, 1))))) |
382 | 382 | return 1 |
383 | 383 | }) |
384 | + luaRegister(l, "setTeamMode", func(*lua.LState) int { | |
385 | + pn := int(numArg(l, 1)) | |
386 | + if pn < 1 || pn > 2 { | |
387 | + l.RaiseError("チーム番号(%v)が不正です。", pn) | |
388 | + } | |
389 | + tm := TeamMode(numArg(l, 2)) | |
390 | + if tm < 0 || tm > TM_LAST { | |
391 | + l.RaiseError("モード番号(%v)が不正です。", tm) | |
392 | + } | |
393 | + nt := int(numArg(l, 3)) | |
394 | + if nt < 1 || nt > MaxSimul { | |
395 | + l.RaiseError("チーム人数(%v)が不正です。", nt) | |
396 | + } | |
397 | + sys.sel.selected[pn-1] = nil | |
398 | + sys.tmode[pn-1] = tm | |
399 | + sys.numTurns[pn-1], sys.numSimul[pn-1] = nt, nt | |
400 | + if tm == TM_Simul && nt == 1 { | |
401 | + sys.tmode[pn-1] = TM_Single | |
402 | + } | |
403 | + return 0 | |
404 | + }) | |
405 | + luaRegister(l, "getCharName", func(*lua.LState) int { | |
406 | + c := sys.sel.GetChar(int(numArg(l, 1))) | |
407 | + l.Push(lua.LString(c.name)) | |
408 | + return 1 | |
409 | + }) | |
410 | + luaRegister(l, "selectChar", func(*lua.LState) int { | |
411 | + pn := int(numArg(l, 1)) | |
412 | + if pn < 1 || pn > 2 { | |
413 | + l.RaiseError("チーム番号(%v)が不正です。", pn) | |
414 | + } | |
415 | + cn, pl, ret := int(numArg(l, 2)), int(numArg(l, 3)), 0 | |
416 | + if pl >= 1 && pl <= 12 && sys.sel.AddSelectedChar(pn-1, cn, pl) { | |
417 | + switch sys.tmode[pn-1] { | |
418 | + case TM_Single: | |
419 | + ret = 2 | |
420 | + case TM_Simul: | |
421 | + if len(sys.sel.selected[pn-1]) >= sys.numSimul[pn-1] { | |
422 | + ret = 2 | |
423 | + } else { | |
424 | + ret = 1 | |
425 | + } | |
426 | + case TM_Turns: | |
427 | + if len(sys.sel.selected[pn-1]) >= sys.numTurns[pn-1] { | |
428 | + ret = 2 | |
429 | + } else { | |
430 | + ret = 1 | |
431 | + } | |
432 | + } | |
433 | + } | |
434 | + l.Push(lua.LNumber(ret)) | |
435 | + return 1 | |
436 | + }) | |
384 | 437 | luaRegister(l, "refresh", func(*lua.LState) int { |
385 | 438 | sys.await(60) |
386 | 439 | if sys.gameEnd { |
@@ -388,6 +441,50 @@ func systemScriptInit(l *lua.LState) { | ||
388 | 441 | } |
389 | 442 | return 0 |
390 | 443 | }) |
444 | + luaRegister(l, "drawPortrait", func(l *lua.LState) int { | |
445 | + n, x, y := int(numArg(l, 1)), float32(numArg(l, 2)), float32(numArg(l, 3)) | |
446 | + var xscl, yscl float32 = 1, 1 | |
447 | + if l.GetTop() >= 4 { | |
448 | + xscl = float32(numArg(l, 4)) | |
449 | + if l.GetTop() >= 5 { | |
450 | + yscl = float32(numArg(l, 5)) | |
451 | + } | |
452 | + } | |
453 | + if !sys.frameSkip { | |
454 | + c := sys.sel.GetChar(n) | |
455 | + if c != nil && c.lportrait != nil { | |
456 | + c.lportrait.Draw(x, y, xscl, yscl, c.lportrait.Pal) | |
457 | + } | |
458 | + } | |
459 | + return 0 | |
460 | + }) | |
461 | + luaRegister(l, "drawFace", func(l *lua.LState) int { | |
462 | + x, y := float32(numArg(l, 1)), float32(numArg(l, 2)) | |
463 | + offset := 0 | |
464 | + if l.GetTop() >= 3 { | |
465 | + offset = int(numArg(l, 3)) | |
466 | + } | |
467 | + if !sys.frameSkip { | |
468 | + for j := 0; j < sys.sel.rows; j++ { | |
469 | + for i := 0; i < sys.sel.columns; i++ { | |
470 | + c := sys.sel.GetChar(offset) | |
471 | + offset++ | |
472 | + if c != nil { | |
473 | + if c.sportrait != nil { | |
474 | + c.sportrait.Draw(x+float32(i)*sys.sel.cellsize[0], | |
475 | + y+float32(j)*sys.sel.cellsize[1], sys.sel.cellscale[0], | |
476 | + sys.sel.cellscale[1], c.sportrait.Pal) | |
477 | + } else if c.def == "randomselect" && sys.sel.randomspr != nil { | |
478 | + sys.sel.randomspr.Draw(x+float32(i)*sys.sel.cellsize[0], | |
479 | + y+float32(j)*sys.sel.cellsize[1], sys.sel.randomscl[0], | |
480 | + sys.sel.randomscl[1], sys.sel.randomspr.Pal) | |
481 | + } | |
482 | + } | |
483 | + } | |
484 | + } | |
485 | + } | |
486 | + return 0 | |
487 | + }) | |
391 | 488 | luaRegister(l, "loadLifebar", func(l *lua.LState) int { |
392 | 489 | lb, err := LoadLifebar(strArg(l, 1)) |
393 | 490 | if err != nil { |
@@ -7,6 +7,7 @@ import ( | ||
7 | 7 | "github.com/yuin/gopher-lua" |
8 | 8 | "runtime" |
9 | 9 | "strings" |
10 | + "sync" | |
10 | 11 | "time" |
11 | 12 | ) |
12 | 13 |
@@ -41,6 +42,7 @@ const ( | ||
41 | 42 | TM_Single TeamMode = iota |
42 | 43 | TM_Simul |
43 | 44 | TM_Turns |
45 | + TM_LAST = TM_Turns | |
44 | 46 | ) |
45 | 47 | |
46 | 48 | type System struct { |
@@ -88,6 +90,7 @@ type System struct { | ||
88 | 90 | numSimul [2]int |
89 | 91 | numTurns [2]int |
90 | 92 | esc bool |
93 | + loadMutex sync.Mutex | |
91 | 94 | } |
92 | 95 | |
93 | 96 | func (s *System) init(w, h int32) *lua.LState { |
@@ -178,7 +181,7 @@ type SelectStage struct { | ||
178 | 181 | def, name string |
179 | 182 | } |
180 | 183 | type Select struct { |
181 | - columns, rows int32 | |
184 | + columns, rows int | |
182 | 185 | cellsize [2]float32 |
183 | 186 | cellscale [2]float32 |
184 | 187 | randomspr *Sprite |
@@ -195,6 +198,23 @@ func newSelect() *Select { | ||
195 | 198 | cellsize: [2]float32{29, 29}, cellscale: [2]float32{1, 1}, |
196 | 199 | selectedStageNo: -1} |
197 | 200 | } |
201 | +func (s *Select) GetCharNo(i int) int { | |
202 | + n := i | |
203 | + if len(s.charlist) > 0 { | |
204 | + n %= len(s.charlist) | |
205 | + if n < 0 { | |
206 | + n += len(s.charlist) | |
207 | + } | |
208 | + } | |
209 | + return n | |
210 | +} | |
211 | +func (s *Select) GetChar(i int) *SelectChar { | |
212 | + if len(s.charlist) == 0 { | |
213 | + return nil | |
214 | + } | |
215 | + n := s.GetCharNo(i) | |
216 | + return &s.charlist[n] | |
217 | +} | |
198 | 218 | func (s *Select) SetStageNo(n int) int { |
199 | 219 | s.curStageNo = n % (len(s.stagelist) + 1) |
200 | 220 | if s.curStageNo < 0 { |
@@ -232,8 +252,8 @@ func (s *Select) AddCahr(def string) { | ||
232 | 252 | if err != nil { |
233 | 253 | return |
234 | 254 | } |
235 | - lines, i, info, files := SplitAndTrim(str, "\n"), 0, true, true | |
236 | - sprite := "" | |
255 | + sc.def = def | |
256 | + lines, i, info, files, sprite := SplitAndTrim(str, "\n"), 0, true, true, "" | |
237 | 257 | for i < len(lines) { |
238 | 258 | is, name, _ := ReadIniSection(lines, &i) |
239 | 259 | switch name { |
@@ -295,6 +315,24 @@ func (s *Select) AddStage(def string) error { | ||
295 | 315 | } |
296 | 316 | return nil |
297 | 317 | } |
318 | +func (s *Select) AddSelectedChar(pn, cn, pl int) bool { | |
319 | + m, n := 0, s.GetCharNo(cn) | |
320 | + if len(s.charlist) == 0 || len(s.charlist[n].def) == 0 { | |
321 | + return false | |
322 | + } | |
323 | + for s.charlist[n].def == "randomselect" || len(s.charlist[n].def) == 0 { | |
324 | + m++ | |
325 | + if m > 100000 { | |
326 | + return false | |
327 | + } | |
328 | + n = int(Rand(0, int32(len(s.charlist))-1)) | |
329 | + pl = int(Rand(1, 12)) | |
330 | + } | |
331 | + sys.loadMutex.Lock() | |
332 | + s.selected[pn] = append(s.selected[pn], [2]int{n, pl}) | |
333 | + sys.loadMutex.Unlock() | |
334 | + return true | |
335 | +} | |
298 | 336 | func (s *Select) ClearSelected() { |
299 | 337 | s.selected = [2][][2]int{} |
300 | 338 | s.selectedStageNo = -1 |