2019-10-31 21:17:13 -04:00
|
|
|
package Map
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image"
|
2019-11-01 14:12:23 -04:00
|
|
|
"math/rand"
|
2019-10-31 21:17:13 -04:00
|
|
|
|
|
|
|
"github.com/essial/OpenDiablo2/Common"
|
|
|
|
"github.com/essial/OpenDiablo2/Sound"
|
|
|
|
"github.com/hajimehoshi/ebiten"
|
|
|
|
)
|
|
|
|
|
|
|
|
type EngineRegion struct {
|
|
|
|
Rect image.Rectangle
|
2019-11-01 14:12:23 -04:00
|
|
|
Region *Region
|
2019-10-31 21:17:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type Engine struct {
|
|
|
|
soundManager *Sound.Manager
|
|
|
|
gameState *Common.GameState
|
|
|
|
fileProvider Common.FileProvider
|
2019-11-01 14:12:23 -04:00
|
|
|
regions []EngineRegion
|
|
|
|
OffsetX float64
|
|
|
|
OffsetY float64
|
2019-10-31 21:17:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateMapEngine(gameState *Common.GameState, soundManager *Sound.Manager, fileProvider Common.FileProvider) *Engine {
|
|
|
|
result := &Engine{
|
|
|
|
gameState: gameState,
|
|
|
|
soundManager: soundManager,
|
|
|
|
fileProvider: fileProvider,
|
2019-11-01 14:12:23 -04:00
|
|
|
regions: make([]EngineRegion, 0),
|
2019-10-31 21:17:13 -04:00
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Engine) GenerateMap(regionType RegionIdType, levelPreset int) {
|
2019-11-01 14:12:23 -04:00
|
|
|
randomSource := rand.NewSource(v.gameState.Seed)
|
|
|
|
region := LoadRegion(randomSource, regionType, levelPreset, v.fileProvider)
|
|
|
|
v.regions = append(v.regions, EngineRegion{
|
|
|
|
Rect: image.Rectangle{image.Point{0, 0}, image.Point{int(region.TileWidth), int(region.TileHeight)}},
|
|
|
|
Region: region,
|
|
|
|
})
|
|
|
|
v.soundManager.PlayBGM("/data/global/music/Act1/tristram.wav") // TODO: Temp stuff here
|
2019-10-31 21:17:13 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Engine) Render(target *ebiten.Image) {
|
2019-11-01 14:12:23 -04:00
|
|
|
// TODO: Temporary hack for testing
|
|
|
|
for y := 0; y < int(v.regions[0].Region.TileHeight); y++ {
|
|
|
|
offX := -(y * 80)
|
|
|
|
offY := y * 40
|
|
|
|
for x := 0; x < int(v.regions[0].Region.TileWidth); x++ {
|
2019-11-01 16:51:50 -04:00
|
|
|
tile := v.regions[0].Region.DS1.Tiles[y][x]
|
|
|
|
for i := range tile.Floors {
|
|
|
|
v.regions[0].Region.RenderTile(400+offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeFloors, i, target)
|
|
|
|
}
|
|
|
|
offX += 80
|
|
|
|
offY += 40
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for y := 0; y < int(v.regions[0].Region.TileHeight); y++ {
|
|
|
|
offX := -(y * 80)
|
|
|
|
offY := y * 40
|
|
|
|
for x := 0; x < int(v.regions[0].Region.TileWidth); x++ {
|
|
|
|
tile := v.regions[0].Region.DS1.Tiles[y][x]
|
|
|
|
for i := range tile.Walls {
|
|
|
|
// TODO: render back walls, then character, then fore walls
|
|
|
|
v.regions[0].Region.RenderTile(400+offX+int(v.OffsetX), offY+int(v.OffsetY), x, y, RegionLayerTypeWalls, i, target)
|
|
|
|
}
|
2019-11-01 14:12:23 -04:00
|
|
|
offX += 80
|
|
|
|
offY += 40
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-31 21:17:13 -04:00
|
|
|
}
|