Skip to content

Commit

Permalink
scale max tower level past 5
Browse files Browse the repository at this point in the history
  • Loading branch information
Warsinger committed Aug 10, 2024
1 parent e135b0e commit c445d88
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Graphics and sounds by Matt. Nathan created the Lego builds that were used for t
* ~~Fix positioning of creeps when they run into something to make sure they're right up against it~~
* ~~Fix creeps on edge of base not attacking~~
* ~~Don't let creeps overlap each other, stack on top~~
* Creep bouncing when on top of 2 creeps
* ~~Creep bouncing when on top of 2 creeps~~
* Game screen options
* ~~Press some key to start~~
* Choose options for game difficulty
Expand Down
7 changes: 5 additions & 2 deletions components/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,17 @@ func (pr *PlayerRenderData) Draw(screen *ebiten.Image, entry *donburi.Entry, deb
str := fmt.Sprintf("$ %d", player.GetMoney())
nextY := DrawTextLines(screen, assets.ScoreFace, str, float64(board.Width), TextBorder, text.AlignStart, text.AlignStart)

str = fmt.Sprintf("Max Tower Level %d", GetMaxTowerLevel(entry.World))
_ = DrawTextLines(screen, assets.InfoFace, str, float64(board.Width), nextY, text.AlignStart, text.AlignStart)

str = fmt.Sprintf("SCORE %05d", player.Score)
_ = DrawTextLines(screen, assets.ScoreFace, str, float64(board.Width), nextY, text.AlignCenter, text.AlignStart)
_ = DrawTextLines(screen, assets.ScoreFace, str, float64(board.Width), TextBorder, text.AlignCenter, text.AlignStart)

str = fmt.Sprintf("Creep Level %d", player.GetCreepLevel())
if debug {
str = fmt.Sprintf("%s (%d)", str, player.TowerLevels)
}
_ = DrawTextLines(screen, assets.ScoreFace, str, float64(board.Width), TextBorder, text.AlignCenter, text.AlignStart)
_ = DrawTextLines(screen, assets.InfoFace, str, float64(board.Width), nextY, text.AlignCenter, text.AlignStart)
}

func (p *PlayerData) GetScore() int {
Expand Down
20 changes: 18 additions & 2 deletions components/renders.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"image"
"image/color"
"math"
"strings"
"tower-defense/assets"
"tower-defense/config"
Expand Down Expand Up @@ -57,8 +58,23 @@ func (t *InfoRenderData) Draw(screen *ebiten.Image, entry *donburi.Entry) {
// draw blue dots along the side of the entity for each level
level := Level.Get(entry)
const size = 3
for i := 1; i <= level.Level; i++ {
vector.DrawFilledCircle(screen, float32(rect.Min.X)+1, float32(rect.Min.Y)+float32(i)*(size*2), size, color.RGBA{0, 0, 255, 255}, true)
const perColumn = 8
const maxColumns = 4
for i := 0; i < GetMaxTowerLevel(entry.World); i++ {
column := float32(math.Trunc(float64(i) / perColumn))
row := float32(i % perColumn)
var x float32
if column < maxColumns/2 {
x = float32(rect.Min.X) + column*size*2
} else {
x = float32(rect.Max.X) - (maxColumns-column-1)*size*2
}
y := float32(rect.Min.Y) + row*size*2
if i < level.Level {
vector.DrawFilledCircle(screen, x, y, size, color.RGBA{0, 0, 255, 255}, true)
} else {
vector.StrokeCircle(screen, x, y, size, 1, color.RGBA{0, 255, 0, 255}, true)
}
}
}

Expand Down
11 changes: 9 additions & 2 deletions components/towers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package components
import (
"fmt"
"image"
"math"

"github.com/leap-fish/necs/esync/srvsync"
"github.com/yohamta/donburi"
Expand Down Expand Up @@ -72,11 +73,17 @@ func (t *TowerData) Heal(entry *donburi.Entry) bool {
return false
}

const maxLevel = 5
const initMaxTowerLevel = 5

func GetMaxTowerLevel(world donburi.World) int {
pe := Player.MustFirst(world)
player := Player.Get(pe)
return initMaxTowerLevel + int(math.Trunc(float64(player.TowerLevels)/20))
}

func (t *TowerData) Upgrade(entry *donburi.Entry) bool {
level := Level.Get(entry)
if level.Level >= maxLevel {
if level.Level >= GetMaxTowerLevel(entry.World) {
fmt.Printf("Tower is max level %v\n", level.Level)
return false
}
Expand Down
2 changes: 1 addition & 1 deletion scenes/title.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (t *TitleScene) Draw(screen *ebiten.Image) {
str = "Click to place towers Cost: $50"
nextY := comp.DrawTextLines(screen, assets.ScoreFace, str, width, 250, text.AlignCenter, text.AlignStart)

str = "Mouse over a tower\nPress H to heal to full Cost: $25\nPress U to upgrade and heal to full Cost: $50\nMax upgrade level is 5"
str = "Mouse over a tower\nPress H to heal to full Cost: $25\nPress U to upgrade and heal to full Cost: $50\nMax upgrade level is 5 (+1 for every 20 upgrades)"
nextY = comp.DrawTextLines(screen, assets.InfoFace, str, width, nextY, text.AlignCenter, text.AlignStart)

towerImage := assets.GetImage("tower")
Expand Down

0 comments on commit c445d88

Please sign in to comment.