Skip to content

Commit bd95598

Browse files
authored
Merge pull request #47 from pankona/show-monery-earned
show money earned
2 parents 4a26f45 + 5b63ed6 commit bd95598

10 files changed

+164
-99
lines changed

barricade.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ import (
77
"log"
88

99
"github.com/hajimehoshi/ebiten/v2"
10-
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
1110

1211
_ "embed"
12+
"image/color"
1313
_ "image/png"
1414
)
1515

@@ -157,10 +157,11 @@ func (b *barricade) OnClick(x, y int) bool {
157157
b.game.infoPanel.setIcon(icon)
158158
b.game.infoPanel.setUnit(b)
159159
b.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
160-
ebitenutil.DebugPrintAt(screen, "I am Barricade!", x, y)
161-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20)
160+
var scale float64 = 2
161+
drawText(screen, "I am Barricade!", x, y-10, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
162+
drawText(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
162163
// 敵の進行を邪魔するという説明を記載する
163-
ebitenutil.DebugPrintAt(screen, "Blocks enemy's advance!", x, y+40)
164+
drawText(screen, "Blocks enemy's advance!", x, y+50, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
164165
}
165166

166167
return false

gameclear.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"image/color"
55

66
"github.com/hajimehoshi/ebiten/v2"
7-
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
87
"github.com/hajimehoshi/ebiten/v2/vector"
98
)
109

@@ -57,8 +56,8 @@ func (g *gameclear) Draw(screen *ebiten.Image) {
5756
// 画面全体を半透明の黒で覆う
5857
vector.DrawFilledRect(screen, 0, 0, screenWidth, screenHeight, color.RGBA{0, 0, 0, 0x90}, true)
5958

60-
// とりあえず画面中央に Game Clear って出す
61-
ebitenutil.DebugPrintAt(screen, "Congratulation! Game Clear!", screenWidth/2-80, eScreenHeight/2-20)
59+
// 画面中央に勝った感のあるメッセージを出す
60+
drawText(screen, "Congratulations! All waves over!", screenWidth/2-490, eScreenHeight/2-100, 5, 5, color.RGBA{0xff, 0xff, 0xff, 0xff})
6261
// Click to Restart って出す
63-
ebitenutil.DebugPrintAt(screen, "Click to Restart", screenWidth/2-50, eScreenHeight/2+10)
62+
drawText(screen, "Click to Restart", screenWidth/2-230, eScreenHeight/2+100, 5, 5, color.RGBA{0xff, 0xff, 0xff, 0xff})
6463
}

gameover.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"image/color"
55

66
"github.com/hajimehoshi/ebiten/v2"
7-
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
87
"github.com/hajimehoshi/ebiten/v2/vector"
98
)
109

@@ -58,8 +57,8 @@ func (g *gameover) Draw(screen *ebiten.Image) {
5857
// 画面全体を半透明の黒で覆う
5958
vector.DrawFilledRect(screen, 0, 0, screenWidth, screenHeight, color.RGBA{0, 0, 0, 0x90}, true)
6059

61-
// とりあえず画面中央に GameOver って出す
62-
ebitenutil.DebugPrintAt(screen, "Game Over!", screenWidth/2-30, eScreenHeight/2-20)
60+
// 画面中央に負けた感のあるメッセージを出す
61+
drawText(screen, "You lose! House destroyed...", screenWidth/2-400, eScreenHeight/2-100, 5, 5, color.RGBA{0xff, 0xff, 0xff, 0xff})
6362
// Click to Restart って出す
64-
ebitenutil.DebugPrintAt(screen, "Click to Restart", screenWidth/2-50, eScreenHeight/2+10)
63+
drawText(screen, "Click to Restart", screenWidth/2-230, eScreenHeight/2+100, 5, 5, color.RGBA{0xff, 0xff, 0xff, 0xff})
6564
}

house.go

