xxxxxxxxxx
270
let emojiPlay = [];
let speedX
let speedY
let XPos
let YPos
let result
let red = 0
let green = 255
let blue = 0
let color = 0
let diameter = 20
let barWidth = 200
let score = 0
let buttonW = 70
let buttonH = 30
let buttonColor = 0
let backgroundColor = 0
let startW = 260
let startH = 70
let startA = 0
let value = 0
function setup() {
rectMode(CENTER)
createCanvas(600, 600);
fill(red, green, blue);
textSize(15)
speedX = random(2, 5)
speedY = random(5, 6)
XPos = random(50, 550)
YPos = random(0, 50)
for (let i = 0; i < 15; i++) {
emojiPlay.push(new emojiPos());
}
}
function draw() {
background(0, 0, 0, 80)
strokeWeight(0);
if (value == 1) {
scorePrint(35,45);
bar(barWidth);
ball(red,green,blue);
bouncing();
bouncingEffect();
changeLevel(random(0.6,0.9),random(1,1.3));
finalResults(5,9,11,12);
button(0.75)
} else {
startPage(0,0,255,0.75)
}
function scorePrint(x,y) {
push()
fill(255)
text('SCORE : ' + score, x, y);
pop()
}
function bouncingEffect() {
push()
if (YPos > 545 - diameter / 2 && YPos < 565 - diameter && mouseX - barWidth < XPos && XPos < mouseX + barWidth) {
fill(color, color, color)
rect(mouseX, 560, 2 * barWidth - 20, 10);
fill(color, color, color, 0);
strokeWeight(1);
stroke(255);
rect(mouseX + 5, 545, 2 * barWidth + 10, 10);
ellipse(XPos, YPos + 10, diameter + 20, diameter + 20);
ellipse(XPos - 10, YPos - 10, diameter + 10, diameter + 10);
ellipse(XPos + 15, YPos - 25, diameter - 15, diameter - 15);
}
pop()
}
function bar(x) {
push()
fill(color, color, color)
strokeWeight(1);
stroke(255)
rect(mouseX, 550, 2 * x, 10)
pop()
}
function ball(x,y,z) {
fill(x, y, z);
ellipse(XPos, YPos, diameter, diameter)
XPos = XPos + speedX
YPos = YPos + speedY
}
function bouncing() {
if (XPos > width - diameter / 2 || XPos < diameter / 2) {
speedX = -(speedX)
}
if (YPos > 550 - diameter / 2 && YPos < 565 - diameter && mouseX - barWidth < XPos && XPos < mouseX + barWidth || YPos < diameter / 2) {
speedY = -(speedY)
}
}
function changeLevel(xLevel,yLevel) {
if (YPos > 550 - diameter / 2 && YPos < 565 - diameter && mouseX - barWidth < XPos && XPos < mouseX + barWidth) {
score++
barWidth = barWidth - 15
fill(red, green, blue);
red = red + 45
green = green - 45
color = 255
if (speedY < 0) {
speedY = speedY - yLevel
} else {
speedY = speedY + yLevel
}
if (speedX < 0) {
speedX = speedX - xLevel
} else {
speedX = speedX + xLevel
}
} else {
color = 0
}
}
}
function button(x) {
push()
strokeWeight(x)
stroke(255)
fill(0, 100, buttonColor, buttonColor)
rect(530, 45, buttonW, buttonH)
if (mouseX > 495 && mouseX < 565 && mouseY > 30 && mouseY < 60) {
buttonW = 78, buttonH = 35, buttonColor = 255
} else {
buttonW = 70, buttonH = 30, buttonColor = 0
}
pop()
push()
fill(255)
text('Restart', 505, 50);
pop()
}
function endPage() {
push()
background(0, 0, 255)
fill(255)
textSize(25)
textAlign(CENTER);
text(result, width / 2, height / 2 - 60);
textSize(110)
text(score, width / 2, height / 2 + 60);
pop()
}
function finalResults(a,b,c,d) {
if (score <= a) {
result = 'Your Score'
sticker = '💩'
}
if (score > a && score <= b) {
result = 'Not bad, try again'
sticker = '😌'
}
if (score > b && score <= c) {
result = 'Amazing !'
sticker = '👽'
}
if (score == d) {
result = 'YOU WIN !!!'
sticker = '🎉'
}
if (YPos > 900 || score == d) {
endPage();
for (let i = 0; i < emojiPlay.length; i++) {
emojiPlay[i].display();
}
}
if (YPos > 900 || score == d) {
backgroundColor = backgroundColor + 20
} else {
backgroundColor = 0
}
}
function startPage(r,g,b,x) {
push()
fill(255)
strokeWeight(x)
stroke(255)
fill(r, g, b, startA)
rect(width / 2, height / 2, startW, startH)
if (mouseX > width / 2 - 130 && mouseX < width / 2 + 130 && mouseY > height / 2 - 35 && mouseY < height / 2 + 35) {
startW = 280, startH = 80, startA = startA + 10
} else {
startW = 260, startH = 70, startA = 0
}
pop()
push()
fill(255)
textSize(29)
textAlign(CENTER);
text('Start ☄️ Game', width / 2, height / 2 + 10)
pop()
}
function mouseClicked() {
if (mouseX > 495 && mouseX < 565 && mouseY > 30 && mouseY < 60) {
red = 0
green = 255
blue = 0
color = 0
diameter = 20
barWidth = 200
score = 0
counter = 0
speedX = random(2, 5)
speedY = random(5, 6)
XPos = random(50, 550)
YPos = random(0, 50)
buttonColor = 0
}
}
function mouseReleased() {
if (mouseX > width / 2 - 130 && mouseX < width / 2 + 130 && mouseY > height / 2 - 35 && mouseY < height / 2 + 35) {
value = 1
}
}
class emojiPos {
constructor() {
this.x = random(width);
this.y = random(height);
this.diameter = random(10, 30);
}
display() {
push()
textSize(this.diameter * 2)
fill(0, 0, 0, backgroundColor)
text(sticker, this.x, this.y)
pop()
if (this.y > 800) {
this.y = this.y - 800
}
this.y = this.y + 3
}
}