Torture With My Baby

Idea by Felix Nie, code by Felix Nie with help from Victor Veytsman, reprogrammed from Khan Academy Processing JS to Javascript by Victor Veytsman

You must babysit the torturer's baby while keeping inside the torture ring. Make sure the baby doesn't bite your ankles!

Difficulty:

Felix's Original Code: (Khan Academy Processing JS)

var state = "game";
var circleSIZE = 400;
var player = 6;
var playerX = 200;
var playerY = 200;
var aiX = 250;
var aiY = 200;
var ai = 6;
var start = millis();
var difficulty = 10;
difficulty = difficulty/10;
var speed = difficulty;
//^Put variables up here
textSize(50);
//^everything above here is the enclosing circle
draw = function() {
    if (state === "menu") {
        background(0);
        textAlign(CENTER, CENTER);
        fill(255);
        //text(message, x, y) where x and y are the center of the text
        text("Torture with my baby", 10, 50, 400, 150);
        rect(160,250,100,100);
        fill(0);
        text("▶", 214, 301);
        if (mouseIsPressed && mouseX >= 160 && mouseX <= 260 && mouseY >= 250 && mouseY <= 350) {
            start = millis();
            state = "game";
        }
    } else if (state === "game") {
        fill(0);
        background(0);
        stroke(255, 0, 0);
        strokeWeight(5);
        ellipse(200,200,circleSIZE,circleSIZE);
        //^everything above here is the enclosing circle
        fill(255, 145, 0);
        stroke(255, 145, 0);
        ellipse(aiX, aiY, ai, ai);
        fill(255,255,255);
        stroke(255, 255, 255);
        ellipse(playerX,playerY, player, player);
        circleSIZE = circleSIZE-speed;
        if ((sqrt(pow(playerX-200, 2) + pow(playerY-200, 2))) >= (circleSIZE/2)) {
        state = "menu";
    }
        if (circleSIZE <= 80) {
            speed = -speed;
        }

        if (circleSIZE >= 400) {
            speed = -speed;
        }
    if (aiY < playerY) {
        aiY += difficulty;
    }
    if (playerY < aiY) {
        aiY -= difficulty;
    }
    if (playerX > aiX) {
        aiX += difficulty;
    }
    if (playerX < aiX) {
        aiX -= difficulty;
    }
    if (playerX >= aiX-4 && playerX <= aiX+4 && playerY >= aiY-4 && playerY <= aiY+4) {
        state = "menu";
    }
    //((millis()-start)/1000).toFixed(2)
    textAlign(LEFT, TOP);
    text(((millis()-start)/1000).toFixed(2), 10, 0);
    }
};

    mouseMoved = function() {
        playerX = mouseX;
        playerY = mouseY;
    };