From 76ac685cbb43348ce402892c76915a53394d547b Mon Sep 17 00:00:00 2001 From: Sander Schobers Date: Thu, 14 May 2020 07:47:29 +0200 Subject: [PATCH] Added panning with keyboard. Changed D for digging into H for harvesting. --- README.md | 4 ++-- gamecontrols.go | 2 +- intro.go | 4 ++-- projection.go | 23 ++++++++++++++--------- terrainrenderer.go | 8 ++++++++ 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f35b008..beb1714 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,13 @@ In Botanim you play the role of botanist and your goal is to cultivate flowers i Flowers can only grow (well) in certain climates based on two properties: humidity and temperature. Watch out for existing vegetation to get an idea how humid the land is and check the appearance of the tile to see how hot it is. When well placed your planted flower will spread soon but an odd choice might kill your flower almost instantly. So choose carefully. When the flower spread significantly you can dig up flowers again to collect more money. **Controls:** - - D: Selects shovel + - H: Selects shovel - R: Selects research - Spacebar: pauses game - 1: runs game at normal speed - 2: runs game extra fast - Mouse wheel or plus/minus: zooms landscape - - CTRL + left mouse button or middle mouse button: pans landscape + - W, A, S, D keys or CTRL + left mouse button or middle mouse button: pans landscape Have fun playing! diff --git a/gamecontrols.go b/gamecontrols.go index 9d95285..44ebe1d 100644 --- a/gamecontrols.go +++ b/gamecontrols.go @@ -163,7 +163,7 @@ func (c *GameControls) Handle(ctx *Context, event sdl.Event) bool { c.game.Run() case sdl.K_2: c.game.RunFast() - case sdl.K_d: + case sdl.K_h: c.game.SelectShovel() case sdl.K_r: c.dialogs.ShowResearch(ctx) diff --git a/intro.go b/intro.go index f88ed34..cea2aae 100644 --- a/intro.go +++ b/intro.go @@ -12,13 +12,13 @@ func (i *Intro) Init(ctx *Context) error { "In Botanim you play the role of botanist and your goal is to cultivate flowers in an open landscape.\n\n" + "Flowers can only grow (well) in certain climates based on two properties: humidity and temperature. Watch out for existing vegetation to get an idea how humid the land is and check the appearance of the tile to see how hot it is. When well placed your planted flower will spread soon but an odd choice might kill your flower almost instantly. So choose carefully. When the flower spread significantly you can dig up flowers again to collect more money.\n\n" + "Controls:\n" + - " - D: Selects shovel\n" + + " - H: Selects shovel\n" + " - R: Selects research\n" + " - Spacebar: pauses game\n" + " - 1: runs game at normal speed\n" + " - 2: runs game extra fast\n" + " - Mouse wheel or plus/minus: zooms landscape\n" + - " - CTRL + left mouse button or middle mouse button: pans landscape\n" + + " - W, A, S, D keys or CTRL + left mouse button or middle mouse button: pans landscape\n" + "\n" + "Have fun playing!" i.SetContent(&i.welcome) diff --git a/projection.go b/projection.go index f31b493..1b80773 100644 --- a/projection.go +++ b/projection.go @@ -101,6 +101,20 @@ func (p *projection) visibleTiles(action func(int32, int32, Point)) { } } +func (p *projection) Pan(ctx *Context, delta PointF) { + p.center = p.center.Add(delta.Mul(p.zoomInv)) + p.update(ctx.Renderer) +} + +func (p *projection) SetZoom(ctx *Context, center PointF, zoom float32) { + if p.zoom == zoom { + return + } + p.center = center.Sub(center.Sub(p.center).Mul(p.zoom / zoom)) + p.zoom = zoom + p.update(ctx.Renderer) +} + func (p *projection) ZoomOut(ctx *Context, center PointF) { if p.zoom <= .25 { return @@ -114,12 +128,3 @@ func (p *projection) ZoomIn(ctx *Context, center PointF) { } p.SetZoom(ctx, center, 2*p.zoom) } - -func (p *projection) SetZoom(ctx *Context, center PointF, zoom float32) { - if p.zoom == zoom { - return - } - p.center = center.Sub(center.Sub(p.center).Mul(p.zoom / zoom)) - p.zoom = zoom - p.update(ctx.Renderer) -} diff --git a/terrainrenderer.go b/terrainrenderer.go index ed97417..860c946 100644 --- a/terrainrenderer.go +++ b/terrainrenderer.go @@ -101,6 +101,14 @@ func (r *terrainRenderer) Handle(ctx *Context, event sdl.Event) bool { r.project.ZoomOut(ctx, r.project.center) case sdl.K_KP_MINUS: r.project.ZoomOut(ctx, r.project.center) + case sdl.K_w: + r.project.Pan(ctx, PtF(-1, -1)) + case sdl.K_a: + r.project.Pan(ctx, PtF(-1, 1)) + case sdl.K_s: + r.project.Pan(ctx, PtF(1, 1)) + case sdl.K_d: + r.project.Pan(ctx, PtF(1, -1)) } } }