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
|
package modernworld
import (
_ "embed"
"fmt"
tl "github.com/JoelOtter/termloop"
)
var (
//go:embed files/title.txt
titleScreenFile []byte
//go:embed files/game_over.txt
gameOverScreenFile []byte
)
func ShowTitleScreen(modernworld *modernworld) {
prepareScreen(modernworld)
showTitle(modernworld)
if checkArenaSizeNotOk(modernworld) {
modernworld.ScreenSizeNotOK = true
showMaximizeScreen(modernworld)
return
}
showPressToInit(modernworld, 0)
}
func checkArenaSizeNotOk(modernworld *modernworld) bool {
w, h := modernworld.Arena.Size()
if w < 100 || h < 37 {
return true
}
return false
}
func ShowGameOverScreen(modernworld *modernworld) {
prepareScreen(modernworld)
showGameOver(modernworld)
showScore(modernworld)
showPressToInit(modernworld, 2)
}
func prepareScreen(modernworld *modernworld) {
modernworld.Level = tl.NewBaseLevel(tl.Cell{Bg: tl.ColorBlack, Fg: tl.ColorWhite})
modernworld.Game.Screen().SetLevel(modernworld.Level)
modernworld.Level.AddEntity(modernworld)
modernworld.initArena()
modernworld.initHud()
}
func showTitle(modernworld *modernworld) {
showCanvas(modernworld, titleScreenFile)
}
func showGameOver(modernworld *modernworld) {
showCanvas(modernworld, gameOverScreenFile)
}
func showCanvas(modernworld *modernworld, file []byte) {
canvas := CreateCanvas(file)
arenaX, arenaY := modernworld.Arena.Position()
arenaW, arenaH := modernworld.Arena.Size()
x := arenaX + arenaW/2 - len(canvas)/2
y := arenaY + arenaH/2 + -len(canvas[0]) - 1
modernworld.Level.AddEntity(tl.NewEntityFromCanvas(x, y, canvas))
}
func showScore(modernworld *modernworld) {
score := fmt.Sprintf("SCORE: %4d ", modernworld.Score)
showCenterText(score, 0, modernworld)
}
func showPressToInit(modernworld *modernworld, topPadding int) {
showCenterText("Press ENTER to start", topPadding, modernworld)
}
func showMaximizeScreen(modernworld *modernworld) {
showCenterText("Maximize the console and run the game again", 0, modernworld)
}
func showCenterText(text string, topPadding int, modernworld *modernworld) {
arenaX, arenaY := modernworld.Arena.Position()
arenaW, arenaH := modernworld.Arena.Size()
x := arenaX + arenaW/2 - len(text)/2
y := arenaY + arenaH/2 + topPadding
modernworld.Level.AddEntity(tl.NewText(x, y, text, tl.ColorWhite, tl.ColorBlack))
}
|