xxxxxxxxxx
123
/* Image Credit - Elena Gold*/
let tek, xPos, yPos;
let ellipseX, ellipseY, ellipseD;
let score;
const RANGE = 10;
let canEnter = false;
function preload() {
tek = loadImage("https://raw.githubusercontent.com/elenaleegold/hosting/main/tek.png");
}
function setup() {
createCanvas(600, 600);
xPos = 100;
yPos = 100;
score = 0;
ellipseX = 300;
ellipseY = 300;
ellipseD = 100;
//We set the image mode to center here because we want it to match the way the circle is draw (from the center out), so we can measure the distance away from it
imageMode(CENTER);
// setTimeout(
// text("YO", 425, 50)
// ),5000);
// test()
// console.log(test)
}
function showKeepTrying() {
// fill(random(255), random(255), random(255)) text("You're Home!", 200, 50);
// ), 5000);
/* Look mah! No name! */
setTimeout(function() {
fill(random(255), random(255), random(255))
text("You're Home!", 200, 50);
}, 1000);
// test()
// console.log(test)
}
function draw() {
background(0);
fill(255);
ellipse(ellipseX, ellipseY, ellipseD);
fill('white')
text(second(), 425, 50)
fill('black')
if (!canEnter) {
textSize(20);
fill('white')
textAlign(CENTER);
text("We can only enter home between Greece and Belgium!", width/2, 500);
}
if (dist(xPos, yPos, ellipseX, ellipseY) < (ellipseD / 2 + 10)) {
canEnter = false;
if (second() <= 30 || second() >= 32) {
xPos = random(width);
yPost = random(height);
fill(random(255), random(255), random(255))
// text("KEEP TRYING!", 200, 50);
} else {
if (dist(xPos, yPos, ellipseX, ellipseY) < ellipseD / 2) {
canEnter = true;
textSize(25);
fill(random(255), random(255), random(255))
text("You're Home!", width / 2, 50);
}
}
}
image(tek, xPos, yPos);
//The charcter's movement system
if (keyIsDown(LEFT_ARROW) === true) {
xPos -= 5;
} else if (keyIsDown(RIGHT_ARROW) === true) {
xPos += 5;
} else if (keyIsDown(UP_ARROW) === true) {
yPos -= 5;
} else if (keyIsDown(DOWN_ARROW) === true) {
yPos += 5;
}
//This ensures that the character won't move off the screen
if (xPos > width) {
xPos = -1 * tek.width / 2;
} else if (xPos < -1 * tek.width) {
xPos = 600;
}
if (yPos > height) {
yPos = -1 * tek.width / 2;
} else if (yPos < -1 * tek.width) {
yPos = 600;
}
//This assesses whether the distance between the character and the circle is less than the diameter of the ellipse (collision detection). If it is, it prints text to the screen
}