summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2023-10-20 05:05:29 +0100
committerdavidovski <david@davidovski.xyz>2023-10-20 05:05:29 +0100
commitdfe5a3ef5f71b59d89ee66094ae69e456776b480 (patch)
tree23cdbe076d99945834d0ef2477840e4a1eb83ec3
parent2fc34e551e9e883210e7416930516de5d324dda4 (diff)
add camera interpolation
-rw-r--r--pengui.go8
1 files changed, 4 insertions, 4 deletions
diff --git a/pengui.go b/pengui.go
index 3be2347..f88db84 100644
--- a/pengui.go
+++ b/pengui.go
@@ -20,9 +20,9 @@ var BLUE = color.RGBA{0x81, 0xa2, 0xbe, 0xff}
const screen_w, screen_h = 960, 540
const GRAVITY, FRICTION, AIR_RESISTANCE, PUSH = 1.2, 0.02, 0.004, 0.8
-const DELTA_RESOLUTION, DRAW_RESOLUTION, STROKE_WIDTH = 1.0, 4.0, 4.0
+const CAMERA_DELAY, DELTA_RESOLUTION, DRAW_RESOLUTION, STROKE_WIDTH = 0.7, 1.0, 4.0, 4.0
-var sx, sy = 0.0, 0.0
+var sx, sy, sxv, syv = 0.0, 0.0, 0.0, 0.0
type Penguin struct {
img *ebiten.Image
@@ -237,9 +237,9 @@ type Game struct{
func (g *Game) Update() error {
// calculate scroll x and y
- sx = -(g.penguin.Cx() - screen_w/2)
- sy = -(g.penguin.Cy() - screen_h/2)
+ sx = (CAMERA_DELAY * sx - (1-CAMERA_DELAY) * (g.penguin.Cx() - screen_w/2))
+ sy = (CAMERA_DELAY * sy - (1-CAMERA_DELAY) * (g.penguin.Cy() - screen_h/2))
if ebiten.IsMouseButtonPressed(ebiten.MouseButton0){
cx, cy := ebiten.CursorPosition()