## 第11回 ## 先週のやったこと 衝突回避 ## 今週の目標 座標の取得をして簡単なゲームを作る ## 座標取得 サイト https://qiita.com/youtoy/items/6620385a0f77e22ac6fd https://github.com/toio/toio.js/blob/master/examples/chase/index.js コード ``` const { NearestScanner } = require('@toio/scanner') export let toiojs = {}; //let cube = {}; let cube = { connected: "(defined)", turnOnLight: _ => undefined, turnOffLight: _ => undefined, playPresetSound: _ => undefined, stopSound: _ => undefined, move: _ => undefined, stop: _ => undefined }; export async function main() { // start a scanner to find the nearest cube const cube = await new NearestScanner().start(); // connect to the cube await cube.connect(); //座標の取得 let cubeX = 0 let cubeY = 0 cube.on('id:position-id', data => { cubeX = data.x cubeY = data.y console.log('X座標',cubeX) console.log('Y座標',cubeY) }) } ``` ## 角度の取得(toioがマットに対して向いている角度) コード ``` const { NearestScanner } = require('@toio/scanner') export let toiojs = {}; //let cube = {}; let cube = { connected: "(defined)", turnOnLight: _ => undefined, turnOffLight: _ => undefined, playPresetSound: _ => undefined, stopSound: _ => undefined, move: _ => undefined, stop: _ => undefined }; export async function main() { // start a scanner to find the nearest cube const cube = await new NearestScanner().start(); // connect to the cube await cube.connect(); cube.on('id:standard-id', data => { console.log(data) }) } ``` ## 思い付きのゲーム ![](https://i.imgur.com/08ap68Z.png)