I've cleaned the remaining commits and packed them into the 0.2.1 release. Now the idea is to work a little more cleanly by pushing PRs, not individual commits on main. This will prove somewhat painful for this diary, but better for long term code quality.
The first big functionnality I want to add now is the ability to move from maps to maps. Castle of the winds had a few pregenerated maps (first levels and towns) and all the rest of the maps were generated for each new game. I've drawn those pregenerated maps (inspired from castle of the winds, though I changed some things) so the main issue is now to actually work on the logic.
Here's how the Map struct is looking right now
type Map struct {
Name string
PlayerStart Coord
spawnNPC SpawnNPC
NPCList []*model.NPCStats
ObjectList []*model.Object
MapMatrix [][]int
}
My idea is to create a new struct to handle special tiles. This will become handy for transition tiles (map edges, stairs) but also for traps and maybe other things in the future. Then I have to add it in the Map struct and add the logic to handle this when player walks on one
type SpecialTile struct {
Type string
Pos Coord
Destination Coord
}
I also created a slice containing all the maps
// Slice containing all the maps of the game
AllTheMaps = []Map{Village, ToTheOldMine}
And I have to add the map index in every Coord struct.
type Coord struct {
X, Y int
Map int
}
I'll have to be careful though, this could create bugs if I'm not careful. In most cases, I don't want to use the Map because the map is the current map. But I haven't found how to default this. I'll probably need a constructor but this is tedious...
Then, I have to create a function called CheckTileIsSpecial() which is similar to CheckTileIsWalkable and return the special tile if one is found on the coordinates
And finally I have to handle the code to move from maps to maps in the actOnDirectionKey() function.
// this tile could be special, check if it is
tile := currentMap.CheckTileIsSpecial(newX, newY)
if tile != maps.NotSpecialTile {
if tile.Type == "MapTransition" {
currentMap = maps.AllTheMaps[tile.Destination.Map]
player.Avatar.PosX = tile.Destination.X
player.Avatar.PosY = tile.Destination.Y
ShowGameScreen(currentWindow)
}
// TODO handle error
}
Surprisingly, it worked on first try. The only thing that has been overlooked is that calling ShowGameScreen() clears the objects and NPCs on the map we are transitionning to. That's not what we want.