-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpiece.go
64 lines (55 loc) · 1.63 KB
/
piece.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import rl "github.com/gen2brain/raylib-go/raylib"
const (
NamePawn = "Pawn"
NameKnight = "Knight"
NameBishop = "Bishop"
NameRook = "Rook"
NameQueen = "Queen"
NameKing = "King"
NameBomber = "Suicide Bomber"
NameLeopard = "Leopard"
NameChecker = "Checker"
NameMountedArcher = "Mounted Archer"
NameWizard = "Wizard"
NameArchbishop = "Archbishop"
NameFortress = "Fortress"
NameScout = "Scout"
NameWarlock = "Warlock"
NameCelestial = "Celestial"
)
type PieceColor uint32
const (
WHITE PieceColor = iota
BLACK
)
type PieceType struct {
Id uint32
Name string
TexWhite rl.Texture2D
TexBlack rl.Texture2D
}
type Piece struct {
Id uint32 `json:"id"`
Typ uint32 `json:"type"`
Color PieceColor `json:"color"`
Board uint32 `json:"board"`
Coord Vec2 `json:"coord"`
Scale uint32 `json:"scale"`
}
func (p *Piece) Render() {
var typ = sandbox.GetPieceType(p.Typ)
var tex = typ.TexWhite
if p.Color == BLACK {
tex = typ.TexBlack
}
var pos = GetBoardOrigo().Add(p.Coord.Scale(TileSize))
var texScale = float32(TileSize) / float32(max(tex.Width, tex.Height))
var pieceCorner = pos.Add(ONEONE.Scale(TileSize / 2)).Sub(Vec2{int(texScale * float32(tex.Width) / 2), int(texScale * float32(tex.Height) / 2)})
rl.DrawTextureEx(tex, pieceCorner.ToRlVec(), 0, float32(p.Scale)*texScale, rl.White)
}
func (p *Piece) RenderCrossPlaneIndicator() {
var pos = GetBoardOrigo().Add(p.Coord.Scale(TileSize))
var offset = TileSize / 2
rl.DrawCircle(int32(pos.X+offset), int32(pos.Y+offset), 12, rl.Blue)
}