API Documentation for: 0.11.8
Show:

platypus.components.LogicWindUpRacer Class

Replicates logic for a wind-up toy: listens for a wind-up message over a series of ticks to charge, and then begins racing once the charge is complete.

Methods

'handle-logic'

(
  • message.delta
)

Defined in 'handle-logic':63

On a tick logic message, the component updates its charging counter if necessary.

Parameters:

  • message.delta Number

    To determine how much to charge, the component checks the length of the tick.

'hit-solid'

(
  • collision.x
)

Defined in 'hit-solid':149

On receiving this message, the entity stops racing.

Parameters:

  • collision.x Number

    Either 1,0, or -1. 1 if we're colliding with an object on our right. -1 if on our left. 0 if not at all.

'stop-racing'

()

Defined in 'stop-racing':127

Causes the entity to stop racing.

'wind-up'

(
  • message.pressed
)

Defined in 'wind-up':137

Causes the entity to wind up for a race.

Parameters:

  • message.pressed Boolean

    If message is included, the component checks the value of pressed: false causes winding to stop.

addEventListener

(
  • event
  • callback
)
Function private
This method adds an event listener to the entity.

Parameters:

  • event String
    The event that this component should listen for.
  • callback Function
    The handler for the event.

Returns:

Function: handler A reference to the bound handler.

addMethod

(
  • name
  • func
)
private
This method adds a method to the entity.

Parameters:

  • name String
    The name of the method. For example, if name is "turnYellow", the method is accessible on the entity as entity.turnYellow().
  • func Function
    The function describing the method.

destroy

() private

Inherited from platypus.Component: destroy:54

This method cleans up listeners and methods that this component added to the entity. It should never be called by the component itself. Call this.owner.removeComponent(this) instead.

getAssetList

(
  • definition
  • properties
  • defaultProperties
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • definition Object
    The definition for the component.
  • properties Object
    The properties of the Entity.
  • defaultProperties Object
    The default properties of the Entity.

Returns:

Array: A list of the necessary assets to load.

getLateAssetList

(
  • data
)
Array
This method can be overwritten to provide the list of assets this component requires. This method is invoked when the list of game scenes is created to determine assets for each scene.

Parameters:

  • data Object
    Scene data that affects the list of assets.

Returns:

Array: A list of the necessary assets to load.

removeEventListener

(
  • event
  • callback
)
private
This method removes an event listener from the entity.

Parameters:

  • event String
    The event for which to remove a listener.
  • callback Function
    The listener to remove. If not supplied, all event listeners for the provided event are removed.

removeEventListeners

(
  • [listeners]
)
private
This method removes multiple event listeners from the entity.

Parameters:

  • [listeners] Array optional
    The list of listeners to remove. If not supplied, all event listeners are removed.

removeMethod

(
  • name
)
private
This method removes a method from the entity.

Parameters:

  • name String
    The name of the method to be removed.

toJSON

() Object

Inherited from platypus.Component: toJSON:45

Available since 0.11.0

Returns a JSON object describing the component.

Returns:

Object: Returns a JSON definition that can be used to recreate the component.

toString

() String
Returns a string describing the component.

Returns:

String: Returns the component type as a string of the form "[Component ComponentType]".

Properties

inputs

Object

Defined in inputs:161

This is the list of events containing key/value pairs that describe state changes to make for the given event.

{
                                                "smell-toast": {
                                                    "smelling-food": true,
                                                    "smelling-nothing": false
                                                },
                                                "go-to-store": {
                                                    "at-store": true
                                                }
                                            }

Default: null

outputs

Object

Defined in outputs:180

These are messages that should be triggered when certain conditions are met. The messages are only triggered the instant the condition is met, until the conditions are no longer met and then once again met. Example:

{
                                                "smelling-food": { // Keys map to states, and if true, the value of the key is processed. In this case, the value of the "smelling-food" key is another object of key/value pairs, giving us another layer of checks.
                                                    "!smelling-trash": "time-to-eat", // This key is an inverse check, meaning that the "smelling-trash" state of the entity must be false to continue along this path. This time the value is a string, so the string "time-to-eat" is treated as a message to be broadcast if the entity is both "smelling-food" and not "smelling-trash".
                                                    "true": "belly-rumble" // In some cases, a message should be triggered for a set of states, while still doing deeper state checks like above. "true" will always handle the next layer of values if the parent key was true.
                                                },
                                                "smelling-trash": "feeling-sick" // Multiple states can be handled to multiple depths, like a list of if () statements
                                                "!smelling-nothing": {
                                                    "!smelling-trash":{
                                                        "!at-store": "go-to-store", // Note that the "go-to-store" message will change this entity's state to "at-store" according to "inputs" above, but LogicStateMachine uses a cache of states when broadcasting output messages, so the next section will not be processed until the next state check.
                                                        "at-store":{
                                                            "have-money": "buy-more-food",
                                                            "!have-money": "buy-less-food"
                                                        }
                                                    }
                                                }
                                            }

Default: null

raceTime

Number

Defined in raceTime:26

Time in milliseconds that entity will race before coming to a stop.

Default: 5000

speed

Number

Defined in speed:17

Velocity at which the entity should travel while racing.

Default: 0.3

windTime

Number

Defined in windTime:35

Time in milliseconds that entity needs to receive wind-up calls before racing can begin.

Default: 500

Events

'blocked'

Defined in 'blocked':160

This message is triggered if the entity collides while racing.

Event Payload:

'racing'

Defined in 'racing':74

This event is triggered when winding is finished and the entity begins racing.

'stopped-racing'

Defined in 'stopped-racing':88

This event is triggered when the entity stops racing.

'stopped-winding'

This event is triggered when the entity stops winding.

'winding'

Defined in 'winding':100

This event is triggered as the entity winds up.

Event Payload:

  • fraction Number

    The amount of progress that has been made from 0 to 1.