Today I started by doing to cleanup of the stats system. I moved the CharacterStats initialization in the model package instead of the newgame screen. I also switch all the stats from float64 (from the sliders) to int because all the characteristics will always be positive integers.
I thought using uints first but I'm unconformable with the fact that some computations could lead to negative values. In some case it's not possible (there are no negative stats or negative levels) but in other it could (negative current health point, yeah, you're dead). I'll leave an issue for the future me.
All this is preliminary work to display live counters in the stats box of the game screen.
I then reworked the code from the newgame screen + game screen to clean some ugly things, move code in functions to improve readability, set up constants.
No value is now set and then updated (like in newgame screen) and they are all dynamically displayed (specifically in updateStats() function but not only).
func updateStats() {
healthPointsValueLabel.Text = fmt.Sprintf("%d/%d", model.Player.CurrentHP, model.Player.MaxHP)
healthPointsValueLabel.Refresh()
manaPointsValueLabel.Text = fmt.Sprintf("%d/%d", model.Player.CurrentMP, model.Player.MaxMP)
manaPointsValueLabel.Refresh()
timeSpentValueLabel.Text = model.FormatDuration(model.TimeSinceBegin, "short")
timeSpentValueLabel.Refresh()
}
- pointsToSpendValue := widget.NewLabel("10")
+ pointsToSpendValue := widget.NewLabel(fmt.Sprintf("%d", model.Player.PointsToSpend))
Now, I can rework on NPCs a bit. I've added a new file called npc.go containing various structs that will be useful for next steps.
type Avatar struct {
AspectPath *canvas.Image
PosX int
PosY int
}
type NPCStats struct {
Name string
Pronoun string
Avatar Avatar
MaxHP int
CurrentHP int
MaxMP int
CurrentMP int
}
type NPCsOnCurrentMap struct {
List []NPCStats
}
var (
FarmerAvatar = Avatar{
CanvasImage: canvas.NewImageFromFile("./static/farmer.png"),
}
Farmer = NPCStats{
Name: "farmer",
Avatar: FarmerAvatar,
Pronoun: "him",
MaxHP: 10,
CurrentHP: 10,
}
)
On the map, I'll then remove the previous attempts to make NPCs and instantiate a list NPCsOnCurrentMap. The drawSubject() function is already nearly generic and so are movePlayer and moveNPC1 so only a little rework is required.
That's what I thought but it turned out it was a bit of a pain xD. I managed to get something to compile but NPC movement and collision is totally broken now .