-
Notifications
You must be signed in to change notification settings - Fork 0
/
roundresult.go
120 lines (94 loc) · 4.03 KB
/
roundresult.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
package homebrawlapp
import (
"bytes"
"fmt"
"image/color"
"github.com/brensch/smarthome"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/inpututil"
"github.com/hajimehoshi/ebiten/v2/text"
)
func (g *Game) DrawGameResult(screen *ebiten.Image) {
x, y := ebiten.CursorPosition()
// op.GeoM.Scale(.5, .5)
// offset := time.Now().UnixMilli() % int64(screen.Bounds().Dx())
// if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
// op.GeoM.Translate(float64(x), float64(y))
// }
// text.Draw(g.Image, "lumb", mplusNormalFont, imageWidth/2, imageHeight/2, color.Black)
// screen.DrawImage(g.Image, op)
var houses [2]smarthome.HouseState
for _, appliance := range g.states[g.turn].Appliances {
house, ok := appliance.(smarthome.HouseState)
if ok {
if house.Team == -1 {
houses[0] = house
} else {
houses[1] = house
}
continue
}
applianceSquare := ebiten.NewImage(g.ApplianceDimension, g.ApplianceDimension)
op := &ebiten.DrawImageOptions{}
// add 1 to y for house
imageX, imageY := float64(appliance.State().Location.X)*float64(g.ApplianceDimension), float64(appliance.State().Location.Y+1)*float64(g.ApplianceDimension)
// fmt.Println(appliance.Type(), imageX, imageY)
op.GeoM.Translate(imageX, imageY)
// op.ColorM.Apply(color.White)
if appliance.State().Team == -1 {
applianceSquare.Fill(downColour)
} else {
applianceSquare.Fill(upColour)
}
// op.C
label := fmt.Sprintf("(%d,%d) %s\nhealth: %d\nstrength: %d", appliance.State().Location.X, appliance.State().Location.Y, appliance.Type(), appliance.State().Health, appliance.State().Strength)
text.Draw(applianceSquare, label, mplusNormalFont, 0, mplusNormalFont.Metrics().Height.Ceil(), color.Black)
screen.DrawImage(applianceSquare, op)
}
// draw events sidepanel
eventsSquare := ebiten.NewImage(g.ApplianceDimension*2, g.ApplianceDimension*2)
eventsString := bytes.NewBuffer(nil)
for _, event := range g.states[g.turn].Events {
eventsString.WriteString(fmt.Sprintf("%s - %d,%d\n", event.Type(), event.Base().Target.X, event.Base().Target.Y))
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(3*g.ApplianceDimension), 0)
text.Draw(eventsSquare, eventsString.String(), mplusNormalFont, 0, mplusNormalFont.Metrics().Height.Ceil(), color.White)
screen.DrawImage(eventsSquare, op)
if int(g.turn) == len(g.states)-1 {
resultSquare := ebiten.NewImage(g.ApplianceDimension*2, g.ApplianceDimension*2)
op.GeoM.Translate(float64(3*g.ApplianceDimension), 0)
text.Draw(resultSquare, "lumb", mplusNormalFont, 0, mplusNormalFont.Metrics().Height.Ceil(), color.White)
screen.DrawImage(resultSquare, op)
}
// draw houses
upHouse := ebiten.NewImage(g.ApplianceDimension*3, g.ApplianceDimension)
upHouse.Fill(upColour)
upHouseOp := &ebiten.DrawImageOptions{}
upHouseState := fmt.Sprintf("Team UP\nhealth: %d", houses[1].Health)
text.Draw(upHouse, upHouseState, mplusNormalFont, 0, mplusNormalFont.Metrics().Height.Ceil(), color.Black)
screen.DrawImage(upHouse, upHouseOp)
downHouse := ebiten.NewImage(g.ApplianceDimension*3, g.ApplianceDimension)
downHouse.Fill(downColour)
downHouseOp := &ebiten.DrawImageOptions{}
downHouseOp.GeoM.Translate(0, float64(7*g.ApplianceDimension))
downHouseState := fmt.Sprintf("Team DOWN\nhealth: %d", houses[0].Health)
text.Draw(downHouse, downHouseState, mplusNormalFont, 0, mplusNormalFont.Metrics().Height.Ceil(), color.Black)
screen.DrawImage(downHouse, downHouseOp)
ebitenutil.DebugPrint(screen, fmt.Sprintf("%f, %d:%d %t\nturn:%d", ebiten.CurrentFPS(), x, y, ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft), g.turn))
}
func (g *Game) UpdateGameResult() {
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonLeft) {
if int(g.turn) == len(g.states)-1 {
return
}
g.turn++
}
if inpututil.IsMouseButtonJustPressed(ebiten.MouseButtonRight) {
if int(g.turn) == 0 {
return
}
g.turn--
}
}