Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

miscs #44

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions barricade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package main

import (
"bytes"
"fmt"
"image"
"log"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"

_ "embed"
_ "image/png"
Expand Down Expand Up @@ -149,6 +151,12 @@ func (b *barricade) OnClick(x, y int) bool {
icon := newBarricadeIcon(80, eScreenHeight+70)
b.game.infoPanel.setIcon(icon)
b.game.infoPanel.setUnit(b)
b.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
ebitenutil.DebugPrintAt(screen, "I am Barricade!", x, y)
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20)
// 敵の進行を邪魔するという説明を記載する
ebitenutil.DebugPrintAt(screen, "Blocks enemy's advance!", x, y+40)
}

return false
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func (g *Game) initialize() {
g.drawHandler.Add(bg)

// クレジットを初期化
g.credit = 100
g.credit = 1000

// 敵が全滅したらウェーブを終了して建築フェーズに戻る
// 敵が全滅したことをコールバックする
Expand Down
16 changes: 15 additions & 1 deletion panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type infoPanel struct {
icon *icon
unit infoer
buttons []*Button

drawDescriptionFn func(screen *ebiten.Image, x, y int)
}

func newInfoPanel(g *Game, w, h int) *infoPanel {
Expand All @@ -30,7 +32,7 @@ func newInfoPanel(g *Game, w, h int) *infoPanel {
y: screenHeight - h - bottomMargin,
width: w,
height: h,
zindex: 10,
zindex: 60,
}
}

Expand Down Expand Up @@ -78,6 +80,7 @@ func (p *infoPanel) ClearButtons() {
p.game.clickHandler.Remove(button)
}
p.buttons = nil
p.drawDescriptionFn = nil
}

func (p *infoPanel) Draw(screen *ebiten.Image) {
Expand All @@ -102,10 +105,21 @@ func (p *infoPanel) Draw(screen *ebiten.Image) {
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("%s", name), p.x+100+40, p.y+30)
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("HP: %d", health), p.x+100+40, p.y+50)

// 家だったら現在のクレジットも表示する
if name == "House" {
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("$: %d", p.game.credit), p.x+100+40, p.y+70)
}

// ボタンを描画
for _, button := range p.buttons {
button.Draw(screen)
}

// description を描画
// ボタンの右側に表示するので、ボタンの数だけ右にずらす
if p.drawDescriptionFn != nil {
p.drawDescriptionFn(screen, 255+infoPanelHeight*len(p.buttons), p.y+30)
}
}

func (p *infoPanel) ZIndex() int {
Expand Down
9 changes: 8 additions & 1 deletion radiotower.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package main

import (
"bytes"
"fmt"
"image"
"log"
"math"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/vector"

_ "embed"
Expand Down Expand Up @@ -264,7 +266,12 @@ func (b *radioTower) OnClick(x, y int) bool {
icon := newRadioTowerIcon(80, eScreenHeight+70)
b.game.infoPanel.setIcon(icon)
b.game.infoPanel.setUnit(b)

b.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
ebitenutil.DebugPrintAt(screen, "I am Radio Tower!", x, y)
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20)
// 範囲攻撃するしレンジも広いが、近くは攻撃できない
ebitenutil.DebugPrintAt(screen, "Attacks in an area, effective at range, but cannot hit nearby enemies.", x, y+40)
}
return false
}

Expand Down
8 changes: 8 additions & 0 deletions tower.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package main

import (
"bytes"
"fmt"
"image"
"log"
"math"

"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"github.com/hajimehoshi/ebiten/v2/vector"

_ "embed"
Expand Down Expand Up @@ -246,6 +248,12 @@ func (b *tower) OnClick(x, y int) bool {
icon := newTowerIcon(80, eScreenHeight+70)
b.game.infoPanel.setIcon(icon)
b.game.infoPanel.setUnit(b)
b.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
ebitenutil.DebugPrintAt(screen, "I am Beam Tower!", x, y)
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", b.Cost()), x, y+20)
// 敵を一匹ずつ攻撃するという説明を記載する
ebitenutil.DebugPrintAt(screen, "Attack single bug by laser beam!", x, y+40)
}

return false
}
Expand Down