Coder Social home page Coder Social logo

pxt-maker-controller's Introduction

maker-controller

The extension allows to easily create custom controllers for MakeCode Arcade games (https://arcade.makecode.com) running in the browser.

Under the hood, the extension uses the keyboard extension to generate keyboard key stroke that emulate one or more players.

Usage

This repository contains a MakeCode extension. To use it in MakeCode,

Button press

Simulate a button press when a button in pressed on your device.

input.buttonA.onEvent(ButtonEvent.Click, function () {
    makerController.player1.press(ControllerButton.A)
})

Up, down states

Simulate buttons left and right pressed based on the accelerometer readings.

forever(function () {
    if (input.acceleration(Dimension.X) < -300) {
        makerController.player1.setButtonDown(ControllerButton.Right, false)
        makerController.player1.setButtonDown(ControllerButton.Left, true)
        light.photonForward(1)
    } else if (input.acceleration(Dimension.X) > 300) {
        makerController.player1.setButtonDown(ControllerButton.Left, false)
        makerController.player1.setButtonDown(ControllerButton.Right, true)
        light.photonForward(-1)
    } else {
        makerController.player1.reset()
    }
})

Analog buttons

Map analog sensors to dpad buttons.

forever(function () {
    makerController.player1.setAnalog(ArcadeAnalogButton.LeftRight, input.acceleration(Dimension.X))
    makerController.player1.setAnalog(ArcadeAnalogButton.DownUp, input.acceleration(Dimension.Y))
})

Also map analog sensors to A/B buttons.

forever(function () {
    makerController.player1.setAnalog(ArcadeAnalogButton.A, input.soundLevel())
})

You can tune the threshold to detect that a button is pressed or not.

makerController.player1.setAnalogThreshold(ArcadeAnalogButton.A, 0, 200)

Collaborators

You can invite users to become collaborators to this repository. This will allow multiple users to work on the same project at the same time. Learn more...

To edit this repository in MakeCode,

Supported targets

  • for PXT/adafruit
  • for PXT/codal
  • for PXT/maker

(The metadata above is needed for package search.)

pxt-maker-controller's People

Contributors

microsoft-github-operations[bot] avatar microsoftopensource avatar pelikhan avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pxt-maker-controller's Issues

Not working for the micro:bit

Hi @pelikhan,

Just read with joy your fun article about "Everything is a Keyboard".

But I am unable to get this pxt-maker-controller extension to work for the micro:bit in the official https://makecode.microbit.org/ editor.

The extension won't load at all into the editor.

Having somewhat similar MCU as many of the maker boards on maker.makecode.com, I had expected it to work also for the micro:bit.

Do you know why the this extension isn't working for the micro:bit, and maybe what your think could be done to make it work?

Br,
Vegard

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.