This PR contains the work done to update the library and the attached example project to use the Swift 6.4 computer as a minimum supported version and also, to use the latest features introduced in it. Reviewed-on: #1 Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
39 lines
1.5 KiB
Swift
39 lines
1.5 KiB
Swift
internal import CPlaydate
|
|
|
|
extension Sprite {
|
|
/// A single collision. Wraps `SpriteCollisionInfo`.
|
|
public struct CollisionInfo {
|
|
/// The sprite being moved.
|
|
public let sprite: Sprite
|
|
public let other: Sprite
|
|
public let response: CollisionResponse
|
|
/// `true` if already overlapping `other` at the start; `false` if it tunneled through.
|
|
public let overlaps: Bool
|
|
/// Fraction of the move to the goal done at the collision, 0...1.
|
|
public let ti: Float
|
|
/// Difference between the original and actual positions at the collision.
|
|
public let move: (x: Float, y: Float)
|
|
/// Components usually -1, 0, or 1.
|
|
public let normal: (x: Int, y: Int)
|
|
/// Where `sprite` started touching `other`.
|
|
public let touch: (x: Float, y: Float)
|
|
/// `sprite`'s rect at the touch.
|
|
public let spriteRect: Rect
|
|
/// `other`'s rect at the touch.
|
|
public let otherRect: Rect
|
|
|
|
init(_ info: SpriteCollisionInfo) {
|
|
sprite = Sprite.wrapper(for: info.sprite)
|
|
other = Sprite.wrapper(for: info.other)
|
|
response = CollisionResponse(info.responseType)
|
|
overlaps = info.overlaps != 0
|
|
ti = info.ti
|
|
move = (info.move.x, info.move.y)
|
|
normal = (Int(info.normal.x), Int(info.normal.y))
|
|
touch = (info.touch.x, info.touch.y)
|
|
spriteRect = Rect(info.spriteRect)
|
|
otherRect = Rect(info.otherRect)
|
|
}
|
|
}
|
|
}
|