xxxxxxxxxx
659
let mode = 8;
let counter =1;
let cntmod=0;
let check1=0;
let compsign;
let plsign;
let video;
let classifier;
let label = 'loading...';
let change = 0;
let round = 1;
let opponent_score = 0;
let avatar_score = 0;
let moves = ['rock', 'paper', 'scissors'];
let opponent_move_1;
let opponent_move_2;
let opponent_move_3;
function preload(){
classifier = ml5.imageClassifier('https://teachablemachine.withgoogle.com/models/Xk2dAwXyw/'+'model.json')
unicornfont = loadFont('GoodUnicornRegular-Rxev.ttf');
background_1 = loadImage("background_1.jpg");
background_2 = loadImage("background_2.jpg");
background_3 = loadImage("background_3.jpg");
background_4 = loadImage("background_4.jpg");
background_5 = loadImage("background_5.jpg");
background_6 = loadImage("background_6.jpg");
background_7a = loadImage("background_7a.jpg");
background_7b = loadImage("background_7b.png");
thumbs_up = loadImage("thumbs_up.png");
rock_sign = loadImage("rock_sign.png");
paper_sign = loadImage("paper_sign.png");
scissors_sign = loadImage("scissors_sign.png");
rock_sign_flip = loadImage("rock_sign_flip.png");
paper_sign_flip = loadImage("paper_sign_flip.png");
scissors_sign_flip = loadImage("scissors_sign_flip.png");
battlefield = loadImage("battlefield.jpg");
countdown_1 = loadImage("countdown_1.png");
countdown_2 = loadImage("countdown_2.png");
countdown_3 = loadImage("countdown_3.png");
go = loadImage("go.png");
}
function setup() {
createCanvas(640, 520);
// Create the video
video = createCapture(VIDEO);
video.hide();
classifyVideo();
opponent_move_1 = random(moves);
opponent_move_2 = random(moves);
opponent_move_3 = random(moves);
}
function classifyVideo(){
classifier.classify(video, gotResults)
}
function draw() {
switch(mode){
case(1):
startingScreen();
textSize(32);
textAlign(CENTER, CENTER);
fill(0);
text(label, width/2, height-16);
// print(label);
break;
case(2):
screen_2();
break;
case(3):
screen_3();
break;
case(4):
screen_4();
break;
case(5):
screen_5();
break;
case(6):
screen_6();
break;
case(7):
screen_7();
break;
case(8):
round_1();
break;
case(9):
round_2();
break;
case(10):
round_3();
break;
}
// image(video, 0, 0);
}
function gotResults(error, results){
if (error){
consol.error(error);
return
}
label = results[0].label
classifyVideo();
}
function startingScreen(){
push();
imageMode(CENTER);
image(background_1, width/2, height/2, width, height);
image(thumbs_up, width*0.7, height*0.8, width*0.1, height*0.1);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "Rock";
let s2 = "Paper";
let s3 = "Scissors!";
let s4 = "Show a thumbs-up to start";
let s5 = "START";
textSize(100);
fill(0);
text(s1,width/2, height/7);
text(s2,width/2, height/7+75);
text(s3,width/2, height/7+150);
textSize(50);
text(s4,width/2, height/5+220);
textSize(100);
text(s5,width/2, height/5+300);
if (label == 'nothing'){
change = 1;
}
if (label == 'thumbs_up' && change == 1){
mode = 2;
change = 0;
}
pop();
}
function screen_2(){
push();
imageMode(CENTER);
image(background_2, width*0.5, height*0.5, width, height);
image(rock_sign, width*0.5, height*0.4, width*0.3, height*0.3);
image(thumbs_up, width*0.9, height*0.05, width*0.05, height*0.05);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "ROCK";
let s2 = "next";
textSize(100);
fill(0);
text(s1,width/2, height/7);
textSize(30)
text(s2,width*0.96, height*0.04);
if (label == 'nothing'){
change = 1;
}
if (label == 'thumbs_up' && change == 1){
mode = 3;
change = 0;
}
pop();
}
function screen_3(){
push();
imageMode(CENTER);
image(background_3, width*0.5, height*0.5, width, height);
image(paper_sign, width*0.5, height*0.4, width*0.3, height*0.3);
image(thumbs_up, width*0.9, height*0.05, width*0.05, height*0.05);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "PAPER";
let s2 = "next";
textSize(100);
fill(0);
text(s1,width/2, height/7);
textSize(30)
text(s2,width*0.96, height*0.04);
if (label == 'nothing'){
change = 1;
}
if (label == 'thumbs_up' && change == 1){
mode = 4;
change = 0;
}
pop();
}
function screen_4(){
push();
imageMode(CENTER);
image(background_4, width*0.5, height*0.5, width, height);
image(scissors_sign, width*0.5, height*0.4, width*0.3, height*0.3);
image(thumbs_up, width*0.9, height*0.05, width*0.05, height*0.05);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "SCISSORS";
let s2 = "next";
textSize(100);
fill(255);
text(s1,width/2, height/7);
textSize(30)
text(s2,width*0.96, height*0.04);
if (label == 'nothing'){
change = 1;
}
if (label == 'thumbs_up' && change == 1){
mode = 5;
change = 0;
}
pop();
}
function screen_5(){
push();
imageMode(CENTER);
image(background_5, width*0.5, height*0.5, width, height);
image(thumbs_up, width*0.9, height*0.05, width*0.05, height*0.05);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "These nations lived peacefully";
let s3 = "amongst one another";
let s4 = "until one day...";
let s2 = "next";
textSize(50);
fill(0);
text(s1,width/2, height/4);
text(s3, width/2, height/4 + 50);
text(s4, width/2, height/4 + 130);
textSize(30)
text(s2,width*0.96, height*0.04);
if (label == 'nothing'){
change = 1;
}
if (label == 'thumbs_up' && change == 1){
mode = 6;
change = 0;
}
pop();
}
function screen_6(){
push();
imageMode(CENTER);
tint(255, 80);
image(background_6, width*0.5, height*0.5, width, height);
image(thumbs_up, width*0.9, height*0.05, width*0.05, height*0.05);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "A false messiah had risen up";
let s3 = "The one who is responsible for the ongoing 100 year war";
let s4 = "among the great nations";
let s2 = "next";
textSize(50);
fill(0);
text(s1,width/2, height/4);
text(s3, width/2, height/4 + 50);
text(s4, width/2, height/4 + 100);
textSize(30)
text(s2,width*0.96, height*0.04);
if (label == 'nothing'){
change = 1;
}
if (label == 'thumbs_up' && change == 1){
mode = 7;
change = 0;
}
pop();
}
function screen_7(){
push();
imageMode(CENTER);
image(background_7a, width*0.5, height*0.5, width, height);
tint(255, 80);
image(background_7b, width*0.5, height*0.5, width, height);
tint(255,255);
image(thumbs_up, width*0.8, height*0.68, width*0.1, height*0.1);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "Only you, the Avatar, can defeat him";
let s3 = "You can wield all 3 elements";
let s4 = "and end the messiah's rain of terror";
let s2 = "BEGIN FIGHT";
textSize(50);
fill(255);
text(s1,width/2, height/5);
text(s3, width/2, height/5 + 50);
text(s4, width/2, height/5 + 100);
textSize(70);
text(s2,width/2, height/5+250);
if (label == 'nothing'){
change = 1;
}
if (label == 'thumbs_up' && change == 1){
mode = 8;
change = 0;
}
pop();
}
function round_1(){
push();
counter+=1;
imageMode(CENTER);
image(battlefield, width*0.5, height*0.5, width, height);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "Round 1";
let s2 = "Opponent Score:";
let s3 = "Avatar Score:";
let s4 = opponent_score;
let s5 = avatar_score;
textSize(100);
fill(255);
text(s1,width*0.5, height*0.15);
textSize(30);
fill(255,0,0);
text(s2,width*0.15, height*0.2);
text(s4, width*0.15+90, height*0.2);
fill(0,0,255);
text(s3, width*0.8, height*0.2);
text(s5, width*0.8+80, height*0.2);
if(counter<=50){
image(countdown_3, width*0.5, height*0.5, width*0.2, height*0.2);
}
else if(counter<=100){
image(countdown_2, width*0.5, height*0.5, width*0.2, height*0.2);
}
else if(counter<=150){
image(countdown_1, width*0.5, height*0.5, width*0.2, height*0.2);
}
else{
image(go, width*0.5, height*0.5, width*0.2, height*0.2);
compsign=opponent_move_1;
print(compsign);
plsign=label;
if(check1==1)
{if(opponent_move_1 == 'rock'){
image(rock_sign, width*0.2, height*0.5, width*0.3, height*0.3);
if (label == 'scissors'){
image(scissors_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
opponent_score = opponent_score + 1;
}
else if (label == 'paper'){
image(paper_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
avatar_score = avatar_score + 1;
}
else if (label == 'rock'){
image(rock_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
}
}
else if(opponent_move_1 == 'paper'){
image(paper_sign, width*0.2, height*0.5, width*0.3, height*0.3);
if (label == 'scissors'){
image(scissors_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
avatar_score = avatar_score + 1;
}
else if (label == 'rock'){
image(rock_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
opponent_score = opponent_score + 1;
}
else if (label == 'paper'){
image(paper_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
}
}
else if(opponent_move_1 == 'scissors'){
image(scissors_sign, width*0.2, height*0.5, width*0.3, height*0.3);
if (label == 'rock'){
image(rock_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
avatar_score = avatar_score + 1;
}
else if (label == 'paper'){
image(paper_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
opponent_score = opponent_score + 1;
}
else if (label == 'scissors'){
image(scissors_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
}
}
}
if (plsign == 'rock'){
image(rock_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
}
else if (plsign == 'paper'){
image(paper_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
}
else if (plsign == 'scissors'){
image(scissors_sign_flip, width*0.8, height*0.5, width*0.3, height*0.3);
}
if (compsign == 'rock'){
image(rock_sign, width*0.2, height*0.5, width*0.3, height*0.3);
}
else if (compsign == 'paper'){
image(paper_sign, width*0.2, height*0.5, width*0.3, height*0.3);
}
else if (compsign == 'scissors'){
image(scissors_sign, width*0.2, height*0.5, width*0.3, height*0.3);
}
check1=0;
cntmod+=1;
if(cntmod>100){
mode=9;
cntmod = 0;
checkmod = 1;
}
}
pop();
}
function round_2(){
push();
imageMode(CENTER);
image(battlefield, width*0.5, height*0.5, width, height);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "Round 2";
let s2 = "Opponent Score:";
let s3 = "Avatar Score:";
let s4 = opponent_score;
let s5 = avatar_score;
textSize(100);
fill(255);
text(s1,width*0.5, height*0.15);
textSize(30);
fill(255,0,0);
text(s2,width*0.15, height*0.2);
text(s4, width*0.15+90, height*0.2);
fill(0,0,255);
text(s3, width*0.8, height*0.2);
text(s5, width*0.8+80, height*0.2);
image(countdown_3, width*0.5, height*0.5, width*0.2, height*0.2);
image(countdown_2, width*0.5, height*0.5, width*0.2, height*0.2);
image(countdown_1, width*0.5, height*0.5, width*0.2, height*0.2);
if(opponent_move_2 == 'rock'){
if (label == 'scissors'){
opponent_score = opponent_score + 1;
mode = 10;
}
else if (label == 'paper'){
avatar_score = avatar_score + 1;
mode = 10;
}
}
if(opponent_move_2 == 'paper'){
if (label == 'scissors'){
avatar_score = avatar_score + 1;
mode = 10;
}
else if (label == 'rock'){
opponent_score = opponent_score + 1;
mode = 10;
}
}
if(opponent_move_2 == 'scissors'){
if (label == 'rock'){
avatar_score = avatar_score + 1;
mode = 10;
}
else if (label == 'paper'){
opponent_score = opponent_score + 1;
mode = 10;
}
}
if (opponent_move_2 == label){
mode = 10;
}
pop();
}
function round_3(){
push();
imageMode(CENTER);
image(battlefield, width*0.5, height*0.5, width, height);
textAlign(CENTER);
textFont(unicornfont);
let s1 = "Round 3";
let s2 = "Opponent Score:";
let s3 = "Avatar Score:";
let s4 = opponent_score;
let s5 = avatar_score;
textSize(100);
fill(255);
text(s1,width*0.5, height*0.15);
textSize(30);
fill(255,0,0);
text(s2,width*0.15, height*0.2);
text(s4, width*0.15+90, height*0.2);
fill(0,0,255);
text(s3, width*0.8, height*0.2);
text(s5, width*0.8+80, height*0.2);
image(countdown_3, width*0.5, height*0.5, width*0.2, height*0.2);
image(countdown_2, width*0.5, height*0.5, width*0.2, height*0.2);
image(countdown_1, width*0.5, height*0.5, width*0.2, height*0.2);
if(opponent_move_3 == 'rock'){
if (label == 'scissors'){
opponent_score = opponent_score + 1;
}
else if (label == 'paper'){
avatar_score = avatar_score + 1;
}
}
if(opponent_move_3 == 'paper'){
if (label == 'scissors'){
avatar_score = avatar_score + 1;
}
else if (label == 'rock'){
opponent_score = opponent_score + 1;
}
}
if(opponent_move_3 == 'scissors'){
if (label == 'rock'){
avatar_score = avatar_score + 1;
}
else if (label == 'paper'){
opponent_score = opponent_score + 1;
}
}
if (opponent_move_3 == label){
mode = 11;
}
pop();
}