|
|
|
@ -30,8 +30,8 @@ func (r *RenderEnvironment) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|
|
|
|
r.Initialize()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for x := 0; x < world.MapSize; x++ {
|
|
|
|
|
for y := 0; y < world.MapSize; y++ {
|
|
|
|
|
for x := 0.0; x < world.MapSize; x++ {
|
|
|
|
|
for y := 0.0; y < world.MapSize; y++ {
|
|
|
|
|
i := world.TileIndex(x, y)
|
|
|
|
|
t := world.Map[i]
|
|
|
|
|
|
|
|
|
@ -46,11 +46,11 @@ func (r *RenderEnvironment) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
r.renderTile(t, x, y, screen)
|
|
|
|
|
renderSprite(screen, t.Sprite, x, y, r.op)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
highlightX, highlightY := -1, -1
|
|
|
|
|
highlightX, highlightY := -1.0, -1.0
|
|
|
|
|
if highlightX >= 0 && highlightY >= 0 && highlightX < world.MapSize && highlightY < world.MapSize {
|
|
|
|
|
boxX, boxY := world.LevelCoordinatesToScreen(highlightX, highlightY)
|
|
|
|
|
right := boxX + world.TileSize*world.CamScale
|
|
|
|
@ -58,35 +58,39 @@ func (r *RenderEnvironment) Draw(e gohan.Entity, screen *ebiten.Image) error {
|
|
|
|
|
|
|
|
|
|
outerColor := color.RGBA{0, 0, 0, 255}
|
|
|
|
|
outerSize := 3 * world.CamScale
|
|
|
|
|
screen.SubImage(image.Rect(boxX, boxY, right, boxY+outerSize)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
screen.SubImage(image.Rect(boxX, bottom-outerSize, right, bottom)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
screen.SubImage(image.Rect(boxX, boxY, boxX+outerSize, bottom)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
screen.SubImage(image.Rect(right-outerSize, boxY, right, bottom)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
screen.SubImage(floatRect(boxX, boxY, right, boxY+outerSize)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
screen.SubImage(floatRect(boxX, bottom-outerSize, right, bottom)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
screen.SubImage(floatRect(boxX, boxY, boxX+outerSize, bottom)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
screen.SubImage(floatRect(right-outerSize, boxY, right, bottom)).(*ebiten.Image).Fill(outerColor)
|
|
|
|
|
|
|
|
|
|
innerColor := color.RGBA{255, 255, 255, 255}
|
|
|
|
|
innerPadding := 1 * world.CamScale
|
|
|
|
|
innerSize := 1 * world.CamScale
|
|
|
|
|
screen.SubImage(image.Rect(boxX+innerPadding, boxY+innerPadding, right-innerPadding, boxY+innerPadding+innerSize)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
screen.SubImage(image.Rect(boxX+innerPadding, bottom-innerPadding-innerSize, right-innerPadding, bottom-innerPadding)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
screen.SubImage(image.Rect(boxX+innerPadding, boxY+innerPadding, boxX+innerPadding+innerSize, bottom-innerPadding)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
screen.SubImage(image.Rect(right-innerPadding-innerSize, boxY+innerPadding, right-innerPadding, bottom-innerPadding)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
screen.SubImage(floatRect(boxX+innerPadding, boxY+innerPadding, right-innerPadding, boxY+innerPadding+innerSize)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
screen.SubImage(floatRect(boxX+innerPadding, bottom-innerPadding-innerSize, right-innerPadding, bottom-innerPadding)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
screen.SubImage(floatRect(boxX+innerPadding, boxY+innerPadding, boxX+innerPadding+innerSize, bottom-innerPadding)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
screen.SubImage(floatRect(right-innerPadding-innerSize, boxY+innerPadding, right-innerPadding, bottom-innerPadding)).(*ebiten.Image).Fill(innerColor)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *RenderEnvironment) renderTile(t world.Tile, x int, y int, target *ebiten.Image) int {
|
|
|
|
|
r.op.GeoM.Reset()
|
|
|
|
|
func renderSprite(target *ebiten.Image, img *ebiten.Image, x float64, y float64, op *ebiten.DrawImageOptions) int {
|
|
|
|
|
op.GeoM.Reset()
|
|
|
|
|
|
|
|
|
|
// Move to current position.
|
|
|
|
|
r.op.GeoM.Translate(float64(x*world.TileSize), float64(y*world.TileSize))
|
|
|
|
|
op.GeoM.Translate(x*world.TileSize, y*world.TileSize)
|
|
|
|
|
// Translate camera position.
|
|
|
|
|
r.op.GeoM.Translate(float64(-world.CamX), float64(-world.CamY))
|
|
|
|
|
op.GeoM.Translate(float64(-world.CamX), float64(-world.CamY))
|
|
|
|
|
// Zoom.
|
|
|
|
|
r.op.GeoM.Scale(float64(world.CamScale), float64(world.CamScale))
|
|
|
|
|
op.GeoM.Scale(float64(world.CamScale), float64(world.CamScale))
|
|
|
|
|
// Center.
|
|
|
|
|
r.op.GeoM.Translate(float64(world.ScreenWidth/2), float64(world.ScreenHeight/2))
|
|
|
|
|
op.GeoM.Translate(float64(world.ScreenWidth/2), float64(world.ScreenHeight/2))
|
|
|
|
|
|
|
|
|
|
target.DrawImage(t.Sprite, r.op)
|
|
|
|
|
target.DrawImage(img, op)
|
|
|
|
|
return 1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func floatRect(x0, y0, x1, y1 float64) image.Rectangle {
|
|
|
|
|
return image.Rect(int(x0), int(y0), int(x1), int(y1))
|
|
|
|
|
}
|
|
|
|
|