Skip to content

Commit

Permalink
More achievements: bridges and mills (#260)
Browse files Browse the repository at this point in the history
* achievements can use multitile index
* add achievements for bridges and mills
* use bridge achievements for maps with rivers
* show number of achivements in main menu
  • Loading branch information
mlange-42 authored Mar 18, 2024
1 parent 481891e commit d422668
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 15 deletions.
41 changes: 41 additions & 0 deletions data/json/achievements.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,34 @@
}
]
},
{
"id": "poineer",
"name": "Pioneer",
"icon": "bridge",
"icon_index": 5,
"description": "Own 5 bridges.",
"conditions": [
{
"type": "terrain",
"ids": ["bridge"],
"number": 5
}
]
},
{
"id": "civil-engineer",
"name": "Civil Engineer",
"icon": "bridge",
"icon_index": 5,
"description": "Own 10 bridges.",
"conditions": [
{
"type": "terrain",
"ids": ["bridge"],
"number": 10
}
]
},
{
"id": "granary",
"name": "Granary",
Expand Down Expand Up @@ -168,6 +196,19 @@
}
]
},
{
"id": "miller-guild",
"name": "Miller Guild",
"icon": "watermill",
"description": "Own 10 mills.",
"conditions": [
{
"type": "terrain",
"ids": ["watermill", "windmill"],
"number": 10
}
]
},
{
"id": "knight",
"name": "Knight",
Expand Down
3 changes: 2 additions & 1 deletion data/maps/Coastline.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
],
"achievements": [
"landscape-architect",
"fisherman-guild"
"fisherman-guild",
"pioneer"
],
"description": [
"A medium-sized (40x40) map with a coastline and a river. Plenty of all resources.",
Expand Down
2 changes: 1 addition & 1 deletion data/maps/River Delta.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"landscape-architect",
"wood-gnome",
"fisherman-guild",
"farmer-guild"
"civil-engineer"
],
"description": [
"A larger (53x46) map of a river delta. Plenty of resources, but a lot of waterways to bridge.",
Expand Down
25 changes: 13 additions & 12 deletions game/menu/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,14 +722,8 @@ func (ui *UI) createScenariosPanel(games []save.SaveGame, achievements *achievem

func (ui *UI) createAchievementsPanel(achieves *achievements.Achievements, fonts *res.Fonts) *widget.Container {
menuContainer := ui.createTabPanel()

img := ui.emptyImage()

label := ui.createMainMenuLabel("Achievements", fonts)
menuContainer.AddChild(label)

scroll, content := ui.createScrollPanel(panelHeight - 76)

achUnlocked := []*achievements.Achievement{}
achLocked := []*achievements.Achievement{}
for i := range achieves.Achievements {
Expand All @@ -742,6 +736,11 @@ func (ui *UI) createAchievementsPanel(achieves *achievements.Achievements, fonts
}
achUnlocked = append(achUnlocked, achLocked...)

label := ui.createMainMenuLabel(fmt.Sprintf("Achievements (%d/%d)", len(achUnlocked)-len(achLocked), len(achUnlocked)), fonts)
menuContainer.AddChild(label)

scroll, content := ui.createScrollPanel(panelHeight - 76)

for _, ach := range achUnlocked {
name := util.Capitalize(ach.Name)

Expand All @@ -763,9 +762,10 @@ func (ui *UI) createAchievementsPanel(achieves *achievements.Achievements, fonts
var icon *ebiten.Image
if terr.IsTerrainName(ach.Icon) {
t := terr.ToTerrain(ach.Icon)
icon = ui.createTerrainImage(t, 1)
icon = ui.createTerrainImage(t, ach.IconIndex, 1)
} else {
icon = ui.sprites.Get(ui.sprites.GetIndex(ach.Icon))
idx := ui.sprites.GetIndex(ach.Icon)
icon = ui.sprites.GetSprite(ui.sprites.GetMultiTileIndex(idx, terr.Directions(ach.IconIndex), 0, 0))
}

graphic := widget.NewGraphic(
Expand Down Expand Up @@ -849,7 +849,7 @@ func (ui *UI) emptyImage() *widget.ButtonImage {
}

func (ui *UI) createTerrainGraphic(terrain terr.Terrain) *widget.Graphic {
img := ui.createTerrainImage(terrain, 3)
img := ui.createTerrainImage(terrain, 0, 3)

graphic := widget.NewGraphic(
widget.GraphicOpts.WidgetOpts(
Expand All @@ -865,14 +865,13 @@ func (ui *UI) createTerrainGraphic(terrain terr.Terrain) *widget.Graphic {
return graphic
}

func (ui *UI) createTerrainImage(t terr.Terrain, scale int) *ebiten.Image {
func (ui *UI) createTerrainImage(t terr.Terrain, tileIdx int, scale int) *ebiten.Image {
props := &terr.Properties[t]

bx, by := ui.sprites.TileWidth, ui.sprites.TileWidth

img := ebiten.NewImage(bx*scale, by*scale)

idx := ui.sprites.GetTerrainIndex(t)
height := 0

for _, tr := range props.TerrainBelow {
Expand All @@ -888,7 +887,9 @@ func (ui *UI) createTerrainImage(t terr.Terrain, scale int) *ebiten.Image {
height = info2.Height
}

sp1 := ui.sprites.GetRand(idx, 0, 0)
idx := ui.sprites.GetTerrainIndex(t)
subIdx := ui.sprites.GetMultiTileIndex(idx, terr.Directions(tileIdx), 0, 0)
sp1 := ui.sprites.GetSprite(subIdx)
op := ebiten.DrawImageOptions{}
op.GeoM.Translate(0, float64(ui.sprites.TileWidth-sp1.Bounds().Dy()-height))
op.GeoM.Scale(float64(scale), float64(scale))
Expand Down
3 changes: 3 additions & 0 deletions game/res/achievements/achievements.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Achievement struct {
Name string
Description string
Icon string
IconIndex int
Conditions []Condition
Completed bool
}
Expand Down Expand Up @@ -113,6 +114,7 @@ func New(world *ecs.World, f fs.FS, file string, playerFile string) *Achievement
ID: achieve.ID,
Name: achieve.Name,
Icon: achieve.Icon,
IconIndex: achieve.IconIndex,
Description: achieve.Description,
Conditions: conditions,
},
Expand Down Expand Up @@ -255,6 +257,7 @@ type achievementJs struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
IconIndex int `json:"icon_index"`
Description string `json:"description"`
Conditions []conditionJs `json:"conditions"`
}
Expand Down
2 changes: 1 addition & 1 deletion game/res/sprites.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,5 @@ func (s *Sprites) GetMultiTileIndex(idx int, dirs terr.Directions, frame int, ra
sIdx := (rand%vars)*inf.AnimFrames + (frame/inf.AnimSpeed)%inf.AnimFrames
return inf.Index[sIdx]
}
return idx
return inf.Index[0]
}

0 comments on commit d422668

Please sign in to comment.