+16-13
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func newHouse(game *Game) *house {
5252
height: img.Bounds().Dy(),
5353
scale: 0.5,
5454

55-
health: 100,
55+
health: 1,
5656

5757
image: ebiten.NewImageFromImage(img),
5858

@@ -193,10 +193,11 @@ func (h *house) OnClick(x, y int) bool {
193193
h.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
194194
x = x - 150
195195
y = y + 10
196-
ebitenutil.DebugPrintAt(screen, "I am Barricade!", x, y)
197-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20)
196+
var scale float64 = 2
197+
drawText(screen, "I am Barricade!", x, y-15, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
198+
drawText(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+15, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
198199
// 敵の進行を邪魔するという説明を記載する
199-
ebitenutil.DebugPrintAt(screen, "Blocks enemy's advance!", x, y+40)
200+
drawText(screen, "Blocks enemy's advance!", x, y+45, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
200201
}
201202
return false
202203
},
@@ -253,10 +254,11 @@ func (h *house) OnClick(x, y int) bool {
253254
t.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
254255
x = x - 150
255256
y = y + 10
256-
ebitenutil.DebugPrintAt(screen, "I am Beam Tower!", x, y)
257-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", t.Cost()), x, y+20)
257+
var scale float64 = 2
258258
// 敵を一匹ずつ攻撃するという説明を記載する
259-
ebitenutil.DebugPrintAt(screen, "Attack single bug by laser beam!", x, y+40)
259+
drawText(screen, "I am Beam Tower!", x, y-15, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
260+
drawText(screen, fmt.Sprintf("Cost: $%d", t.Cost()), x, y+15, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
261+
drawText(screen, "Attack single bug by laser beam!", x, y+45, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
260262
}
261263
return false
262264
},
@@ -312,10 +314,11 @@ func (h *house) OnClick(x, y int) bool {
312314
h.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
313315
x = x - 150
314316
y = y + 10
315-
ebitenutil.DebugPrintAt(screen, "I am Radio Tower!", x, y)
316-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", rt.Cost()), x, y+20)
317+
var scale float64 = 2
317318
// 範囲攻撃するしレンジも広いが、近くは攻撃できない
318-
ebitenutil.DebugPrintAt(screen, "Attacks in an area, effective at range, but cannot hit nearby enemies.", x, y+40)
319+
drawText(screen, "I am Radio Tower!", x, y-15, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
320+
drawText(screen, fmt.Sprintf("Cost: $%d", rt.Cost()), x, y+15, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
321+
drawText(screen, "Attacks in area, cannot hit near bugs!", x, y+45, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
319322
}
320323
return false
321324
},
@@ -366,10 +369,10 @@ func (h *house) OnClick(x, y int) bool {
366369
},
367370
func(screen *ebiten.Image, x, y, width, height int) {
368371
drawRect(screen, x, y, width, height)
369-
ebitenutil.DebugPrintAt(screen, "FINISH BUILDING!", x+width/2-45, y+height/2-40)
370-
ebitenutil.DebugPrintAt(screen, "START NEXT WAVE!", x+width/2-45, y+height/2-8)
372+
drawText(screen, "FINISH BUILDING!", x+width/2-45, y+height/2-40, 1, 1, color.RGBA{0xff, 0xff, 0xff, 0xff})
373+
drawText(screen, "START NEXT WAVE!", x+width/2-45, y+height/2-8, 1, 1, color.RGBA{0xff, 0xff, 0xff, 0xff})
371374
// 現在のウェーブとトータルウェーブ数を表示する
372-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("CURRENT WAVE: %d/%d", h.game.waveCtrl.currentBigWave, len(waveList)), x+width/2-52, y+height/2+32)
375+
drawText(screen, fmt.Sprintf("CURRENT WAVE: %d/%d", h.game.waveCtrl.currentBigWave+1, len(waveList)), x+width/2-52, y+height/2+32, 1, 1, color.RGBA{0xff, 0xff, 0xff, 0xff})
373376
},
374377
)
375378
h.game.infoPanel.AddButton(nextWaveStartButton)

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ func (g *Game) initialize() {
218218
g.drawHandler.Add(bg)
219219

220220
// クレジットを初期化
221-
g.credit = 100
221+
g.credit = 1000
222222

223223
// 敵が全滅したらウェーブを終了して建築フェーズに戻る
224224
// 敵が全滅したことをコールバックする

radiotower.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"math"
99

1010
"github.com/hajimehoshi/ebiten/v2"
11-
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
1211
"github.com/hajimehoshi/ebiten/v2/vector"
1312

1413
_ "embed"
@@ -272,10 +271,11 @@ func (b *radioTower) OnClick(x, y int) bool {
272271
b.game.infoPanel.setIcon(icon)
273272
b.game.infoPanel.setUnit(b)
274273
b.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
275-
ebitenutil.DebugPrintAt(screen, "I am Radio Tower!", x, y)
276-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20)
274+
var scale float64 = 2
277275
// 範囲攻撃するしレンジも広いが、近くは攻撃できない
278-
ebitenutil.DebugPrintAt(screen, "Attacks in an area, effective at range, but cannot hit nearby enemies.", x, y+40)
276+
drawText(screen, "I am Radio Tower!", x, y-10, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
277+
drawText(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
278+
drawText(screen, "Attacks in area, cannot hit near bugs!", x, y+50, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
279279
}
280280
return false
281281
}

text.go

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"image/color"
5+
6+
"github.com/hajimehoshi/bitmapfont/v3"
7+
"github.com/hajimehoshi/ebiten/v2"
8+
"github.com/hajimehoshi/ebiten/v2/text/v2"
9+
)
10+
11+
/*
12+
こんなふうに使う
13+
14+
clr := color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
15+
scaleX, scaleY = float64(5), float64(5)
16+
drawText(screen, "HOUSE DEFENSE OPERATION!", screenWidth-750, 100, scaleX, scaleY, clr)
17+
*/
18+
func drawText(screen *ebiten.Image, t string, x, y int, scaleX, scaleY float64, clr color.RGBA) {
19+
textOp := &text.DrawOptions{}
20+
textOp.ColorScale.ScaleWithColor(clr)
21+
textOp.GeoM.Scale(scaleX, scaleY)
22+
textOp.GeoM.Translate(float64(x), float64(y))
23+
text.Draw(screen, t, text.NewGoXFace(bitmapfont.Face), textOp)
24+
}

title.go

+2-15
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import (
66
"image/color"
77
"log"
88

9-
"github.com/hajimehoshi/bitmapfont/v3"
109
"github.com/hajimehoshi/ebiten/v2"
11-
"github.com/hajimehoshi/ebiten/v2/text/v2"
1210
)
1311

1412
type title struct {
@@ -136,19 +134,8 @@ func (t *title) Draw(screen *ebiten.Image) {
136134
// 文字を描く
137135
clr := color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
138136
scaleX, scaleY = float64(5), float64(5)
139-
140-
textOp := &text.DrawOptions{}
141-
textOp.ColorScale.ScaleWithColor(clr)
142-
textOp.GeoM.Scale(scaleX, scaleY)
143-
textOp.GeoM.Translate(float64(screenWidth-750), 100)
144-
text.Draw(screen, "HOUSE DEFENSE OPERATION!", text.NewGoXFace(bitmapfont.Face), textOp)
145-
146-
textOp = &text.DrawOptions{}
147-
textOp.ColorScale.ScaleWithColor(clr)
148-
textOp.GeoM.Scale(scaleX, scaleY)
149-
textOp.GeoM.Translate(float64(screenWidth-750), 170)
150-
text.Draw(screen, "CLICK TO START!", text.NewGoXFace(bitmapfont.Face), textOp)
151-
137+
drawText(screen, "HOUSE DEFENSE OPERATION!", screenWidth-750, 100, scaleX, scaleY, clr)
138+
drawText(screen, "CLICK TO START!", screenWidth-750, 170, scaleX, scaleY, clr)
152139
}
153140

154141
func (t *title) ZIndex() int {

tower.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"math"
99

1010
"github.com/hajimehoshi/ebiten/v2"
11-
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
1211
"github.com/hajimehoshi/ebiten/v2/vector"
1312

1413
_ "embed"
@@ -254,10 +253,11 @@ func (b *tower) OnClick(x, y int) bool {
254253
b.game.infoPanel.setIcon(icon)
255254
b.game.infoPanel.setUnit(b)
256255
b.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
257-
ebitenutil.DebugPrintAt(screen, "I am Beam Tower!", x, y)
258-
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20)
256+
var scale float64 = 2
259257
// 敵を一匹ずつ攻撃するという説明を記載する
260-
ebitenutil.DebugPrintAt(screen, "Attack single bug by laser beam!", x, y+40)
258+
drawText(screen, "I am Beam Tower!", x, y-10, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
259+
drawText(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
260+
drawText(screen, "Attack single bug by laser beam!", x, y+50, scale, scale, color.RGBA{0xff, 0xff, 0xff, 0xff})
261261
}
262262

263263
return false

0 commit comments

Comments
 (0)