From f1b163fd8e70d5894c4899ceda1cfed22b74a3a3 Mon Sep 17 00:00:00 2001 From: John Ruble Date: Mon, 26 Aug 2024 16:01:17 -0400 Subject: [PATCH] Pong example crank support (#88) --- Examples/Pong/Sources/Pong/Game.swift | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Examples/Pong/Sources/Pong/Game.swift b/Examples/Pong/Sources/Pong/Game.swift index 7a42a4ec..36f00598 100644 --- a/Examples/Pong/Sources/Pong/Game.swift +++ b/Examples/Pong/Sources/Pong/Game.swift @@ -186,16 +186,22 @@ class ComputerPaddle: Paddle { class PlayerPaddle: Paddle { override func update() { - if System.buttonState.current.contains(.down) { - moveWithCollisions( - goal: position + Vector(x: 0, y: speed) - ) - } - - if System.buttonState.current.contains(.up) { - moveWithCollisions( - goal: position - Vector(x: 0, y: speed) - ) + if System.isCrankDocked{ + if System.buttonState.current.contains(.down) { + moveWithCollisions( + goal: position + Vector(x: 0, y: speed) + ) + } + if System.buttonState.current.contains(.up) { + moveWithCollisions( + goal: position - Vector(x: 0, y: speed) + ) + } + }else{ + /// 0 at the top, 1 at the bottom + let zeroToOne :Float = (180 - abs(System.crankAngle-180))/180 + let targetY = zeroToOne * Float(Display.height) + moveWithCollisions(goal: Point(x:position.x,y:targetY)) } } }