6 changed files with 173 additions and 4 deletions
@ -0,0 +1,65 @@
|
||||
package system |
||||
|
||||
import ( |
||||
"code.rocketnine.space/tslocum/commandeuropa/component" |
||||
"code.rocketnine.space/tslocum/commandeuropa/world" |
||||
"code.rocketnine.space/tslocum/gohan" |
||||
"github.com/hajimehoshi/ebiten/v2" |
||||
) |
||||
|
||||
type HandleInput struct { |
||||
Once *component.Once |
||||
} |
||||
|
||||
func (r *HandleInput) Update(e gohan.Entity) error { |
||||
const panDistance = 3 |
||||
|
||||
// Pan with keyboard.
|
||||
if ebiten.IsKeyPressed(ebiten.KeyLeft) { |
||||
world.CamX -= panDistance |
||||
} |
||||
if ebiten.IsKeyPressed(ebiten.KeyRight) { |
||||
world.CamX += panDistance |
||||
} |
||||
if ebiten.IsKeyPressed(ebiten.KeyUp) { |
||||
world.CamY -= panDistance |
||||
} |
||||
if ebiten.IsKeyPressed(ebiten.KeyDown) { |
||||
world.CamY += panDistance |
||||
} |
||||
|
||||
// Zoom with mouse.
|
||||
const minZoom = 1 |
||||
const maxZoom = 7 |
||||
_, scroll := ebiten.Wheel() |
||||
if scroll < 0 { |
||||
world.CamScale -= 1 |
||||
if world.CamScale < minZoom { |
||||
world.CamScale = minZoom |
||||
} |
||||
} else if scroll > 0 { |
||||
world.CamScale += 1 |
||||
if world.CamScale > maxZoom { |
||||
world.CamScale = maxZoom |
||||
} |
||||
} |
||||
|
||||
// Pan with mouse.
|
||||
const panArea = 7 |
||||
x, y := ebiten.CursorPosition() |
||||
if x <= panArea { |
||||
world.CamX -= panDistance |
||||
} else if x >= world.ScreenWidth-panArea { |
||||
world.CamX += panDistance |
||||
} |
||||
if y <= panArea { |
||||
world.CamY -= panDistance |
||||
} else if y >= world.ScreenHeight-panArea { |
||||
world.CamY += panDistance |
||||
} |
||||
return nil |
||||
} |
||||
|
||||
func (r *HandleInput) Draw(e gohan.Entity, screen *ebiten.Image) error { |
||||
return gohan.ErrUnregister |
||||
} |
@ -0,0 +1,17 @@
|
||||
package world |
||||
|
||||
import ( |
||||
"github.com/hajimehoshi/ebiten/v2" |
||||
) |
||||
|
||||
type MapTile struct { |
||||
Sprite *ebiten.Image |
||||
} |
||||
|
||||
func NewGameMap(w, h int) []MapTile { |
||||
tiles := make([]MapTile, w*h) |
||||
for i := range tiles { |
||||
tiles[i].Sprite = blankSprite |
||||
} |
||||
return tiles |
||||
} |
Loading…
Reference in new issue