1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-05 09:47:18 -05:00
OpenDiablo2/Map/Engine.go

76 lines
2.1 KiB
Go
Raw Normal View History

package Map
import (
"image"
"math/rand"
"github.com/essial/OpenDiablo2/Common"
"github.com/essial/OpenDiablo2/Sound"
"github.com/hajimehoshi/ebiten"
)
type EngineRegion struct {
Rect image.Rectangle
Region *Region
}
type Engine struct {
soundManager *Sound.Manager
gameState *Common.GameState
fileProvider Common.FileProvider
regions []EngineRegion
OffsetX float64
OffsetY float64
}
func CreateMapEngine(gameState *Common.GameState, soundManager *Sound.Manager, fileProvider Common.FileProvider) *Engine {
result := &Engine{
gameState: gameState,
soundManager: soundManager,
fileProvider: fileProvider,
regions: make([]EngineRegion, 0),
}
return result
}
func (v *Engine) GenerateMap(regionType RegionIdType, levelPreset int) {
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
}
func (v *Engine) Render(target *ebiten.Image) {
// 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)
}
offX += 80
offY += 40
}
}
}