2019-11-11 23:48:55 -05:00
|
|
|
package d2scene
|
|
|
|
|
|
|
|
import (
|
2019-12-21 20:53:18 -05:00
|
|
|
"image/color"
|
|
|
|
|
2020-01-26 00:39:13 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2enum"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2common/d2resource"
|
2019-11-17 01:14:58 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2audio"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core"
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2corecommon/d2coreinterface"
|
2020-01-25 23:28:21 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2input"
|
2019-12-16 11:04:39 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2player"
|
2019-11-13 00:31:52 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render"
|
2019-12-06 23:58:36 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2mapengine"
|
2019-12-28 16:46:08 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2surface"
|
2019-11-11 23:48:55 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2render/d2ui"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Game struct {
|
|
|
|
gameState *d2core.GameState
|
|
|
|
uiManager *d2ui.Manager
|
|
|
|
soundManager *d2audio.Manager
|
2019-11-17 00:16:33 -05:00
|
|
|
sceneProvider d2coreinterface.SceneProvider
|
2019-12-21 20:53:18 -05:00
|
|
|
pentSpinLeft *d2render.Sprite
|
|
|
|
pentSpinRight *d2render.Sprite
|
2019-11-13 00:31:52 -05:00
|
|
|
testLabel d2ui.Label
|
2019-12-13 00:33:11 -05:00
|
|
|
mapEngine *d2mapengine.MapEngine
|
|
|
|
hero *d2core.Hero
|
2019-12-16 11:04:39 -05:00
|
|
|
gameControls *d2player.GameControls
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func CreateGame(
|
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,
|
|
|
|
uiManager: uiManager,
|
|
|
|
soundManager: soundManager,
|
|
|
|
sceneProvider: sceneProvider,
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Game) Load() []func() {
|
|
|
|
return []func(){
|
|
|
|
func() {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.pentSpinLeft, _ = d2render.LoadSprite(d2resource.PentSpin, d2resource.PaletteSky)
|
|
|
|
v.pentSpinLeft.PlayBackward()
|
|
|
|
v.pentSpinLeft.SetPlayLengthMs(475)
|
|
|
|
v.pentSpinLeft.SetPosition(100, 300)
|
2019-11-13 00:31:52 -05:00
|
|
|
},
|
|
|
|
func() {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.pentSpinRight, _ = d2render.LoadSprite(d2resource.PentSpin, d2resource.PaletteSky)
|
|
|
|
v.pentSpinRight.PlayForward()
|
|
|
|
v.pentSpinRight.SetPlayLengthMs(475)
|
|
|
|
v.pentSpinRight.SetPosition(650, 300)
|
2019-11-13 00:31:52 -05:00
|
|
|
},
|
|
|
|
func() {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.testLabel = d2ui.CreateLabel(d2resource.Font42, d2resource.PaletteUnits)
|
2019-11-13 00:31:52 -05:00
|
|
|
v.testLabel.Alignment = d2ui.LabelAlignCenter
|
|
|
|
v.testLabel.SetText("Soon :tm:")
|
2019-12-21 20:53:18 -05:00
|
|
|
v.testLabel.SetPosition(400, 250)
|
2019-11-11 23:48:55 -05:00
|
|
|
},
|
2019-11-17 01:14:58 -05:00
|
|
|
func() {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.mapEngine = d2mapengine.CreateMapEngine(v.gameState, v.soundManager)
|
2019-11-17 01:14:58 -05:00
|
|
|
v.mapEngine.GenerateMap(d2enum.RegionAct1Town, 1, 0)
|
2019-12-13 00:33:11 -05:00
|
|
|
|
|
|
|
startX, startY := v.mapEngine.GetStartPosition()
|
|
|
|
v.hero = d2core.CreateHero(
|
|
|
|
int32(startX*5)+3,
|
|
|
|
int32(startY*5)+3,
|
2019-11-17 01:14:58 -05:00
|
|
|
0,
|
|
|
|
v.gameState.HeroType,
|
|
|
|
v.gameState.Equipment,
|
2019-12-13 00:33:11 -05:00
|
|
|
)
|
|
|
|
v.mapEngine.AddEntity(v.hero)
|
2019-11-17 01:14:58 -05:00
|
|
|
},
|
2019-12-16 11:04:39 -05:00
|
|
|
func() {
|
2019-12-21 20:53:18 -05:00
|
|
|
v.gameControls = d2player.NewGameControls(v.hero, v.mapEngine)
|
2019-12-16 11:04:39 -05:00
|
|
|
v.gameControls.Load()
|
2020-01-25 23:28:21 -05:00
|
|
|
d2input.BindHandler(v.gameControls)
|
2019-12-16 11:04:39 -05:00
|
|
|
},
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v *Game) Unload() {
|
2020-01-25 23:28:21 -05:00
|
|
|
d2input.UnbindHandler(v.gameControls)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2019-12-28 16:46:08 -05:00
|
|
|
func (v Game) Render(screen *d2surface.Surface) {
|
|
|
|
screen.Clear(color.Black)
|
2019-11-17 01:14:58 -05:00
|
|
|
v.mapEngine.Render(screen)
|
2019-12-16 11:04:39 -05:00
|
|
|
v.gameControls.Render(screen)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2019-12-28 23:32:24 -05:00
|
|
|
func (v *Game) Advance(tickTime float64) {
|
2019-12-13 00:33:11 -05:00
|
|
|
v.mapEngine.Advance(tickTime)
|
2019-12-02 16:55:48 -05:00
|
|
|
|
2019-12-13 00:33:11 -05:00
|
|
|
rx, ry := v.mapEngine.WorldToOrtho(v.hero.AnimatedEntity.LocationX/5, v.hero.AnimatedEntity.LocationY/5)
|
|
|
|
v.mapEngine.MoveCameraTo(rx, ry)
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|