xxxxxxxxxx
67
function draw() {
background(220);
// Fade-in effect for the circle
if (circleAlpha < 255) {
circleAlpha += fadeSpeed; // Increase the alpha of the circle gradually
}
fill(0, 0, 0, circleAlpha); // Set fill with the current alpha value
noStroke(); // Remove outline from the circle
circle(xdistance, ydistance, 50); // Draw the circle
// Move the circle toward (0, 0)
if (xdistance > 0) {
xdistance -= moveSpeed; // Move the circle left
}
if (ydistance > 0) {
ydistance -= moveSpeed; // Move the circle upward
}
// Now draw the images stored in combArr with a gradual fade-in
for (let i = 0; i < combArr.length; i++) {
let arrow = combArr[i];
// Increase alpha gradually to fade in
if (arrow.alpha < 255) {
arrow.alpha += fadeSpeed;
}
// Move arrows toward (0, 0)
if (arrow.x > 0) {
arrow.x -= moveSpeed; // Move arrow left
}
if (arrow.y > 0) {
arrow.y -= moveSpeed; // Move arrow upward
}
// Apply the alpha value for fade-in effect
tint(255, arrow.alpha);
image(arrow.img, arrow.x, arrow.y, 30, 30); // Draw the image at the stored position
}
// Check if UP_ARROW is pressed and enough time has passed since last removal
if (keyIsDown(UP_ARROW) && combArr.length > 0 && combArr[0].img === greenUP) {
let currentTime = millis(); // Get the current time in milliseconds
if (currentTime - lastRemoveTime > delayTime) { // Check if the delay has passed
combArr.shift(); // Remove the first element
realignImages(); // Realign the remaining images
lastRemoveTime = currentTime; // Update the last removal time
}
}
}
// Function to realign the images after one is removed
function realignImages() {
// Reset arrowXdistance to center the remaining arrows
arrowXdistance = xdistance - (scaleArrow * combArr.length / 2); // Centering remaining arrows
// Update positions of remaining images
for (let i = 0; i < combArr.length; i++) {
combArr[i].x = arrowXdistance; // Set new x position
arrowXdistance += scaleArrow; // Move to the next position
}
}