Last active
September 20, 2020 11:08
-
-
Save thykka/5c975ec65a0b5f7cf158cf0de9ea966a to your computer and use it in GitHub Desktop.
SCRIPT-8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const PointerAppearance = { | |
| cursor: { | |
| sprite: 127, | |
| offset: [1, 1] | |
| }, | |
| crosshair: { | |
| sprite: 126, | |
| offset: [4, 4] | |
| } | |
| } | |
| const createPointer = (options = {}) => { | |
| const defaults = { | |
| position: [63, 63], | |
| speed: [0, 0], | |
| acceleration: 0.1, | |
| appearance: 'cursor', | |
| bounds: [0, 0, 127, 127] | |
| } | |
| return Object.assign({}, defaults, options) | |
| } | |
| init = state => { | |
| state.pointer = createPointer() | |
| } | |
| const updatePointer = (pointer, input) => { | |
| const moved = movePointer(pointer, input) | |
| if (moved) limitPointerToBounds(pointer) | |
| } | |
| const movePointer = (pointer, input) => { | |
| const previousPosition = [...pointer.position] | |
| pointer.speed = pointer.speed.map((v, i) => v * 0.9) | |
| if (input.left) pointer.speed[0] -= pointer.acceleration | |
| if (input.right) pointer.speed[0] += pointer.acceleration | |
| if (input.up) pointer.speed[1] -= pointer.acceleration | |
| if (input.down) pointer.speed[1] += pointer.acceleration | |
| if(Math.abs(pointer.speed[0]) < 0.1 && Math.abs(pointer.speed[1]) < 0.1) { | |
| return false | |
| } | |
| pointer.position = pointer.position.map((v, i) => v + pointer.speed[i]) | |
| return true | |
| } | |
| const limitPointerToBounds = pointer => { | |
| pointer.position[0] = clamp( | |
| pointer.position[0], | |
| pointer.bounds[0], | |
| pointer.bounds[2] | |
| ) | |
| pointer.position[1] = clamp( | |
| pointer.position[1], | |
| pointer.bounds[1], | |
| pointer.bounds[3] | |
| ) | |
| } | |
| update = (state, input, elapsed) => { | |
| updatePointer(state.pointer, input) | |
| } | |
| const drawPointer = pointer => { | |
| const appearance = PointerAppearance[pointer.appearance] | |
| sprite( | |
| ...pointer.position.map((v, i) => v - appearance.offset[i]), | |
| appearance.sprite | |
| ) | |
| } | |
| draw = state => { | |
| clear(4) | |
| drawPointer(state.pointer) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "iframeVersion": "0.1.280", | |
| "lines": [ | |
| 77, | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0, | |
| 0 | |
| ] | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "125": [ | |
| " ", | |
| " 000 ", | |
| " 00700 ", | |
| " 0007000", | |
| " 0007700", | |
| " 0000000", | |
| " 00000 ", | |
| " 000 " | |
| ], | |
| "126": [ | |
| " ", | |
| " 0 ", | |
| " 0 ", | |
| " ", | |
| " 00 7 00", | |
| " ", | |
| " 0 ", | |
| " 0 " | |
| ], | |
| "127": [ | |
| "77 ", | |
| "707 ", | |
| "7007 ", | |
| "70007 ", | |
| "7007 ", | |
| "70707 ", | |
| "77 7 ", | |
| " " | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment