• R/O
  • HTTP
  • SSH
  • HTTPS

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Go で書き直した Ikemen


Commit MetaInfo

修订版d9002f424c499e26beabf3757d7baf62ff2cacb9 (tree)
时间2016-12-04 00:11:31
作者SUEHIRO <supersuehiro@user...>
CommiterSUEHIRO

Log Message

キャラクターを選択する画面まで

更改概述

差异

--- a/src/script.go
+++ b/src/script.go
@@ -364,8 +364,8 @@ func systemScriptInit(l *lua.LState) {
364364 return 0
365365 })
366366 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))
369369 return 0
370370 })
371371 luaRegister(l, "setSelCellSize", func(*lua.LState) int {
@@ -381,6 +381,59 @@ func systemScriptInit(l *lua.LState) {
381381 l.Push(lua.LNumber(sys.sel.SetStageNo(int(numArg(l, 1)))))
382382 return 1
383383 })
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+ })
384437 luaRegister(l, "refresh", func(*lua.LState) int {
385438 sys.await(60)
386439 if sys.gameEnd {
@@ -388,6 +441,50 @@ func systemScriptInit(l *lua.LState) {
388441 }
389442 return 0
390443 })
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+ })
391488 luaRegister(l, "loadLifebar", func(l *lua.LState) int {
392489 lb, err := LoadLifebar(strArg(l, 1))
393490 if err != nil {
--- a/src/system.go
+++ b/src/system.go
@@ -7,6 +7,7 @@ import (
77 "github.com/yuin/gopher-lua"
88 "runtime"
99 "strings"
10+ "sync"
1011 "time"
1112 )
1213
@@ -41,6 +42,7 @@ const (
4142 TM_Single TeamMode = iota
4243 TM_Simul
4344 TM_Turns
45+ TM_LAST = TM_Turns
4446 )
4547
4648 type System struct {
@@ -88,6 +90,7 @@ type System struct {
8890 numSimul [2]int
8991 numTurns [2]int
9092 esc bool
93+ loadMutex sync.Mutex
9194 }
9295
9396 func (s *System) init(w, h int32) *lua.LState {
@@ -178,7 +181,7 @@ type SelectStage struct {
178181 def, name string
179182 }
180183 type Select struct {
181- columns, rows int32
184+ columns, rows int
182185 cellsize [2]float32
183186 cellscale [2]float32
184187 randomspr *Sprite
@@ -195,6 +198,23 @@ func newSelect() *Select {
195198 cellsize: [2]float32{29, 29}, cellscale: [2]float32{1, 1},
196199 selectedStageNo: -1}
197200 }
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+}
198218 func (s *Select) SetStageNo(n int) int {
199219 s.curStageNo = n % (len(s.stagelist) + 1)
200220 if s.curStageNo < 0 {
@@ -232,8 +252,8 @@ func (s *Select) AddCahr(def string) {
232252 if err != nil {
233253 return
234254 }
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, ""
237257 for i < len(lines) {
238258 is, name, _ := ReadIniSection(lines, &i)
239259 switch name {
@@ -295,6 +315,24 @@ func (s *Select) AddStage(def string) error {
295315 }
296316 return nil
297317 }
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+}
298336 func (s *Select) ClearSelected() {
299337 s.selected = [2][][2]int{}
300338 s.selectedStageNo = -1