xxxxxxxxxx
278
let emojiPlay = [];
let speedX
let speedY
let XPos
let YPos
let result
let sticker
let color = 0
let diameter = 20
let radius = 10
let barWidth = 200
let score = 0
let buttonW = 70
let buttonH = 30
let buttonColor = 0
let startW = 260
let startH = 70
let startA = 0
let value = 0
let bg;
var winningSound;
var LosingSound;
function preload()
{
winningSound = loadSound("[YT2mp3.info] - Victory Sound Effect (320kbps).mp3");
LosingSound = loadSound("[YT2mp3.info] - The Price is Right Losing Horn - Gaming Sound Effect (HD) (320kbps).mp3");
bg = loadImage("https://raw.githubusercontent.com/Rabbid76/graphics-snippets/master/resource/texture/background.jpg");
}
function setup() {
rectMode(CENTER)
createCanvas(600, 600);
fill(red, 255, blue);
textSize(15)
speedX = random(2, 5)
speedY = random(5, 6)
XPos = random(50, 550)
YPos = 10
let i=15;
while(i--){
emojiPlay.push(new emojiPos());
}
}
function draw() {
background(bg)
strokeWeight(0);
if (value == 1) {
scorePrint(380,45);
bar(barWidth);
ball( 0 , 255 , 0);
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 - radius && 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 += speedX
YPos += speedY
}
function bouncing() {
if (XPos > width - radius || XPos < radius)
{
speedX *= -1
}
if (YPos > 550 - radius && YPos < 565 - diameter && mouseX - barWidth < XPos && XPos < mouseX + barWidth || YPos < radius)
{
speedY *= -1
}
}
function changeLevel(xLevel,yLevel) {
if (YPos > 550 - radius && 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-= yLevel
}
else
{
speedY+= yLevel
}
if (speedX < 0)
{
speedX-= xLevel
}
else
{
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 end() {
push()
background(20, 20, 20)
fill(255)
textSize(25)
textAlign(CENTER);
text(result, width/2, height/2 - 60);
textSize(110)
text(score, width/2, height/2 + 60);
if(score<12 ) LosingSound.play();
pop()
}
function finalResults(a,b,c,d) {
if (score < d)
{
result = 'You lost. Your Score'
}
else if (score == d) {
winningSound.play();
result = 'CONGRATULATIONS! YOU WON :)'
sticker = '🎉'
}
if (YPos > 900 || score == d) {
end();
for (let i = 0; i < emojiPlay.length; i++) {
emojiPlay[i].display();
}
//startPage(0,0,255,0.75)
}
}
function startPage(r,g,b,x) {
push()
fill(255)
strokeWeight(x)
stroke(255)
fill(20, 20, 20, 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()
textSize(59)
textAlign(CENTER);
text('Sky Bounce Game', width/2, height/3 + 10)
fill(255)
textSize(29)
textAlign(CENTER);
text('Start Game', width/2, height/2 + 10)
textSize(15);
text('Instructions: move the platform using your touchpad to allow the ball to bounce on it', width/2, height/3 + 180)
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
XPos = random(50, 550)
YPos = random(0, 50)
speedX = random(2, 5)
speedY = random(5, 6)
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)
text(sticker, this.x, this.y, 0)
pop()
if (this.y > 800) {
this.y -= 800
}
this.y += 3
}
}