xxxxxxxxxx
43
//生成したモデルのURLに入れ替える!
let url = 'https://teachablemachine.withgoogle.com/models/Bqh6T9b8/';
let game; //ゲーム本体
let classifier; //ml5によるクラス分け
let mode = 0; //ゲームモード 0:学習中、1:ゲームプレイ
function preload(){
classifier = new Classifier(url);
classifier.preload();
}
function setup(){
createCanvas(windowWidth, windowHeight);
// テニスゲームを初期化
game = new TennisGame();
// 学習開始
classifier.setup();
// ゲームを開始モードに
mode = 1;
}
function draw(){
// カメラ映像を表示
classifier.draw();
if(mode == 1){
//ゲームの更新と描画
game.update();
game.draw();
//分析の結果でバーを動かす
if(classifier.currentLabel == 'left'){
game.bar.location.x += game.bar.speed;
}
if(classifier.currentLabel == 'right'){
game.bar.location.x -= game.bar.speed;
}
}
}
// 学習完了
function gotResult(error, results) {
classifier.gotResult(error, results);
}