2019-11-11 23:48:55 -05:00
|
|
|
package d2scene
|
|
|
|
|
|
|
|
import (
|
2019-11-13 00:31:52 -05:00
|
|
|
"image/color"
|
2019-11-17 01:14:58 -05:00
|
|
|
|
2019-11-26 21:04:36 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2data/d2dc6"
|
|
|
|
|
2019-11-17 01:14:58 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2helper"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2mapengine"
|
2019-11-13 00:31:52 -05:00
|
|
|
|
2019-11-17 00:16:33 -05:00
|
|
|
"github.com/OpenDiablo2/D2Shared/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/D2Shared/d2common/d2interface"
|
|
|
|
"github.com/OpenDiablo2/D2Shared/d2common/d2resource"
|
|
|
|
"github.com/OpenDiablo2/D2Shared/d2data/d2datadict"
|
2019-11-17 01:14:58 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2audio"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2corecommon/d2coreinterface"
|
2019-11-13 00:31:52 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render"
|
2019-11-11 23:48:55 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2ui"
|
|
|
|
"github.com/hajimehoshi/ebiten"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Game struct {
|
|
|
|
gameState *d2core.GameState
|
|
|
|
uiManager *d2ui.Manager
|
|
|
|
soundManager *d2audio.Manager
|
|
|
|
fileProvider d2interface.FileProvider
|
2019-11-17 00:16:33 -05:00
|
|
|
sceneProvider d2coreinterface.SceneProvider
|
2019-11-13 00:31:52 -05:00
|
|
|
pentSpinLeft d2render.Sprite
|
|
|
|
pentSpinRight d2render.Sprite
|
|
|
|
testLabel d2ui.Label
|
2019-11-17 01:14:58 -05:00
|
|
|
mapEngine *d2mapengine.Engine
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateGame(
|
|
|
|
fileProvider d2interface.FileProvider,
|
2019-11-17 00:16:33 -05:00
|
|
|
sceneProvider d2coreinterface.SceneProvider,
|
2019-11-11 23:48:55 -05:00
|
|
|
uiManager *d2ui.Manager,
|
|
|
|
soundManager *d2audio.Manager,
|
|
|
|
gameState *d2core.GameState,
|
|
|
|
) *Game {
|
|
|
|
result := &Game{
|
|
|
|
gameState: gameState,
|
|
|
|
fileProvider: fileProvider,
|
|
|
|
uiManager: uiManager,
|
|
|
|
soundManager: soundManager,
|
|
|
|
sceneProvider: sceneProvider,
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Game) Load() []func() {
|
|
|
|
return []func(){
|
|
|
|
func() {
|
2019-11-24 17:58:23 -05:00
|
|
|
dc6, _ := d2dc6.LoadDC6(v.fileProvider.LoadFile(d2resource.PentSpin), d2datadict.Palettes[d2enum.Sky])
|
|
|
|
v.pentSpinLeft = d2render.CreateSpriteFromDC6(dc6)
|
2019-11-13 00:31:52 -05:00
|
|
|
v.pentSpinLeft.Animate = true
|
|
|
|
v.pentSpinLeft.AnimateBackwards = true
|
|
|
|
v.pentSpinLeft.SpecialFrameTime = 475
|
|
|
|
v.pentSpinLeft.MoveTo(100, 300)
|
|
|
|
},
|
|
|
|
func() {
|
2019-11-24 17:58:23 -05:00
|
|
|
dc6, _ := d2dc6.LoadDC6(v.fileProvider.LoadFile(d2resource.PentSpin), d2datadict.Palettes[d2enum.Sky])
|
|
|
|
v.pentSpinRight = d2render.CreateSpriteFromDC6(dc6)
|
2019-11-13 00:31:52 -05:00
|
|
|
v.pentSpinRight.Animate = true
|
|
|
|
v.pentSpinRight.SpecialFrameTime = 475
|
|
|
|
v.pentSpinRight.MoveTo(650, 300)
|
|
|
|
},
|
|
|
|
func() {
|
|
|
|
v.testLabel = d2ui.CreateLabel(v.fileProvider, d2resource.Font42, d2enum.Units)
|
|
|
|
v.testLabel.Alignment = d2ui.LabelAlignCenter
|
|
|
|
v.testLabel.SetText("Soon :tm:")
|
|
|
|
v.testLabel.MoveTo(400, 250)
|
2019-11-11 23:48:55 -05:00
|
|
|
},
|
2019-11-17 01:14:58 -05:00
|
|
|
func() {
|
|
|
|
v.mapEngine = d2mapengine.CreateMapEngine(v.gameState, v.soundManager, v.fileProvider)
|
|
|
|
// TODO: This needs to be different depending on the act of the player
|
|
|
|
v.mapEngine.GenerateMap(d2enum.RegionAct1Town, 1, 0)
|
2019-12-06 09:44:52 -05:00
|
|
|
v.mapEngine.SetRegion(0)
|
|
|
|
region := v.mapEngine.Region()
|
2019-12-02 16:55:48 -05:00
|
|
|
rx, ry := d2helper.IsoToScreen(region.Region.StartX, region.Region.StartY, 0, 0)
|
|
|
|
v.mapEngine.CenterCameraOn(rx, ry)
|
2019-11-17 01:14:58 -05:00
|
|
|
v.mapEngine.Hero = d2core.CreateHero(
|
|
|
|
int32((region.Region.StartX*5)+3),
|
|
|
|
int32((region.Region.StartY*5)+3),
|
|
|
|
0,
|
|
|
|
v.gameState.HeroType,
|
|
|
|
v.gameState.Equipment,
|
|
|
|
v.fileProvider)
|
|
|
|
},
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Game) Unload() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v Game) Render(screen *ebiten.Image) {
|
2019-11-13 00:31:52 -05:00
|
|
|
screen.Fill(color.Black)
|
2019-11-17 01:14:58 -05:00
|
|
|
v.mapEngine.Render(screen)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Game) Update(tickTime float64) {
|
2019-11-17 01:14:58 -05:00
|
|
|
// TODO: Pathfinding
|
2019-12-02 16:55:48 -05:00
|
|
|
|
|
|
|
if v.mapEngine.Hero.AnimatedEntity.LocationX != v.mapEngine.Hero.AnimatedEntity.TargetX ||
|
|
|
|
v.mapEngine.Hero.AnimatedEntity.LocationY != v.mapEngine.Hero.AnimatedEntity.TargetY {
|
|
|
|
v.mapEngine.Hero.AnimatedEntity.Step(tickTime)
|
|
|
|
}
|
|
|
|
|
2019-12-06 09:44:52 -05:00
|
|
|
for _, npc := range v.mapEngine.Region().Region.NPCs {
|
|
|
|
|
|
|
|
if npc.HasPaths &&
|
|
|
|
npc.AnimatedEntity.LocationX == npc.AnimatedEntity.TargetX &&
|
|
|
|
npc.AnimatedEntity.LocationY == npc.AnimatedEntity.TargetY {
|
|
|
|
// If at the target, set target to the next path.
|
|
|
|
// TODO: pause at target, figure out how to use Path.Action
|
|
|
|
path := npc.NextPath()
|
|
|
|
npc.AnimatedEntity.SetTarget(
|
|
|
|
float64(path.X),
|
|
|
|
float64(path.Y),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
if npc.AnimatedEntity.LocationX != npc.AnimatedEntity.TargetX ||
|
|
|
|
npc.AnimatedEntity.LocationY != npc.AnimatedEntity.TargetY {
|
|
|
|
npc.AnimatedEntity.Step(tickTime)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-11-17 01:14:58 -05:00
|
|
|
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
|
|
|
mx, my := ebiten.CursorPosition()
|
|
|
|
px, py := d2helper.ScreenToIso(float64(mx)-v.mapEngine.OffsetX, float64(my)-v.mapEngine.OffsetY)
|
2019-12-02 16:55:48 -05:00
|
|
|
|
2019-12-06 09:44:52 -05:00
|
|
|
v.mapEngine.Hero.AnimatedEntity.SetTarget(px*5, py*5)
|
2019-11-17 01:14:58 -05:00
|
|
|
}
|
2019-11-11 23:48:55 -05:00
|
|
|
|
2019-12-06 09:44:52 -05:00
|
|
|
rx, ry := d2helper.IsoToScreen(v.mapEngine.Hero.AnimatedEntity.LocationX/5, v.mapEngine.Hero.AnimatedEntity.LocationY/5, 0, 0)
|
|
|
|
v.mapEngine.CenterCameraOn(rx, ry)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|