Skip to content

Commit

Permalink
Pong example crank support (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrr authored Aug 26, 2024
1 parent 5237983 commit f1b163f
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions Examples/Pong/Sources/Pong/Game.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down

0 comments on commit f1b163f

Please sign in to comment.