-
Notifications
You must be signed in to change notification settings - Fork 0
/
gamedraw.go
164 lines (123 loc) · 3.56 KB
/
gamedraw.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package main
import (
"image/color"
"strconv"
"github.com/darellanodev/jetpack-game/lib"
"github.com/darellanodev/jetpack-game/objects"
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/text"
)
func (g * Game) getWidthText(textLine string) int {
width := 0
if len(textLine) < 10 {
width = appWidth / 2 - 100
}
if len(textLine) > 10 && len(textLine) < 17 {
width = appWidth / 3
}
if len(textLine) > 17 && len(textLine) < 30 {
width = appWidth / 4
}
if len(textLine) > 30 && len(textLine) < 40 {
width = appWidth / 8
}
return width
}
func (g *Game) drawVerticalTexts(screen *ebiten.Image, textLines []string) {
posY := 100
heigth := appHeight / 2 - 150
for _, textLine := range textLines {
text.Draw(screen, textLine, lib.MplusNormalFont, g.getWidthText(textLine), heigth + posY, color.White)
posY += 50
}
}
func (g *Game) Draw(screen *ebiten.Image) {
if g.status == GameStatusMainMenu {
g.mainmenu.Draw(screen)
} else if g.status == GameStatusTravelingToPlanet {
g.planets.Draw(screen)
} else {
backgroundSpriteName := "background" + strconv.Itoa(g.level.number)
lib.DrawNormalImage(screen, sprites[backgroundSpriteName], 0, 0)
for _, blinkingStar := range g.blinkingStars {
blinkingStar.Draw(screen, g.count)
}
if g.status == GameStatusPlaying || g.status == GameStatusPaused {
g.player.Draw(screen, g.count)
}
if g.status != GameStatusTravelingToLevel && g.status != GameStatusFinishingLevel {
g.enemy.Draw(screen)
g.fuel.Draw(screen)
}
if g.showSmokeTime < maxTimeToShowSmoke {
g.smoke.Draw(screen)
}
if g.explosion.Creating && g.showExplosionTime < 50 {
g.explosion.Draw(screen)
}
g.rocket.Draw(screen)
for _, platform := range g.platforms {
platform.Draw(screen)
}
//draw first lava floors (because then normal floors will be in front of lava floors and it will look better)
for _, floor := range g.floors {
if floor.IsLavaFloor() {
floor.Draw(screen, g.count)
}
}
//then draw normal floors
for _, floor := range g.floors {
if floor.FloorType == objects.FloorNormal {
floor.Draw(screen, g.count)
}
}
if g.status != GameStatusInit {
g.hud.Draw(screen)
}
if g.status == GameStatusGameComplete {
displayText := []string{
"Game Complete!",
"Thanks for playing, this game is",
"in an early stage of development",
"More stuff coming soon.",
"Press ENTER to play again.",
}
g.drawVerticalTexts(screen, displayText)
}
if g.status == GameStatusGameOver {
displayText := []string{
"Game Over",
"Press ENTER to play again.",
}
g.drawVerticalTexts(screen, displayText)
}
if g.status == GameStatusPaused {
displayText := []string{
"Paused",
"Press P to continue",
}
g.drawVerticalTexts(screen, displayText)
}
if g.soundTextTime > 0 && g.status == GameStatusPlaying {
soundSwichText := "SOUND OFF"
if soundEnabled {
soundSwichText = "SOUND ON"
}
displayText := []string{
soundSwichText,
"Press S to ON / OFF",
}
g.drawVerticalTexts(screen, displayText)
}
if g.status == GameStatusTravelingToLevel {
displayText := []string{
"Traveling to the",
"next level...",
}
g.drawVerticalTexts(screen, displayText)
}
}
// msg := fmt.Sprintf("posX:%d posY:%d, fuelX:%d fuelY:%d, enemyX:%d enemyY:%d", g.player.x, g.player.y, g.fuel.x, g.fuel.y, g.enemy.x, g.enemy.y)
// msg := fmt.Sprintf("debugMsg:%s soundEnabled: %v lives: %v",g.debugMsg, soundEnabled, g.player.lives)
// ebitenutil.DebugPrint(screen, msg)
}