Restructured the source code in the Playdate bindings target.
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
internal import CPlaydate
|
||||
|
||||
extension Sprite {
|
||||
/// Information about a single collision, mirroring `SpriteCollisionInfo`.
|
||||
public struct CollisionInfo {
|
||||
/// The sprite being moved.
|
||||
public let sprite: Sprite
|
||||
/// The sprite it collided with.
|
||||
public let other: Sprite
|
||||
/// The collision response used.
|
||||
public let response: CollisionResponse
|
||||
/// `true` if the sprites were overlapping when the collision
|
||||
/// started; `false` if the sprite tunneled through.
|
||||
public let overlaps: Bool
|
||||
/// How far along the movement (0...1) the collision occurred.
|
||||
public let ti: Float
|
||||
/// The difference between the requested and actual positions.
|
||||
public let move: (x: Float, y: Float)
|
||||
/// The collision normal (each component -1, 0, or 1).
|
||||
public let normal: (x: Int, y: Int)
|
||||
/// Where the sprite started touching `other`.
|
||||
public let touch: (x: Float, y: Float)
|
||||
/// The sprite's rect at the moment of the touch.
|
||||
public let spriteRect: Rect
|
||||
/// `other`'s rect at the moment of 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)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
internal import CPlaydate
|
||||
|
||||
extension Sprite {
|
||||
/// Information about a sprite intersected by a line segment,
|
||||
/// mirroring `SpriteQueryInfo`.
|
||||
public struct QueryInfo {
|
||||
public let sprite: Sprite
|
||||
/// How far along the segment (0...1) the segment enters the sprite.
|
||||
public let ti1: Float
|
||||
/// How far along the segment (0...1) the segment exits the sprite.
|
||||
public let ti2: Float
|
||||
public let entryPoint: (x: Float, y: Float)
|
||||
public let exitPoint: (x: Float, y: Float)
|
||||
|
||||
init(_ info: SpriteQueryInfo) {
|
||||
sprite = Sprite.wrapper(for: info.sprite)
|
||||
ti1 = info.ti1
|
||||
ti2 = info.ti2
|
||||
entryPoint = (info.entryPoint.x, info.entryPoint.y)
|
||||
exitPoint = (info.exitPoint.x, info.exitPoint.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
internal import CPlaydate
|
||||
|
||||
/// A floating-point rectangle mirroring `PDRect`.
|
||||
public struct Rect: Sendable {
|
||||
public var x: Float
|
||||
public var y: Float
|
||||
public var width: Float
|
||||
public var height: Float
|
||||
|
||||
public init(x: Float, y: Float, width: Float, height: Float) {
|
||||
self.x = x
|
||||
self.y = y
|
||||
self.width = width
|
||||
self.height = height
|
||||
}
|
||||
|
||||
init(_ rect: PDRect) {
|
||||
self.init(x: rect.x, y: rect.y, width: rect.width, height: rect.height)
|
||||
}
|
||||
|
||||
var cValue: PDRect { PDRect(x: x, y: y, width: width, height: height) }
|
||||
}
|
||||
Reference in New Issue
Block a user