• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

Go で書き直した Ikemen


コミットメタ情報

リビジョン8644bb1382647546d344a7cfeccf9dddec24b614 (tree)
日時2019-02-20 17:55:52
作者neatunsou <sisiy4excite@gmai...>
コミッターneatunsou

ログメッセージ

Windblade氏の更新を適応

変更サマリ

差分

--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -1,7 +1,10 @@
1-MIT License
1+?ソMIT License
22
33 Original work Copyright (c) 2016 Suehiro
44 Modified work Copyright (c) 2018 K4thos
5+Modified work Copyright (c) 2018 ShinLucho
6+Modified work Copyright (c) 2018 NeatUnsou
7+Modified work Copyright (c) 2019 Windblade
58
69 Permission is hereby granted, free of charge, to any person obtaining a copy
710 of this software and associated documentation files (the "Software"), to deal
@@ -22,20 +25,27 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2225 SOFTWARE.
2326
2427
25-以下に定める条件に従い、本ソフトウェアおよび関連文書のファイル(以下「ソフトウェア」)
26-の複製を取得するすべての人に対し、ソフトウェアを無制限に扱うことを無償で許可します。
27-これには、ソフトウェアの複製を使用、複写、変更、結合、掲載、頒布、サブライセンス、および
28-または販売する権利、およびソフトウェアを提供する相手に同じことを許可する権利も無制限に含まれます。
28+窶サNote
29+Data files below, font Following files contain content created by a third party,
30+It is not covered by this license.
2931
30-上記の著作権表示および本許諾表示を、ソフトウェアのすべての複製または重要な部分に記載するものとします。
3132
32-ソフトウェアは「現状のまま」で、明示であるか暗黙であるかを問わず、何らの保証もなく提供されます。
33-ここでいう保証とは、商品性、特定の目的への適合性、および権利非侵害についての保証も含みますが、
34-それに限定されるものではありません。 作者または著作権者は、契約行為、不法行為、またはそれ以外であろうと、
35-ソフトウェアに起因または関連し、あるいはソフトウェアの使用またはその他の扱いによって生じる一切の請求、損害、
36-その他の義務について何らの責任も負わないものとします。
3733
3834
39-※注意
40-data以下のファイル, font以下のファイルには第三者が作成したコンテンツを含んでいるため、
41-このライセンスの対象外となります。
35+莉・荳九↓螳壹a繧区擅莉カ縺ォ蠕薙>縲∵悽繧ス繝輔ヨ繧ヲ繧ァ繧「縺翫h縺ウ髢「騾」譁?嶌縺ョ繝輔ぃ繧、繝ォ?井サ・荳九?後た繝輔ヨ繧ヲ繧ァ繧「縲搾シ
36+縺ョ隍?」ス繧貞叙蠕励☆繧九☆縺ケ縺ヲ縺ョ莠コ縺ォ蟇セ縺励?√た繝輔ヨ繧ヲ繧ァ繧「繧堤┌蛻カ髯舌↓謇ア縺?%縺ィ繧堤┌蜆溘〒險ア蜿ッ縺励∪縺吶?
37+縺薙l縺ォ縺ッ縲√た繝輔ヨ繧ヲ繧ァ繧「縺ョ隍?」ス繧剃スソ逕ィ縲∬、??縲∝、画峩縲∫オ仙粋縲∵軸霈峨???貞ク??√し繝悶Λ繧、繧サ繝ウ繧ケ縲√♀繧医?
38+縺セ縺溘?雋ゥ螢イ縺吶k讓ゥ蛻ゥ縲√♀繧医?繧ス繝輔ヨ繧ヲ繧ァ繧「繧呈署萓帙☆繧狗嶌謇九↓蜷後§縺薙→繧定ィア蜿ッ縺吶k讓ゥ蛻ゥ繧ら┌蛻カ髯舌↓蜷ォ縺セ繧後∪縺吶?
39+
40+荳願ィ倥?闡嶺ス懈ィゥ陦ィ遉コ縺翫h縺ウ譛ャ險ア隲セ陦ィ遉コ繧偵?√た繝輔ヨ繧ヲ繧ァ繧「縺ョ縺吶∋縺ヲ縺ョ隍?」ス縺セ縺溘?驥崎ヲ√↑驛ィ蛻?↓險倩シ峨☆繧九b縺ョ縺ィ縺励∪縺吶?
41+
42+繧ス繝輔ヨ繧ヲ繧ァ繧「縺ッ縲檎樟迥カ縺ョ縺セ縺セ縲阪〒縲∵?遉コ縺ァ縺ゅk縺区囓鮟吶〒縺ゅk縺九r蝠上o縺壹?∽ス輔i縺ョ菫晁ィシ繧ゅ↑縺乗署萓帙&繧後∪縺吶?
43+縺薙%縺ァ縺?≧菫晁ィシ縺ィ縺ッ縲∝膚蜩∵?ァ縲∫音螳壹?逶ョ逧?∈縺ョ驕ゥ蜷域?ァ縲√♀繧医?讓ゥ蛻ゥ髱樔セオ螳ウ縺ォ縺、縺?※縺ョ菫晁ィシ繧ょ性縺ソ縺セ縺吶′縲
44+縺昴l縺ォ髯仙ョ壹&繧後k繧ゅ?縺ァ縺ッ縺ゅj縺セ縺帙s縲 菴懆??∪縺溘?闡嶺ス懈ィゥ閠??縲∝・醍エ?。檎ぜ縲∽ク肴ウ戊。檎ぜ縲√∪縺溘?縺昴l莉・螟悶〒縺ゅm縺?→縲
45+繧ス繝輔ヨ繧ヲ繧ァ繧「縺ォ襍キ蝗?縺セ縺溘?髢「騾」縺励?√≠繧九>縺ッ繧ス繝輔ヨ繧ヲ繧ァ繧「縺ョ菴ソ逕ィ縺セ縺溘?縺昴?莉悶?謇ア縺?↓繧医▲縺ヲ逕溘§繧倶ク?蛻??隲区アゅ?∵錐螳ウ縲
46+縺昴?莉悶?鄒ゥ蜍吶↓縺、縺?※菴輔i縺ョ雋ャ莉サ繧りイ?繧上↑縺?b縺ョ縺ィ縺励∪縺吶?
47+
48+
49+窶サ豕ィ諢
50+data莉・荳九?繝輔ぃ繧、繝ォ, font莉・荳九?繝輔ぃ繧、繝ォ縺ォ縺ッ隨ャ荳芽??′菴懈?縺励◆繧ウ繝ウ繝?Φ繝?r蜷ォ繧薙〒縺?k縺溘a縲
51+縺薙?繝ゥ繧、繧サ繝ウ繧ケ縺ョ蟇セ雎。螟悶→縺ェ繧翫∪縺吶?
--- a/get.sh
+++ b/get.sh
@@ -5,6 +5,8 @@ go get -u github.com/go-gl/glfw/v3.2/glfw
55 go get -u github.com/go-gl/gl/v2.1/gl
66 go get -u github.com/jfreymuth/go-vorbis/ogg/vorbis
77 go get -u github.com/timshannon/go-openal/openal
8+go get -u github.com/K4thos/glfont
9+go get -u github.com/flopp/go-findfont
810 go get -u github.com/faiface/beep
911 go get -u github.com/hajimehoshi/oto
1012 go get -u github.com/hajimehoshi/go-mp3
--- a/src/char.go
+++ b/src/char.go
@@ -2354,7 +2354,11 @@ func (c *Char) leftEdge() float32 {
23542354 return sys.cam.ScreenPos[0] / c.localscl
23552355 }
23562356 func (c *Char) lose() bool {
2357- return sys.winTeam == 1^c.teamside
2357+ if c.roundState() > 2 {
2358+ return sys.winTeam != c.teamside
2359+ } else {
2360+ return false
2361+ }
23582362 }
23592363 func (c *Char) loseKO() bool {
23602364 return c.lose() && sys.finish == FT_KO
@@ -2564,7 +2568,11 @@ func (c *Char) win() bool {
25642568 if c.teamside >= 2 {
25652569 return false
25662570 }
2567- return sys.winTeam == c.playerNo&1
2571+ if c.roundState() > 2 {
2572+ return sys.winTeam == c.playerNo&1
2573+ } else {
2574+ return false
2575+ }
25682576 }
25692577 func (c *Char) winKO() bool {
25702578 return c.win() && sys.finish == FT_KO
@@ -2644,6 +2652,8 @@ func (c *Char) playSound(f, lowpriority, loop bool, g, n, chNo, vol int32,
26442652 }
26452653 }
26462654 }
2655+
2656+// Furimuki = Turn around
26472657 func (c *Char) furimuki() {
26482658 if c.scf(SCF_ctrl) && c.helperIndex == 0 {
26492659 if c.rdDistX(sys.charList.enemyNear(c, 0, true), c).ToF() < 0 {
@@ -2702,7 +2712,7 @@ func (c *Char) stateChange2() bool {
27022712 return false
27032713 }
27042714 func (c *Char) changeStateEx(no int32, pn int, anim, ctrl int32) {
2705- if c.minus <= 0 && (c.ss.stateType == ST_S || c.ss.stateType == ST_C) {
2715+ if c.minus <= 0 && (c.ss.stateType == ST_S || c.ss.stateType == ST_C) && !c.sf(CSF_noautoturn) {
27062716 c.furimuki()
27072717 }
27082718 if anim >= 0 {
--- a/src/common.go
+++ b/src/common.go
@@ -241,21 +241,24 @@ func FileExist(filename string) string {
241241 }
242242 return ""
243243 }
244-func LoadFile(file *string, deffile string, load func(string) error) error {
244+
245+//SearchFile returns the directory that file is located
246+//This search on deffile directory, then it keep looking on other dirs
247+func SearchFile(file string, deffile string) string {
245248 var fp string
246- *file = strings.Replace(*file, "\\", "/", -1)
249+ file = strings.Replace(file, "\\", "/", -1)
247250 defdir := filepath.Dir(strings.Replace(deffile, "\\", "/", -1))
248- if defdir == "." || strings.Contains(*file, ":/") {
249- fp = *file
251+ if defdir == "." || strings.Contains(file, ":/") {
252+ fp = file
250253 } else if defdir == "/" {
251- fp = "/" + *file
254+ fp = "/" + file
252255 } else {
253- fp = defdir + "/" + *file
256+ fp = defdir + "/" + file
254257 }
255258 if fp = FileExist(fp); len(fp) == 0 {
256259 _else := false
257260 if defdir != "data" {
258- fp = "data/" + *file
261+ fp = "data/" + file
259262 if fp = FileExist(fp); len(fp) == 0 {
260263 _else = true
261264 }
@@ -263,18 +266,25 @@ func LoadFile(file *string, deffile string, load func(string) error) error {
263266 _else = true
264267 }
265268 if _else {
266- fp = *file
269+ fp = file
267270 if fp = FileExist(fp); len(fp) == 0 {
268- fp = *file
271+ fp = file
269272 }
270273 }
271274 }
275+
276+ return fp
277+}
278+
279+func LoadFile(file *string, deffile string, load func(string) error) error {
280+ fp := SearchFile(*file, deffile)
272281 if err := load(fp); err != nil {
273282 return Error(deffile + ":\n" + fp + "\n" + err.Error())
274283 }
275284 *file = fp
276285 return nil
277286 }
287+
278288 func SplitAndTrim(str, sep string) (ss []string) {
279289 ss = strings.Split(str, sep)
280290 for i, s := range ss {
--- a/src/font.go
+++ b/src/font.go
@@ -7,78 +7,128 @@ import (
77 "strings"
88 "unsafe"
99
10+ "github.com/K4thos/glfont"
11+ findfont "github.com/flopp/go-findfont"
1012 "github.com/go-gl/gl/v2.1/gl"
1113 )
1214
15+// FntCharImage stores sprite and position
1316 type FntCharImage struct {
1417 ofs, w uint16
1518 img []Sprite
1619 }
20+
21+// Fnt is a interface for basic font information
1722 type Fnt struct {
1823 images map[rune]*FntCharImage
1924 palettes [][256]uint32
2025 ver, ver2 uint16
26+ Type string
2127 Size [2]uint16
2228 Spacing [2]int32
2329 colors int32
2430 offset [2]int32
31+ ttf *glfont.Font
32+ palfx *PalFX
33+ alphaSrc int32
34+ alphaDst int32
35+}
36+
37+func newFnt() *Fnt {
38+ return &Fnt{
39+ images: make(map[rune]*FntCharImage),
40+ palfx: newPalFX(),
41+ }
2542 }
2643
27-func newFnt() *Fnt { return &Fnt{images: make(map[rune]*FntCharImage)} }
2844 func loadFnt(filename string) (*Fnt, error) {
45+
46+ if strings.HasSuffix(filename, ".fnt") {
47+ return loadFntV1(filename)
48+ }
49+
50+ return loadFntV2(filename)
51+}
52+
53+func loadFntV1(filename string) (*Fnt, error) {
2954 f := newFnt()
3055 fp, err := os.Open(filename)
56+
57+ //Check file in "font/"" directory
58+ if err != nil {
59+ fp, err = os.Open("font/" + filename)
60+ }
61+
62+ //Error opening file
3163 if err != nil {
3264 return nil, err
3365 }
66+
3467 defer func() { chk(fp.Close()) }()
68+
69+ //Read header
3570 buf := make([]byte, 12)
36- var n int
37- if n, err = fp.Read(buf); err != nil {
71+ n, err := fp.Read(buf)
72+
73+ //Error reading file
74+ if err != nil {
3875 return nil, err
3976 }
77+
78+ //Error is not a valid fnt file
4079 if string(buf[:n]) != "ElecbyteFnt\x00" {
4180 return nil, Error("ElecbyteFntではありません")
4281 }
82+
4383 read := func(x interface{}) error {
4484 return binary.Read(fp, binary.LittleEndian, x)
4585 }
86+
4687 if err := read(&f.ver); err != nil {
4788 return nil, err
4889 }
90+
4991 if err := read(&f.ver2); err != nil {
5092 return nil, err
5193 }
94+
5295 var pcxDataOffset, pcxDataLenght, txtDataOffset, txtDataLenght uint32
5396 if err := read(&pcxDataOffset); err != nil {
5497 return nil, err
5598 }
99+
56100 if err := read(&pcxDataLenght); err != nil {
57101 return nil, err
58102 }
103+
59104 if err := read(&txtDataOffset); err != nil {
60105 return nil, err
61106 }
107+
62108 if err := read(&txtDataLenght); err != nil {
63109 return nil, err
64110 }
111+
65112 spr := newSprite()
66113 if err := spr.readPcxHeader(fp, int64(pcxDataOffset)); err != nil {
67114 return nil, err
68115 }
116+
69117 fp.Seek(int64(pcxDataOffset)+128, 0)
70118 px := make([]byte, pcxDataLenght-128-768)
71119 if err := read(px); err != nil {
72120 return nil, err
73121 }
122+
74123 spr.Pal = make([]uint32, 256)
75124 var rgb [3]byte
76125 for i := range spr.Pal {
77126 if err := read(rgb[:]); err != nil {
78127 return nil, err
79128 }
80- spr.Pal[i] = uint32(255)<<24 | uint32(rgb[2])<<16 | uint32(rgb[1])<<8 | uint32(rgb[0])
129+ spr.Pal[i] = uint32(rgb[2])<<16 | uint32(rgb[1])<<8 | uint32(rgb[0])
81130 }
131+
82132 px = spr.RlePcxDecode(px)
83133 fp.Seek(int64(txtDataOffset), 0)
84134 buf = make([]byte, txtDataLenght)
@@ -106,6 +156,7 @@ func loadFnt(filename string) (*Fnt, error) {
106156 mapflg = false
107157 re := regexp.MustCompile("(\\S+)(?:\\s+(\\S+)(?:\\s+(\\S+))?)?")
108158 ofs := uint16(0)
159+ w := int32(0)
109160 for ; i < len(lines); i++ {
110161 if len(lines[i]) > 0 && lines[i][0] == '[' {
111162 break
@@ -134,10 +185,10 @@ func loadFnt(filename string) (*Fnt, error) {
134185 fci := &FntCharImage{ofs: ofs}
135186 f.images[c] = fci
136187 if len(cap[3]) > 0 {
137- w := Atoi(cap[3])
188+ w = Atoi(cap[3])
138189 if w < 0 {
139- ofs = I32ToU16(int32(ofs) - w)
140- w = -w
190+ ofs += I32ToU16(int32(ofs) - w)
191+ w = 0 - w
141192 }
142193 fci.w = I32ToU16(w)
143194 ofs += fci.w - f.Size[0]
@@ -153,33 +204,7 @@ func loadFnt(filename string) (*Fnt, error) {
153204 defflg = false
154205 is := NewIniSection()
155206 is.Parse(lines, &i)
156- ary := SplitAndTrim(is["size"], ",")
157- if len(ary[0]) > 0 {
158- f.Size[0] = I32ToU16(Atoi(ary[0]))
159- }
160- if len(ary) > 1 && len(ary[1]) > 0 {
161- f.Size[1] = I32ToU16(Atoi(ary[1]))
162- }
163- ary = SplitAndTrim(is["spacing"], ",")
164- if len(ary[0]) > 0 {
165- f.Spacing[0] = Atoi(ary[0])
166- }
167- if len(ary) > 1 && len(ary[1]) > 0 {
168- f.Spacing[1] = Atoi(ary[1])
169- }
170- f.colors = Atoi(is["colors"])
171- if f.colors > 255 {
172- f.colors = 255
173- } else if f.colors < 1 {
174- f.colors = 1
175- }
176- ary = SplitAndTrim(is["offset"], ",")
177- if len(ary[0]) > 0 {
178- f.offset[0] = Atoi(ary[0])
179- }
180- if len(ary) > 1 && len(ary[1]) > 0 {
181- f.offset[1] = Atoi(ary[1])
182- }
207+ loadDefInfo(f, filename, is)
183208 }
184209 }
185210 }
@@ -220,8 +245,142 @@ func loadFnt(filename string) (*Fnt, error) {
220245 fci.img[i].Offset[0], fci.img[i].Offset[1], fci.img[i].Pal = 0, 0, p[:]
221246 }
222247 }
248+
249+ f.SetColor(255, 255, 255, 255, 0)
250+
251+ return f, nil
252+}
253+
254+func loadFntV2(filename string) (*Fnt, error) {
255+ f := newFnt()
256+
257+ content, err := LoadText(filename)
258+
259+ //Check file in "font/"" directory
260+ if err != nil {
261+ content, err = LoadText(filename)
262+ }
263+
264+ if err != nil {
265+ return nil, err
266+ }
267+
268+ lines := SplitAndTrim(string(content), "\n")
269+ i := 0
270+ var name string
271+
272+ for ; i < len(lines); i++ {
273+ name, _ = SectionName(lines[i])
274+ if len(name) > 0 {
275+ is := NewIniSection()
276+ i++
277+ is.Parse(lines, &i)
278+ i--
279+ switch name {
280+ case "def":
281+ loadDefInfo(f, filename, is)
282+ }
283+ }
284+ }
285+
286+ f.SetColor(255, 255, 255, 255, 0)
287+
223288 return f, nil
224289 }
290+
291+func loadDefInfo(f *Fnt, filename string, is IniSection) {
292+ f.Type = strings.ToLower(is["type"])
293+ ary := SplitAndTrim(is["size"], ",")
294+ if len(ary[0]) > 0 {
295+ f.Size[0] = I32ToU16(Atoi(ary[0]))
296+ }
297+ if len(ary) > 1 && len(ary[1]) > 0 {
298+ f.Size[1] = I32ToU16(Atoi(ary[1]))
299+ }
300+ ary = SplitAndTrim(is["spacing"], ",")
301+ if len(ary[0]) > 0 {
302+ f.Spacing[0] = Atoi(ary[0])
303+ }
304+ if len(ary) > 1 && len(ary[1]) > 0 {
305+ f.Spacing[1] = Atoi(ary[1])
306+ }
307+ f.colors = Atoi(is["colors"])
308+ if f.colors > 255 {
309+ f.colors = 255
310+ } else if f.colors < 1 {
311+ f.colors = 1
312+ }
313+ ary = SplitAndTrim(is["offset"], ",")
314+ if len(ary[0]) > 0 {
315+ f.offset[0] = Atoi(ary[0])
316+ }
317+ if len(ary) > 1 && len(ary[1]) > 0 {
318+ f.offset[1] = Atoi(ary[1])
319+ }
320+
321+ if len(is["file"]) > 0 {
322+ if f.Type == "truetype" {
323+ loadFntTtf(f, filename, is["file"])
324+ } else {
325+ loadFntSff(f, filename, is["file"])
326+ }
327+ }
328+}
329+
330+func loadFntTtf(f *Fnt, fontfile string, filename string) {
331+ //Search in local directory
332+ fileDir := SearchFile(filename, fontfile)
333+ //Search in system directory
334+ fp := fileDir
335+ if fp = FileExist(fp); len(fp) == 0 {
336+ var err error
337+ fileDir, err = findfont.Find(fileDir)
338+ if err != nil {
339+ panic(err)
340+ }
341+ //fmt.Printf("Found font in '%s'\n", fileDir)
342+ }
343+ //Load ttf
344+ ttf, err := glfont.LoadFont(fileDir, int32(f.Size[1]), int(sys.gameWidth), int(sys.gameHeight))
345+ if err != nil {
346+ panic(err)
347+ }
348+ f.ttf = ttf
349+}
350+
351+func loadFntSff(f *Fnt, fontfile string, filename string) {
352+ fileDir := SearchFile(filename, fontfile)
353+ sff, err := loadSff(fileDir, false)
354+
355+ if err != nil {
356+ panic(err)
357+ }
358+
359+ //Load sprites
360+ for k, sprite := range sff.sprites {
361+ s := sff.getOwnPalSprite(sprite.Group, sprite.Number)
362+ offsetX := uint16(s.Offset[0])
363+ sizeX := uint16(s.Size[0])
364+
365+ fci := &FntCharImage{
366+ ofs: offsetX,
367+ w: sizeX,
368+ }
369+ fci.img = make([]Sprite, 1)
370+ fci.img[0] = *s
371+ f.images[rune(k[1])] = fci
372+ }
373+
374+ //Load palettes
375+ f.palettes = make([][256]uint32, sff.header.NumberOfPalettes)
376+ for i := 0; i < int(sff.header.NumberOfPalettes); i++ {
377+ pal := sff.palList.Get(i)
378+ copy(f.palettes[i][:], pal)
379+ }
380+
381+}
382+
383+//CharWidth returns the width that has a specified character
225384 func (f *Fnt) CharWidth(c rune) int32 {
226385 if c == ' ' {
227386 return int32(f.Size[0])
@@ -232,63 +391,135 @@ func (f *Fnt) CharWidth(c rune) int32 {
232391 }
233392 return int32(fci.w)
234393 }
394+
395+//TextWidth returns the width that has a specified text.
396+//This depends on each char's width and font spacing
235397 func (f *Fnt) TextWidth(txt string) (w int32) {
236398 for _, c := range txt {
237399 w += f.CharWidth(c) + f.Spacing[0]
238400 }
239401 return
240402 }
403+
404+func (f *Fnt) SetColor(r, g, b, alphaSrc, alphaDst float32) {
405+
406+ rNormalized := Max(0, Min(255, int32(r)))
407+ gNormalized := Max(0, Min(255, int32(g)))
408+ bNormalized := Max(0, Min(255, int32(b)))
409+
410+ f.palfx.enable = true
411+ f.palfx.eColor = 1
412+ f.palfx.eMul = [...]int32{
413+ 256 * rNormalized >> 8,
414+ 256 * gNormalized >> 8,
415+ 256 * bNormalized >> 8,
416+ }
417+
418+ f.alphaSrc = Max(0, Min(255, int32(alphaSrc)))
419+ f.alphaDst = Max(0, Min(255, int32(alphaDst)))
420+}
421+
241422 func (f *Fnt) getCharSpr(c rune, bank int32) *Sprite {
242423 fci := f.images[c]
243424 if fci == nil {
244425 return nil
245426 }
246- return &fci.img[bank]
427+
428+ if bank < int32(len(fci.img)) {
429+ return &fci.img[bank]
430+ }
431+
432+ return &fci.img[0]
433+}
434+
435+func (f *Fnt) calculateTrans() int32 {
436+ alphaSrc := int32(sys.brightness * f.alphaSrc >> 8)
437+ separator := int32(1 << 9)
438+ alphaDst := int32(f.alphaDst << 10)
439+
440+ return alphaSrc | separator | alphaDst
247441 }
248-func (f *Fnt) drawChar(x, y, xscl, yscl float32, bank int32, c rune) float32 {
442+
443+func (f *Fnt) drawChar(
444+ x, y, xscl, yscl float32,
445+ bank int32,
446+ c rune,
447+ paltex uint32,
448+) float32 {
449+
249450 if c == ' ' {
250451 return float32(f.Size[0]) * xscl
251452 }
453+
252454 spr := f.getCharSpr(c, bank)
253455 if spr == nil || spr.Tex == nil {
254456 return 0
255457 }
458+
459+ //trans := f.calculateTrans()
460+
256461 RenderMugenPal(*spr.Tex, 0, spr.Size, -x*sys.widthScale,
257462 -y*sys.heightScale, &notiling, xscl*sys.widthScale, xscl*sys.widthScale,
258463 yscl*sys.heightScale, 1, 0, 0, 0, 0, sys.brightness*255>>8|1<<9, &sys.scrrect,
259464 0, 0, false, 1, &[3]float32{0, 0, 0}, &[3]float32{1, 1, 1})
465+
260466 return float32(spr.Size[0]) * xscl
261467 }
262-func (f *Fnt) DrawText(txt string, x, y, xscl, yscl float32,
263- bank, align int32) {
468+
469+//DrawText prints on screen a specified text with the current font sprites
470+func (f *Fnt) DrawText(
471+ txt string,
472+ x, y, xscl, yscl float32,
473+ bank, align int32,
474+) {
475+
264476 if len(txt) == 0 {
265477 return
266478 }
479+
267480 x += float32(f.offset[0])*xscl + float32(sys.gameWidth-320)/2
268- y += float32(f.offset[1]-int32(f.Size[1])+1)*yscl +
269- float32(sys.gameHeight-240)
481+ y += float32(f.offset[1]-int32(f.Size[1])+1)*yscl + float32(sys.gameHeight-240)
482+
270483 if align == 0 {
271484 x -= float32(f.TextWidth(txt)) * xscl * 0.5
272485 } else if align < 0 {
273486 x -= float32(f.TextWidth(txt)) * xscl
274487 }
488+
275489 if bank < 0 || len(f.palettes) <= int(bank) {
276490 bank = 0
277491 }
278- // nil から呼ぶと allPalFX が適用される
279- pal := (*PalFX)(nil).getFxPal(f.palettes[bank][:], false)
492+
493+ pal := f.palfx.getFxPal(f.palettes[bank][:], false)
280494 gl.Enable(gl.TEXTURE_1D)
281495 gl.ActiveTexture(gl.TEXTURE1)
282496 var paltex uint32
283497 gl.GenTextures(1, &paltex)
284498 gl.BindTexture(gl.TEXTURE_1D, paltex)
285499 gl.PixelStorei(gl.UNPACK_ALIGNMENT, 1)
286- gl.TexImage1D(gl.TEXTURE_1D, 0, gl.RGBA, 256, 0, gl.RGBA, gl.UNSIGNED_BYTE,
287- unsafe.Pointer(&pal[0]))
500+ gl.TexImage1D(
501+ gl.TEXTURE_1D,
502+ 0,
503+ gl.RGBA,
504+ 256,
505+ 0,
506+ gl.RGBA,
507+ gl.UNSIGNED_BYTE,
508+ unsafe.Pointer(&pal[0]),
509+ )
288510 gl.TexParameteri(gl.TEXTURE_1D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
289511 gl.TexParameteri(gl.TEXTURE_1D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
512+
290513 for _, c := range txt {
291- x += f.drawChar(x, y, xscl, yscl, bank, c) + xscl*float32(f.Spacing[0])
514+ x += f.drawChar(
515+ x,
516+ y,
517+ xscl,
518+ yscl,
519+ bank,
520+ c,
521+ paltex,
522+ ) + xscl*float32(f.Spacing[0])
292523 }
293524 gl.DeleteTextures(1, &paltex)
294525 gl.Disable(gl.TEXTURE_1D)
@@ -304,8 +535,21 @@ type TextSprite struct {
304535 func NewTextSprite() *TextSprite {
305536 return &TextSprite{align: 1, xscl: 1, yscl: 1}
306537 }
538+
539+func (ts *TextSprite) SetColor(r, g, b, alphaSrc, alphaDst float32) {
540+ if ts.fnt.Type == "truetype" {
541+ //ts.fnt.ttf.SetColor(r, g, b, a)
542+ } else {
543+ ts.fnt.SetColor(r, g, b, alphaSrc, alphaDst)
544+ }
545+}
546+
307547 func (ts *TextSprite) Draw() {
308548 if !sys.frameSkip && ts.fnt != nil {
309- ts.fnt.DrawText(ts.text, ts.x, ts.y, ts.xscl, ts.yscl, ts.bank, ts.align)
549+ if ts.fnt.Type == "truetype" {
550+ //ts.fnt.ttf.Printf(ts.x, ts.y, ts.yscl, ts.align, ts.text) //x, y, scale, align, string, printf args
551+ } else {
552+ ts.fnt.DrawText(ts.text, ts.x, ts.y, ts.xscl, ts.yscl, ts.bank, ts.align)
553+ }
310554 }
311555 }
--- a/src/script.go
+++ b/src/script.go
@@ -8,7 +8,7 @@ import (
88 "strings"
99
1010 "github.com/go-gl/glfw/v3.2/glfw"
11- "github.com/yuin/gopher-lua"
11+ lua "github.com/yuin/gopher-lua"
1212 )
1313
1414 func luaRegister(l *lua.LState, name string, f func(*lua.LState) int) {
@@ -245,6 +245,29 @@ func scriptCommonInit(l *lua.LState) {
245245 sys.teamLifeShare = boolArg(l, 1)
246246 return 0
247247 })
248+
249+ // All the lua sprites will be caled by this value
250+ luaRegister(l, "setLuaSpriteScale", func(l *lua.LState) int {
251+ sys.luaSpriteScale = float64(numArg(l, 1))
252+ return 0
253+ })
254+
255+ // All the lua sprites will be caled by this value
256+ luaRegister(l, "setLuaSpriteOffsetX", func(l *lua.LState) int {
257+ sys.luaSpriteOffsetX = float64(numArg(l, 1))
258+ return 0
259+ })
260+
261+ // All the lua sprites will add this value to his position Y
262+ luaRegister(l, "setLuaSmallPortraitScale", func(l *lua.LState) int {
263+ sys.luaSmallPortraitScale = float32(numArg(l, 1))
264+ return 0
265+ })
266+ // All the lua sprites will add this value to his position Y
267+ luaRegister(l, "setLuaBigPortraitScale", func(l *lua.LState) int {
268+ sys.luaBigPortraitScale = float32(numArg(l, 1))
269+ return 0
270+ })
248271 }
249272
250273 // System Script
@@ -296,7 +319,7 @@ func systemScriptInit(l *lua.LState) {
296319 if !ok {
297320 userDataError(l, 1, ts)
298321 }
299- ts.x, ts.y = float32(numArg(l, 2)), float32(numArg(l, 3))
322+ ts.x, ts.y = float32((numArg(l, 2)/sys.luaSpriteScale)+sys.luaSpriteOffsetX), float32(numArg(l, 3)/sys.luaSpriteScale)
300323 return 0
301324 })
302325 luaRegister(l, "textImgSetScale", func(*lua.LState) int {
@@ -304,7 +327,7 @@ func systemScriptInit(l *lua.LState) {
304327 if !ok {
305328 userDataError(l, 1, ts)
306329 }
307- ts.xscl, ts.yscl = float32(numArg(l, 2)), float32(numArg(l, 3))
330+ ts.xscl, ts.yscl = float32(numArg(l, 2)/sys.luaSpriteScale), float32(numArg(l, 3)/sys.luaSpriteScale)
308331 return 0
309332 })
310333 luaRegister(l, "textImgDraw", func(*lua.LState) int {
@@ -333,7 +356,7 @@ func systemScriptInit(l *lua.LState) {
333356 if !ok {
334357 userDataError(l, 1, a)
335358 }
336- a.SetPos(float32(numArg(l, 2)), float32(numArg(l, 3)))
359+ a.SetPos(float32((numArg(l, 2)/sys.luaSpriteScale)+sys.luaSpriteOffsetX), float32(numArg(l, 3)/sys.luaSpriteScale))
337360 return 0
338361 })
339362 luaRegister(l, "animAddPos", func(*lua.LState) int {
@@ -341,7 +364,7 @@ func systemScriptInit(l *lua.LState) {
341364 if !ok {
342365 userDataError(l, 1, a)
343366 }
344- a.AddPos(float32(numArg(l, 2)), float32(numArg(l, 3)))
367+ a.AddPos(float32(numArg(l, 2)/sys.luaSpriteScale), float32(numArg(l, 3)/sys.luaSpriteScale))
345368 return 0
346369 })
347370 luaRegister(l, "animSetTile", func(*lua.LState) int {
@@ -382,7 +405,7 @@ func systemScriptInit(l *lua.LState) {
382405 if !ok {
383406 userDataError(l, 1, a)
384407 }
385- a.SetScale(float32(numArg(l, 2)), float32(numArg(l, 3)))
408+ a.SetScale(float32(numArg(l, 2)/sys.luaSpriteScale), float32(numArg(l, 3)/sys.luaSpriteScale))
386409 return 0
387410 })
388411 luaRegister(l, "animSetWindow", func(*lua.LState) int {
@@ -390,8 +413,8 @@ func systemScriptInit(l *lua.LState) {
390413 if !ok {
391414 userDataError(l, 1, a)
392415 }
393- a.SetWindow(float32(numArg(l, 2)), float32(numArg(l, 3)),
394- float32(numArg(l, 4)), float32(numArg(l, 5)))
416+ a.SetWindow(float32((numArg(l, 2)/sys.luaSpriteScale)+sys.luaSpriteOffsetX), float32(numArg(l, 3)/sys.luaSpriteScale),
417+ float32(numArg(l, 4)/sys.luaSpriteScale), float32(numArg(l, 5)/sys.luaSpriteScale))
395418 return 0
396419 })
397420 luaRegister(l, "animUpdate", func(*lua.LState) int {
@@ -621,7 +644,7 @@ func systemScriptInit(l *lua.LState) {
621644 xscl *= c.portrait_scale
622645 yscl *= c.portrait_scale
623646 }
624- c.lportrait.Draw(x, y, xscl, yscl, c.lportrait.Pal, nil)
647+ c.lportrait.Draw(x/float32(sys.luaSpriteScale)+float32(sys.luaSpriteOffsetX), y/float32(sys.luaSpriteScale), xscl/sys.luaBigPortraitScale, yscl/sys.luaBigPortraitScale, c.lportrait.Pal, nil)
625648 }
626649 }
627650 return 0
@@ -639,13 +662,17 @@ func systemScriptInit(l *lua.LState) {
639662 offset++
640663 if c != nil {
641664 if c.sportrait != nil {
642- c.sportrait.Draw(x+float32(i)*sys.sel.cellsize[0],
643- y+float32(j)*sys.sel.cellsize[1], sys.sel.cellscale[0]*c.portrait_scale,
644- sys.sel.cellscale[1]*c.portrait_scale, c.sportrait.Pal, nil)
665+ c.sportrait.Draw((x + float32(i)*sys.sel.cellsize[0]),
666+ (y+float32(j)*sys.sel.cellsize[1])/float32(sys.luaSpriteScale),
667+ (sys.sel.cellscale[0]*c.portrait_scale)/float32(sys.luaSpriteScale),
668+ (sys.sel.cellscale[1]*c.portrait_scale)/float32(sys.luaSpriteScale),
669+ c.sportrait.Pal, nil)
645670 } else if c.def == "randomselect" && sys.sel.randomspr != nil {
646671 sys.sel.randomspr.Draw(x+float32(i)*sys.sel.cellsize[0],
647- y+float32(j)*sys.sel.cellsize[1], sys.sel.randomscl[0],
648- sys.sel.randomscl[1], sys.sel.randomspr.Pal, nil)
672+ y+float32(j)*sys.sel.cellsize[1]/float32(sys.luaSpriteScale),
673+ sys.sel.randomscl[0]/float32(sys.luaSpriteScale),
674+ sys.sel.randomscl[1]/float32(sys.luaSpriteScale),
675+ sys.sel.randomspr.Pal, nil)
649676 }
650677 }
651678 }
@@ -986,7 +1013,7 @@ func systemScriptInit(l *lua.LState) {
9861013 xscl *= c.portrait_scale
9871014 yscl *= c.portrait_scale
9881015 }
989- c.sportrait.Draw(x, y, xscl, yscl, c.sportrait.Pal, nil)
1016+ c.sportrait.Draw(x/float32(sys.luaSpriteScale)+float32(sys.luaSpriteOffsetX), y/float32(sys.luaSpriteScale), xscl/sys.luaSmallPortraitScale, yscl/sys.luaSmallPortraitScale, c.sportrait.Pal, nil)
9901017 }
9911018 }
9921019 return 0
@@ -1007,7 +1034,7 @@ func systemScriptInit(l *lua.LState) {
10071034 xscl *= c.portrait_scale
10081035 yscl *= c.portrait_scale
10091036 }
1010- c.vsportrait.Draw(x, y, xscl, yscl, c.vsportrait.Pal, nil)
1037+ c.vsportrait.Draw(x/float32(sys.luaSpriteScale)+float32(sys.luaSpriteOffsetX), y/float32(sys.luaSpriteScale), xscl/sys.luaBigPortraitScale, yscl/sys.luaBigPortraitScale, c.vsportrait.Pal, nil)
10111038 }
10121039 }
10131040 return 0
@@ -1028,7 +1055,7 @@ func systemScriptInit(l *lua.LState) {
10281055 xscl *= c.portrait_scale
10291056 yscl *= c.portrait_scale
10301057 }
1031- c.vportrait.Draw(x, y, xscl, yscl, c.vportrait.Pal, nil)
1058+ c.vportrait.Draw(x/float32(sys.luaSpriteScale)+float32(sys.luaSpriteOffsetX), y/float32(sys.luaSpriteScale), xscl/float32(sys.luaSpriteScale), yscl/float32(sys.luaSpriteScale), c.vportrait.Pal, nil)
10321059 }
10331060 }
10341061 return 0
--- a/src/system.go
+++ b/src/system.go
@@ -15,11 +15,11 @@ import (
1515 "github.com/go-gl/gl/v2.1/gl"
1616 "github.com/go-gl/glfw/v3.2/glfw"
1717 "github.com/timshannon/go-openal/openal"
18- "github.com/yuin/gopher-lua"
18+ lua "github.com/yuin/gopher-lua"
1919 )
2020
2121 const (
22- MaxSimul = 4
22+ MaxSimul = 8
2323 MaxAttachedChar = 2
2424 FPS = 60
2525 P1P3Dist = 25
@@ -59,6 +59,11 @@ var sys = System{
5959 audioClose: make(chan bool, 1),
6060 keyInput: glfw.KeyUnknown,
6161 keyString: "",
62+ // Localcoord sceenpack
63+ luaSpriteScale: 1,
64+ luaSmallPortraitScale: 1,
65+ luaBigPortraitScale: 1,
66+ luaSpriteOffsetX: 0,
6267 }
6368
6469 type TeamMode int32
@@ -221,6 +226,11 @@ type System struct {
221226 timerCount []int32
222227 cmdFlags map[string]string
223228 quickLaunch bool
229+ // Localcoord sceenpack
230+ luaSpriteScale float64
231+ luaSmallPortraitScale float32
232+ luaBigPortraitScale float32
233+ luaSpriteOffsetX float64
224234 }
225235
226236 func (s *System) init(w, h int32) *lua.LState {