1
1
mirror of https://github.com/OpenDiablo2/OpenDiablo2 synced 2024-11-18 02:16:23 -05:00

fix(camera): focus the local player on viewport init (#620)

Thanks!
This commit is contained in:
Benjamin Maisonnas 2020-07-25 15:36:15 +02:00 committed by GitHub
parent b13175b070
commit 89b031d2b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 4 deletions

View File

@ -32,7 +32,7 @@ type MapRenderer struct {
} }
// CreateMapRenderer creates a new MapRenderer, sets the required fields and returns a pointer to it. // CreateMapRenderer creates a new MapRenderer, sets the required fields and returns a pointer to it.
func CreateMapRenderer(renderer d2interface.Renderer, mapEngine *d2mapengine.MapEngine, term d2interface.Terminal) *MapRenderer { func CreateMapRenderer(renderer d2interface.Renderer, mapEngine *d2mapengine.MapEngine, term d2interface.Terminal, startX, startY float64) *MapRenderer {
result := &MapRenderer{ result := &MapRenderer{
renderer: renderer, renderer: renderer,
mapEngine: mapEngine, mapEngine: mapEngine,
@ -40,7 +40,8 @@ func CreateMapRenderer(renderer d2interface.Renderer, mapEngine *d2mapengine.Map
} }
result.Camera = Camera{} result.Camera = Camera{}
startPosition := d2vector.NewPosition(0, 0) rx, ry := result.WorldToOrtho(startX, startY)
startPosition := d2vector.NewPosition(rx, ry)
result.Camera.position = &startPosition result.Camera.position = &startPosition
result.viewport.SetCamera(&result.Camera) result.viewport.SetCamera(&result.Camera)

View File

@ -51,13 +51,24 @@ func CreateGame(
gameClient *d2client.GameClient, gameClient *d2client.GameClient,
term d2interface.Terminal, term d2interface.Terminal,
) *Game { ) *Game {
// find the local player and its initial location
var startX, startY float64
for _, player := range gameClient.Players {
if player.ID != gameClient.PlayerID {
continue
}
worldPosition := player.Position.World()
startX, startY = worldPosition.X(), worldPosition.Y()
break
}
result := &Game{ result := &Game{
gameClient: gameClient, gameClient: gameClient,
gameControls: nil, gameControls: nil,
localPlayer: nil, localPlayer: nil,
lastRegionType: d2enum.RegionNone, lastRegionType: d2enum.RegionNone,
ticksSinceLevelCheck: 0, ticksSinceLevelCheck: 0,
mapRenderer: d2maprenderer.CreateMapRenderer(renderer, gameClient.MapEngine, term), mapRenderer: d2maprenderer.CreateMapRenderer(renderer, gameClient.MapEngine, term, startX, startY),
escapeMenu: NewEscapeMenu(navigator, renderer, audioProvider), escapeMenu: NewEscapeMenu(navigator, renderer, audioProvider),
inputManager: inputManager, inputManager: inputManager,
audioProvider: audioProvider, audioProvider: audioProvider,

View File

@ -186,7 +186,7 @@ func (met *MapEngineTest) OnLoad(loading d2screen.LoadingState) {
loading.Progress(fiftyPercent) loading.Progress(fiftyPercent)
met.mapRenderer = d2maprenderer.CreateMapRenderer(met.renderer, met.mapEngine, met.terminal) met.mapRenderer = d2maprenderer.CreateMapRenderer(met.renderer, met.mapEngine, met.terminal, 0.0, 0.0)
loading.Progress(seventyPercent) loading.Progress(seventyPercent)
met.loadRegionByIndex(met.currentRegion, met.levelPreset, met.fileIndex) met.loadRegionByIndex(met.currentRegion, met.levelPreset, met.fileIndex)