JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 34
  • Score
    100M100P100Q75695F
  • License MIT

Composable Game Input.

Package Exports

  • @hmans/controlfreak
  • @hmans/controlfreak/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@hmans/controlfreak) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Version Downloads Bundle Size

CONTROL FREAK

tl;dr

Add it to your project:

yarn add @hmans/controlfreak

Write a module that composes and exports your game controller, eg controller.ts:

import {
  compositeKeyboardVector,
  Controller,
  gamepadAxisVector,
  normalizeVector,
  VectorControl
} from "@hmans/controlfreak"

export const controller = new Controller()

controller
  .addControl("move", VectorControl)
  .addStep(compositeKeyboardVector("w", "s", "a", "d"))
  .addStep(gamepadAxisVector(0, 1))
  .addStep(clampVector(1))

controller
  .addControl("fire", BooleanControl)
  .addStep(whenKeyPressed(" "))
  .addStep(whenButtonPressed(0))

controller
  .addControl("aim", VectorControl)
  .addStep(compositeKeyboardVector("up", "down", "left", "right"))
  .addStep(gamepadAxisVector(2, 3))
  .addStep(normalizeVector)

Then use it in your game loop:

import { controller } from "./controller"

/* Very likely within some sort of loop...: */
controller.update()
console.log(controller.controls.move.value)