xxxxxxxxxx
170
let fruits = [];
let bombs = [];
let powerUps = []; // Array for power-ups
let slices = [];
let splatters = [];
let bombImg, pineappleImg, watermelonImg, bananaImg, coconutImg, orangeImg, bgImg, basketImg;
let customFont;
let score = 0;
let gameTime = 30;
let gameEnded = false;
let spawnInterval = 20;
let lastSpawnTime = 0;
let maxFruits = 2;
let bombProbability = 0.2;
let powerUpProbability = 0.1; // Probability for power-ups
let gravity = 0.1;
let basketX, basketY;
let basketWidth = 80;
let basketSpeed = 5;
let scoreMultiplier = 1; // For combo system
let comboTimer = 0; // Track combo time
let comboDuration = 60; // 60 frames (1 second)
function preload() {
bombImg = loadImage('BOMB.png');
pineappleImg = loadImage('pineapple.png');
watermelonImg = loadImage('watermellon.png');
bananaImg = loadImage('banana.png');
coconutImg = loadImage('coconut.png');
orangeImg = loadImage('orange.png');
bgImg = loadImage('wood.jpg');
basketImg = loadImage('basket.png'); // Image for the basket (make sure you have this image)
customFont = loadFont('hHachimaki.ttf');
}
function setup() {
createCanvas(500, 600);
textFont(customFont);
basketX = width / 2 - basketWidth / 2;
basketY = height - 50;
// Countdown timer
setInterval(() => {
if (gameTime > 0) {
gameTime--;
} else {
gameEnded = true;
}
}, 1000);
}
function draw() {
background(bgImg);
if (gameEnded) {
noLoop();
displayGameOver();
return;
}
// Gradually increase the number of fruits and bombs
if (frameCount % 60 === 0) {
if (maxFruits < 12) maxFruits++;
if (bombProbability < 0.3) bombProbability += 0.01;
}
// Spawn fruits, bombs, and power-ups
if (frameCount - lastSpawnTime > spawnInterval && fruits.length + bombs.length < maxFruits) {
let rand = random();
if (rand < bombProbability && bombs.length < 3) {
bombs.push(new Bomb(random(50, 350), -50, random(1, 3), random(-2, 2))); // Falling bombs from top
} else if (rand < bombProbability + powerUpProbability) {
// powerUps.push(new PowerUp(random(50, 350), -50, random(1, 3), random(-2, 2))); // Falling power-ups from top
} else {
fruits.push(new Fruit(random(50, 350), -50, random(1, 3), random(-2, 2))); // Falling fruits from top
}
lastSpawnTime = frameCount;
}
// Update and display fruits, bombs, and power-ups
for (let i = fruits.length - 1; i >= 0; i--) {
fruits[i].update();
fruits[i].display();
}
for (let i = bombs.length - 1; i >= 0; i--) {
bombs[i].update();
bombs[i].display();
if (bombs[i].missed()) bombs.splice(i, 1);
}
for (let i = powerUps.length - 1; i >= 0; i--) {
powerUps[i].update();
powerUps[i].display();
if (powerUps[i].missed()) powerUps.splice(i, 1);
}
// Basket movement
displayBasket();
handleBasketMovement();
// Check collisions with fruits and power-ups
checkCollisions();
// Juice Splatter
for (let i = splatters.length - 1; i >= 0; i--) {
splatters[i].update();
splatters[i].display();
if (splatters[i].finished) splatters.splice(i, 1);
}
// Display score, timer, and multiplier
displayScoreAndTime();
}
// Basket display and movement
function displayBasket() {
image(basketImg, basketX, basketY, basketWidth, 50);
}
function handleBasketMovement() {
if (keyIsDown(LEFT_ARROW) && basketX > 0) {
basketX -= basketSpeed;
} else if (keyIsDown(RIGHT_ARROW) && basketX < width - basketWidth) {
basketX += basketSpeed;
}
}
// Check for collisions between the basket and fruits/power-ups
function checkCollisions() {
// Check fruits
for (let i = fruits.length - 1; i >= 0; i--) {
if (fruits[i].y > basketY - 30 && fruits[i].x > basketX && fruits[i].x < basketX + basketWidth) {
score += 1 * scoreMultiplier; // Increase score based on multiplier
comboTimer = comboDuration; // Reset combo timer
splatters.push(new FruitSplatter(fruits[i].x, fruits[i].y, fruits[i].radius, fruits[i].type));
fruits.splice(i, 1); // Remove the fruit from the array
}
}
// Check power-ups
for (let i = powerUps.length - 1; i >= 0; i--) {
if (powerUps[i].y > basketY - 30 && powerUps[i].x > basketX && powerUps[i].x < basketX + basketWidth) {
// Activate power-up
powerUps[i].activate();
powerUps.splice(i, 1);
}
}
// Check if a bomb hits the basket (game over)
for (let i = bombs.length - 1; i >= 0; i--) {
if (bombs[i].y > basketY - 30 && bombs[i].x > basketX && bombs[i].x < basketX + basketWidth) {
gameEnded = true; // End the game if a bomb hits the basket
}
}
// Combo system
if (comboTimer > 0) {
comboTimer--;
scoreMultiplier = 2; // Double score if within combo time
} else {
scoreMultiplier = 1; // Reset multiplier
}
}
// Display the score and remaining time
function displayScoreAndTime() {
textSize(24); // Set the font size for the score and timer
fill(255, 0, 0); // Set the text color to red
textAlign(LEFT, TOP); // Align the score text to the top
}