Player

public class Player : SKSpriteNode

A class representation of the game player.

The player class is a subclass of SKSpriteNode that contains additional logic for handling player changes such as costume switching.

STORED PROPERTIES

  • Thre current costume the player is wearing.

    Declaration

    Swift

    public var costume: PlayerCostumeType { get set }
  • Whether the player is currently playing an animation.

    Declaration

    Swift

    var animating: Bool
  • Whether the player is changing costumes.

    Declaration

    Swift

    var isChangingCostumes: Bool
  • hud

    The heads-up display for the player.

    Declaration

    Swift

    var hud: SKNode
  • Whether to enable ML mode.

    Declaration

    Swift

    var machine: Bool { get set }

COMPUTED PROPERTIES

  • The SKTexture frames that play when a player is changing costumes.

    Declaration

    Swift

    var changingFrames: [SKTexture] { get }
  • The walk cycle animation when moving south.

    Declaration

    Swift

    var forwardWalkCycle: [SKTexture] { get }
  • The walk cycle animation when moving north.

    Declaration

    Swift

    var backwardWalkCycle: [SKTexture] { get }
  • The walk cycle animation when moving north.

    Declaration

    Swift

    var sidewardWalkCycle: [SKTexture] { get }
  • Whether the player is carrying an object.

    Declaration

    Swift

    public var isCarryingObject: Bool { get }
  • The list of all available costumes for the player.

    Declaration

    Swift

    public var costumes: [PlayerCostumeType] { get }

CONSTRUCTOR

  • Initialize the player.

    Declaration

    Swift

    public init(texture: SKTexture?, allowCostumes: [PlayerCostumeType])

    Parameters

    texture

    A texture to apply to the sprite.

    allowCostumes

    A list of all of the allowed costumes for a particular level.

  • Initialize the player.

    Declaration

    Swift

    public init(texture: SKTexture?, allowCostumes: [PlayerCostumeType], startingWith costume: PlayerCostumeType)

    Parameters

    texture

    A texture to apply to the sprite.

    allowCostumes

    A list of all of the allowed costumes for a particular level.

    costume

    The costume the player starts with.

  • Initialize the player.

    Declaration

    Swift

    override init(texture: SKTexture?, color: NSColor, size: CGSize)

    Parameters

    texture

    A texture to apply to the sprite.

    color

    The color of the sprite.

    size

    The size of the sprite.

  • Required initializer for this class. Will result in a fatal error if you initialize the object this way.

    Declaration

    Swift

    required init?(coder aDecoder: NSCoder)

STATIC METHODS

  • Get the list of costumes from a given ID.

    Note

    In most cases, IDs will range from 0-2, 0 being the default scenario (flash drive), and 2 being all available costumes (flash drive, bird, and sorceress). In cases where a player can take off a costume, use ID 3.

    Declaration

    Swift

    public static func getCostumeSet(id: Int) -> [PlayerCostumeType]

    Parameters

    id

    An integer representing the ID of costumes available.

COSTUME CHANGE METHODS

  • Switch to the previous costume.

    Declaration

    Swift

    public func previousCostume() -> PlayerCostumeType

    Return Value

    The previous costume the player is now wearing.

  • Switch to the next available costume.

    Declaration

    Swift

    public func nextCostume() -> PlayerCostumeType

    Return Value

    The next costume the player has switched to.

  • Remove a costume from the costume queue.

    Declaration

    Swift

    func remove(costume: PlayerCostumeType)

    Parameters

    costume

    The costume to remove from the queue.

  • Update the player’s data.

    Declaration

    Swift

    public func update()

MOVEMENT METHODS

  • Move the player by a specific amount and adjust the velocity repsectively.

    Use this when needing to apply an impulse directly on the player to cause a movement to occur. In other instances, using move(_ direction: PlayerMoveDirection, unit: CGSize) is preferred. Additionally, this method does not handle the proper animation to play when moving in a direction.

    Declaration

    Swift

    public func move(_ delta: CGVector)

    Parameters

    delta

    A vector that represents the delta to move by.

  • Stop the player from moving and remove all current animations.

    Declaration

    Swift

    public func halt()
  • Make a copy of the player’s sprite body in the map.

    Declaration

    Swift

    public func copyAsObject()
  • Move the player in a given direction, relative to the size of the world.

    This method is typically preferred since AI agents can call this method instead of calculating the delta beforehand. This method also handles any animations that need to be added to make sure the player has an appropriate animation while walking.

    Declaration

    Swift

    public func move(_ direction: PlayerMoveDirection, unit: CGSize)

    Parameters

    direction

    The direction the player will move in.

    unit

    The base unit to calculate the movement delta, relatively.