2019-11-10 08:51:02 -05:00
|
|
|
package d2scene
|
2019-10-27 19:00:38 -04:00
|
|
|
|
|
|
|
import (
|
2019-11-06 18:25:19 -05:00
|
|
|
"fmt"
|
|
|
|
"math"
|
|
|
|
|
2019-11-10 03:36:53 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2helper"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2interface"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2audio"
|
2019-11-13 14:26:42 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
2019-11-10 08:51:02 -05:00
|
|
|
_map "github.com/OpenDiablo2/OpenDiablo2/d2render/d2mapengine"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2ui"
|
2019-10-27 19:00:38 -04:00
|
|
|
"github.com/hajimehoshi/ebiten"
|
2019-11-06 18:25:19 -05:00
|
|
|
"github.com/hajimehoshi/ebiten/ebitenutil"
|
2019-11-13 14:26:42 -05:00
|
|
|
"os"
|
2019-10-27 19:00:38 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type MapEngineTest struct {
|
2019-11-10 08:51:02 -05:00
|
|
|
uiManager *d2ui.Manager
|
2019-11-10 03:36:53 -05:00
|
|
|
soundManager *d2audio.Manager
|
|
|
|
fileProvider d2interface.FileProvider
|
|
|
|
sceneProvider d2interface.SceneProvider
|
|
|
|
gameState *d2core.GameState
|
2019-11-06 22:12:15 -05:00
|
|
|
mapEngine *_map.Engine
|
2019-11-13 14:26:42 -05:00
|
|
|
currentRegion int
|
|
|
|
keyLocked bool
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
2019-11-01 14:12:23 -04:00
|
|
|
func CreateMapEngineTest(
|
2019-11-10 03:36:53 -05:00
|
|
|
fileProvider d2interface.FileProvider,
|
|
|
|
sceneProvider d2interface.SceneProvider,
|
2019-11-10 08:51:02 -05:00
|
|
|
uiManager *d2ui.Manager,
|
2019-11-13 14:26:42 -05:00
|
|
|
soundManager *d2audio.Manager,
|
|
|
|
currentRegion int) *MapEngineTest {
|
2019-10-27 19:00:38 -04:00
|
|
|
result := &MapEngineTest{
|
|
|
|
fileProvider: fileProvider,
|
|
|
|
uiManager: uiManager,
|
|
|
|
soundManager: soundManager,
|
|
|
|
sceneProvider: sceneProvider,
|
2019-11-13 14:26:42 -05:00
|
|
|
currentRegion: currentRegion,
|
|
|
|
keyLocked: false,
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
2019-11-11 23:48:55 -05:00
|
|
|
result.gameState = d2core.CreateTestGameState()
|
2019-10-27 19:00:38 -04:00
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2019-11-13 14:26:42 -05:00
|
|
|
type RegionSpec struct {
|
|
|
|
regionType d2enum.RegionIdType
|
|
|
|
levelPreset int
|
|
|
|
}
|
|
|
|
|
|
|
|
var regions []RegionSpec = []RegionSpec{
|
|
|
|
{d2enum.RegionAct1Tristram, 300},
|
|
|
|
{d2enum.RegionAct1Cathedral, 257},
|
|
|
|
{d2enum.RegionAct2Town, 301},
|
|
|
|
// {d2enum.RegionAct2Harem, 353},
|
|
|
|
{d2enum.RegionAct3Town, 529},
|
|
|
|
{d2enum.RegionAct3Jungle, 574},
|
|
|
|
{d2enum.RegionAct4Town, 797},
|
|
|
|
{d2enum.RegonAct5Town, 863},
|
|
|
|
{d2enum.RegionAct5IceCaves, 1038},
|
|
|
|
{d2enum.RegionAct5Siege, 879},
|
|
|
|
{d2enum.RegionAct5Lava, 105},
|
|
|
|
{d2enum.RegionAct5Barricade, 880},
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MapEngineTest) LoadRegionByIndex(n int) {
|
|
|
|
if n == 0 {
|
|
|
|
v.mapEngine.GenerateAct1Overworld()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
region := regions[n-1]
|
|
|
|
|
|
|
|
v.mapEngine = _map.CreateMapEngine(v.gameState, v.soundManager, v.fileProvider) // necessary for map name update
|
|
|
|
v.mapEngine.OffsetY = 0
|
|
|
|
v.mapEngine.OffsetX = 0
|
|
|
|
v.mapEngine.GenerateMap(region.regionType, region.levelPreset)
|
|
|
|
}
|
|
|
|
|
2019-10-27 19:00:38 -04:00
|
|
|
func (v *MapEngineTest) Load() []func() {
|
2019-10-31 13:39:05 -04:00
|
|
|
// TODO: Game seed comes from the game state object
|
2019-10-31 21:17:13 -04:00
|
|
|
|
2019-10-27 21:35:16 -04:00
|
|
|
v.soundManager.PlayBGM("")
|
|
|
|
return []func(){
|
|
|
|
func() {
|
2019-11-06 22:12:15 -05:00
|
|
|
v.mapEngine = _map.CreateMapEngine(v.gameState, v.soundManager, v.fileProvider)
|
2019-11-01 22:12:07 -04:00
|
|
|
|
2019-11-13 14:26:42 -05:00
|
|
|
v.LoadRegionByIndex(v.currentRegion)
|
|
|
|
// v.mapEngine.GenerateAct1Overworld()
|
|
|
|
// v.mapEngine.GenerateMap(d2enum.RegionAct1Tristram, 300)
|
|
|
|
// v.mapEngine.GenerateMap(d2enum.RegionAct1Cathedral, 257)
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct2Town, 301)
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct2Harem, 353) // Crashes on dcc load
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct3Town, 529)
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct3Jungle, 574)
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct4Town, 797) // Broken height of large objects
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegonAct5Town, 863) // Completely broken!!
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct5IceCaves, 1038) // Completely broken!
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct5Siege, 879) // Completely broken!
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct5Lava, 1057) // Broken
|
|
|
|
//v.mapEngine.GenerateMap(d2enum.RegionAct5Barricade, 880) // Broken
|
2019-11-01 16:51:50 -04:00
|
|
|
|
2019-10-27 21:35:16 -04:00
|
|
|
},
|
|
|
|
}
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MapEngineTest) Unload() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MapEngineTest) Render(screen *ebiten.Image) {
|
2019-10-31 21:17:13 -04:00
|
|
|
v.mapEngine.Render(screen)
|
2019-11-06 18:25:19 -05:00
|
|
|
actualX := float64(v.uiManager.CursorX) - v.mapEngine.OffsetX
|
|
|
|
actualY := float64(v.uiManager.CursorY) - v.mapEngine.OffsetY
|
2019-11-10 03:36:53 -05:00
|
|
|
tileX, tileY := d2helper.ScreenToIso(actualX, actualY)
|
2019-11-06 18:25:19 -05:00
|
|
|
subtileX := int(math.Ceil(math.Mod((tileX*10), 10))) / 2
|
|
|
|
subtileY := int(math.Ceil(math.Mod((tileY*10), 10))) / 2
|
|
|
|
curRegion := v.mapEngine.GetRegionAt(int(tileX), int(tileY))
|
|
|
|
if curRegion == nil {
|
|
|
|
return
|
|
|
|
}
|
2019-11-06 21:25:09 -05:00
|
|
|
line := fmt.Sprintf("%d, %d (Tile %d.%d, %d.%d)",
|
|
|
|
int(math.Ceil(actualX)),
|
|
|
|
int(math.Ceil(actualY)),
|
|
|
|
int(math.Ceil(tileX))-curRegion.Rect.Left,
|
|
|
|
subtileX,
|
|
|
|
int(math.Ceil(tileY))-curRegion.Rect.Top,
|
|
|
|
subtileY,
|
|
|
|
)
|
|
|
|
ebitenutil.DebugPrintAt(screen, line, 5, 5)
|
|
|
|
ebitenutil.DebugPrintAt(screen, "Map: "+curRegion.Region.LevelType.Name, 5, 17)
|
2019-11-13 14:26:42 -05:00
|
|
|
ebitenutil.DebugPrintAt(screen, fmt.Sprintf("%v [%v]", curRegion.Region.RegionPath, v.currentRegion), 5, 29)
|
|
|
|
ebitenutil.DebugPrintAt(screen, "N - next map, P - previous map", 5, 41)
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *MapEngineTest) Update(tickTime float64) {
|
2019-11-01 14:12:23 -04:00
|
|
|
if v.uiManager.KeyPressed(ebiten.KeyDown) {
|
|
|
|
v.mapEngine.OffsetY -= tickTime * 800
|
|
|
|
}
|
|
|
|
if v.uiManager.KeyPressed(ebiten.KeyUp) {
|
|
|
|
v.mapEngine.OffsetY += tickTime * 800
|
|
|
|
}
|
|
|
|
if v.uiManager.KeyPressed(ebiten.KeyLeft) {
|
|
|
|
v.mapEngine.OffsetX += tickTime * 800
|
|
|
|
}
|
|
|
|
if v.uiManager.KeyPressed(ebiten.KeyRight) {
|
|
|
|
v.mapEngine.OffsetX -= tickTime * 800
|
|
|
|
}
|
2019-11-13 14:26:42 -05:00
|
|
|
if v.uiManager.KeyPressed(ebiten.KeyEscape) {
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
if v.uiManager.KeyPressed(ebiten.KeyN) && !v.keyLocked {
|
|
|
|
v.currentRegion++
|
|
|
|
if v.currentRegion == len(regions) {
|
|
|
|
v.currentRegion = 0
|
|
|
|
}
|
|
|
|
v.keyLocked = true
|
|
|
|
fmt.Println("---")
|
|
|
|
v.sceneProvider.SetNextScene(v)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if v.uiManager.KeyPressed(ebiten.KeyP) && !v.keyLocked {
|
|
|
|
v.currentRegion--
|
|
|
|
if v.currentRegion == -1 {
|
|
|
|
v.currentRegion = len(regions) - 1
|
|
|
|
}
|
|
|
|
v.keyLocked = true
|
|
|
|
fmt.Println("---")
|
|
|
|
v.sceneProvider.SetNextScene(v)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
//FIXME: do it better
|
|
|
|
if !v.uiManager.KeyPressed(ebiten.KeyP) && !v.uiManager.KeyPressed(ebiten.KeyN) {
|
|
|
|
v.keyLocked = false
|
|
|
|
}
|
2019-10-27 19:00:38 -04:00
|
|
|
}
|