2020-02-01 18:55:56 -05:00
|
|
|
package d2gamescene
|
2019-11-11 23:48:55 -05:00
|
|
|
|
|
|
|
import (
|
2019-12-21 20:53:18 -05:00
|
|
|
"image/color"
|
|
|
|
|
2020-06-13 18:32:09 -04:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2game/d2player"
|
2020-02-01 18:55:56 -05:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2map"
|
2020-06-13 18:32:09 -04:00
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2networking/d2client"
|
|
|
|
|
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2input"
|
2020-02-01 20:39:28 -05:00
|
|
|
"github.com/OpenDiablo2/OpenDiablo2/d2core/d2render"
|
2019-11-11 23:48:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Game struct {
|
2020-06-13 18:32:09 -04:00
|
|
|
//pentSpinLeft *d2ui.Sprite
|
|
|
|
//pentSpinRight *d2ui.Sprite
|
|
|
|
//testLabel d2ui.Label
|
|
|
|
gameClient *d2client.GameClient
|
|
|
|
mapRenderer *d2map.MapRenderer
|
|
|
|
gameControls *d2player.GameControls // TODO: Hack
|
|
|
|
localPlayer *d2map.Player
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2020-06-13 18:32:09 -04:00
|
|
|
func CreateGame(gameClient *d2client.GameClient) *Game {
|
|
|
|
return &Game{
|
|
|
|
gameClient: gameClient,
|
|
|
|
gameControls: nil,
|
|
|
|
localPlayer: nil,
|
|
|
|
mapRenderer: d2map.CreateMapRenderer(gameClient.MapEngine),
|
|
|
|
}
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *Game) OnLoad() error {
|
2020-06-13 18:32:09 -04:00
|
|
|
//animation, _ := d2asset.LoadAnimation(d2resource.PentSpin, d2resource.PaletteSky)
|
|
|
|
//v.pentSpinLeft, _ = d2ui.LoadSprite(animation)
|
|
|
|
//v.pentSpinLeft.PlayBackward()
|
|
|
|
//v.pentSpinLeft.SetPlayLengthMs(475)
|
|
|
|
//v.pentSpinLeft.SetPosition(100, 300)
|
|
|
|
//
|
|
|
|
//animation, _ = d2asset.LoadAnimation(d2resource.PentSpin, d2resource.PaletteSky)
|
|
|
|
//v.pentSpinRight, _ = d2ui.LoadSprite(animation)
|
|
|
|
//v.pentSpinRight.PlayForward()
|
|
|
|
//v.pentSpinRight.SetPlayLengthMs(475)
|
|
|
|
//v.pentSpinRight.SetPosition(650, 300)
|
|
|
|
//
|
|
|
|
//v.testLabel = d2ui.CreateLabel(d2resource.Font42, d2resource.PaletteUnits)
|
|
|
|
//v.testLabel.Alignment = d2ui.LabelAlignCenter
|
|
|
|
//v.testLabel.SetText("Soon :tm:")
|
|
|
|
//v.testLabel.SetPosition(400, 250)
|
|
|
|
|
|
|
|
/*
|
|
|
|
startX, startY := v.mapEngine.GetStartPosition()
|
|
|
|
v.hero = d2map.CreateHero(
|
|
|
|
int(startX*5)+3,
|
|
|
|
int(startY*5)+3,
|
|
|
|
0,
|
|
|
|
v.gameState.HeroType,
|
|
|
|
v.gameState.Equipment,
|
|
|
|
)
|
|
|
|
v.mapEngine.AddEntity(v.hero)
|
|
|
|
|
|
|
|
v.gameControls = d2player.NewGameControls(v.hero, v.mapEngine)
|
|
|
|
v.gameControls.Load()
|
|
|
|
d2input.BindHandler(v.gameControls)
|
|
|
|
*/
|
2020-02-08 21:02:37 -05:00
|
|
|
|
|
|
|
return nil
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *Game) OnUnload() error {
|
2020-06-13 18:32:09 -04:00
|
|
|
d2input.UnbindHandler(v.gameControls) // TODO: hack
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *Game) Render(screen d2render.Surface) error {
|
2019-12-28 16:46:08 -05:00
|
|
|
screen.Clear(color.Black)
|
2020-06-13 18:32:09 -04:00
|
|
|
v.mapRenderer.Render(screen)
|
|
|
|
if v.gameControls != nil {
|
|
|
|
v.gameControls.Render(screen)
|
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|
|
|
|
|
2020-02-08 21:02:37 -05:00
|
|
|
func (v *Game) Advance(tickTime float64) error {
|
2020-06-13 18:32:09 -04:00
|
|
|
v.gameClient.MapEngine.Advance(tickTime) // TODO: Hack
|
|
|
|
|
|
|
|
// Bind the game controls to the player once it exists
|
|
|
|
if v.gameControls == nil {
|
|
|
|
for _, player := range v.gameClient.Players {
|
|
|
|
if player.Id != v.gameClient.PlayerId {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
v.localPlayer = player
|
|
|
|
v.gameControls = d2player.NewGameControls(player, v.gameClient.MapEngine, v.mapRenderer, v.gameClient)
|
|
|
|
v.gameControls.Load()
|
|
|
|
d2input.BindHandler(v.gameControls)
|
|
|
|
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the camera to focus on the player
|
|
|
|
if v.localPlayer != nil {
|
|
|
|
rx, ry := v.mapRenderer.WorldToOrtho(v.localPlayer.AnimatedComposite.LocationX/5, v.localPlayer.AnimatedComposite.LocationY/5)
|
|
|
|
v.mapRenderer.MoveCameraTo(rx, ry)
|
|
|
|
}
|
2020-02-08 21:02:37 -05:00
|
|
|
return nil
|
2019-11-11 23:48:55 -05:00
|
|
|
}
|