Skip to content

Commit

Permalink
Merge pull request #46 from pankona/show-description-on-select-in-inf…
Browse files Browse the repository at this point in the history
…o-panel

show description on select in info panel
  • Loading branch information
pankona authored Jun 29, 2024
2 parents 795039e + 0671e55 commit 4a26f45
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 4 deletions.
5 changes: 5 additions & 0 deletions barricade.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ func (b *barricade) Damage(d int) {

// barricade implements Clickable interface
func (b *barricade) OnClick(x, y int) bool {
if b.game.buildCandidate != nil {
// 建築予定のものを持っているときには何もしない
return false
}

b.game.clickedObject = "barricade"
getAudioPlayer().play(soundChoice)

Expand Down
2 changes: 2 additions & 0 deletions buildpane.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func newBuildPane(game *Game) *buildPane {

// buildCandidate は次の建築のために初期化する
game.buildCandidate = nil
game.infoPanel.drawDescriptionFn = nil

getAudioPlayer().play(soundDon)

Expand Down Expand Up @@ -88,6 +89,7 @@ func newBuildPane(game *Game) *buildPane {

game.drawHandler.Remove(game.buildCandidate)
game.buildCandidate = nil
game.infoPanel.drawDescriptionFn = nil

getAudioPlayer().play(soundChoice)

Expand Down
38 changes: 35 additions & 3 deletions house.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ func (h *house) OnClick(x, y int) bool {
h.game.buildInstruction = nil
}

if h.game.buildCandidate != nil {
// 建築予定のものを持っているときには何もしない
return false
}

getAudioPlayer().play(soundChoice)

h.game.clickedObject = "House"
Expand Down Expand Up @@ -183,7 +188,16 @@ func (h *house) OnClick(x, y int) bool {
b.game.infoPanel.Remove(b)
}

h.game.buildCandidate = newBarricade(h.game, 0, 0, barricadeOnDestroyFn)
b := newBarricade(h.game, 0, 0, barricadeOnDestroyFn)
h.game.buildCandidate = b
h.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
x = x - 150
y = y + 10
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
},
func(screen *ebiten.Image, x, y, width, height int) {
Expand Down Expand Up @@ -234,7 +248,16 @@ func (h *house) OnClick(x, y int) bool {
b.game.infoPanel.Remove(b)
}

h.game.buildCandidate = newTower(h.game, 0, 0, towerOnDestroyFn)
t := newTower(h.game, 0, 0, towerOnDestroyFn)
h.game.buildCandidate = t
t.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
x = x - 150
y = y + 10
ebitenutil.DebugPrintAt(screen, "I am Beam Tower!", x, y)
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", t.Cost()), x, y+20)
// 敵を一匹ずつ攻撃するという説明を記載する
ebitenutil.DebugPrintAt(screen, "Attack single bug by laser beam!", x, y+40)
}
return false
},
func(screen *ebiten.Image, x, y, width, height int) {
Expand Down Expand Up @@ -284,7 +307,16 @@ func (h *house) OnClick(x, y int) bool {
b.game.infoPanel.Remove(b)
}

h.game.buildCandidate = newRadioTower(h.game, 0, 0, radioTowerOnDestroyFn)
rt := newRadioTower(h.game, 0, 0, radioTowerOnDestroyFn)
h.game.buildCandidate = rt
h.game.infoPanel.drawDescriptionFn = func(screen *ebiten.Image, x, y int) {
x = x - 150
y = y + 10
ebitenutil.DebugPrintAt(screen, "I am Radio Tower!", x, y)
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("Cost: $%d", rt.Cost()), x, y+20)
// 範囲攻撃するしレンジも広いが、近くは攻撃できない
ebitenutil.DebugPrintAt(screen, "Attacks in an area, effective at range, but cannot hit nearby enemies.", x, y+40)
}
return false
},
func(screen *ebiten.Image, x, y, width, height int) {
Expand Down
5 changes: 5 additions & 0 deletions radiotower.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ func (b *radioTower) Damage(d int) {

// radioTower implements Clickable interface
func (b *radioTower) OnClick(x, y int) bool {
if b.game.buildCandidate != nil {
// 建築予定のものを持っているときには何もしない
return false
}

b.game.clickedObject = "radioTower"
getAudioPlayer().play(soundChoice)

Expand Down
2 changes: 1 addition & 1 deletion title.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (t *title) Draw(screen *ebiten.Image) {
}

// 文字を描く
clr := color.RGBA{R: 0x80, G: 0x80, B: 0x80, A: 0xff}
clr := color.RGBA{R: 0xff, G: 0xff, B: 0xff, A: 0xff}
scaleX, scaleY = float64(5), float64(5)

textOp := &text.DrawOptions{}
Expand Down
5 changes: 5 additions & 0 deletions tower.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ func (b *tower) Damage(d int) {

// tower implements Clickable interface
func (b *tower) OnClick(x, y int) bool {
if b.game.buildCandidate != nil {
// 建築予定のものを持っているときには何もしない
return false
}

b.game.clickedObject = "tower"
getAudioPlayer().play(soundChoice)

Expand Down

0 comments on commit 4a26f45

Please sign in to comment.