xxxxxxxxxx
// Gold Miner Game: https://www.youtube.com/watch?v=-w_PfZERd7Q
// imagee1: https://www.videvo.net/stock-video-footage/gold-mine/?page=3
// imagee2: https://im-mining.com/2017/07/03/barrick-shandong-complete-formation-joint-venture-veladero-mine/
// MINER with HOOK on HORIZON. GOLD of different sizes underground. SCORE and TIMER.
// HOOK rotates underneath MINER. When MINER clicks SPACE, HOOK lengthens until it reaches GOLD or the border, and then returns.
// GOLD has 25/50/100 size. MINER need SCORE to win with TIMER as reference.
var playingg = false; // playing GAME or not
var timerr = 0; // TIMER
var scoree = 0; // SCORE
var winn = 5; // SCORE needed to win
var goldd = []; // array to hold all GOLD
var amountt = 10; // amount of GOLD
var sizee = [25, 50, 100]; // size of GOLD
var anglee = 0; // ANGLE of the rotation
var plusanglee = 0.025; // increasing amount of ANGLE of the rotation
var lengthh = 100; // length of ROPE
var pluslengthh = 5; // increasing amount of the length of ROPE
var changelengthh = 0; // lengthening ROPE or not
function preload ()
{
imagee1 = loadImage('Gold1.jpg');
imagee2 = loadImage('Gold2.jpg');
soundd = loadSound('Gold.wav');
}
function setup()
{
createCanvas(windowWidth, windowHeight);
textFont('Georgia');
rectMode(CENTER);
ellipseMode(CENTER);
for(let i=0; i<amountt; i++)
{
goldd[i] = new GOLD(random(0, windowWidth), random(200, windowHeight), random(sizee));
}
}
class GOLD
{
constructor(xx, yy, dd) // run "new GOLD" each time and create a new gold with the following functions
// set some properties:
{
this.xx = xx;
this.yy = yy;
this.dd = dd;
this.rr = 255;
this.gg = random(175,255);
this.bb = 0;
}
// add some methods:
draww()
{
fill(this.rr, this.gg, this.bb);
circle(this.xx,this.yy,this.dd);
}
hitt(x, y) // detect collision
{
if(dist(x, y, this.xx, this.yy)<this.dd/2)
{
return(1);
}
else
{
return(0);
}
}
}
function draw()
{
// Before:
if(!playingg)
{
background(imagee1);
textAlign(CENTER);
textSize(50);
fill(255);
text('In the game, press SPACE to start, get ' + winn + ' GOLD to win.', windowWidth/2, windowHeight/2-100);
text('Reach your goal as fast as you can.', windowWidth/2, windowHeight/2)
text('Right now, press 1 to start.', windowWidth/2, windowHeight/2+100);
}
// Game:
if(playingg)
{
background(imagee2);
textAlign(LEFT);
textSize(25);
timerr = int(millis()/1000); // TIMER
text('Time: ' + timerr + ' sec', 60, 40); // TIMER
scoree = amountt-goldd.length; // SCORE
text('Score: ' + scoree + ' / ' + winn, 60, 80); // SCORE
line(0, 100, windowWidth, 100); // HORIZON
square(windowWidth/2, 75, 50); // MINER
for(let i=0; i<goldd.length; i++)
{
goldd[i].draww();
}
fill(0); // color of MINER and HOOK
linexx = windowWidth/2 + lengthh*cos(anglee);
lineyy = 75 + lengthh*sin(anglee);
line(windowWidth/2, 75, linexx, lineyy); // ROPE
circle(linexx, lineyy, 25); // HOOK
if(anglee < 0) plusanglee = -plusanglee;
if(anglee > 3) plusanglee = -plusanglee;
anglee = anglee + plusanglee; // change angle
if(changelengthh===1) lengthh = lengthh + pluslengthh; // lengthen ROPE
for(let i=goldd.length-1; i>=0; i--)
{
if(goldd[i].hitt(linexx, lineyy)===1) // detect collision
{
goldd.splice(i, 1); // delete GOLD
returnn(); // reach GOLD and return
soundd.play();
}
}
if(lengthh>1000) misss(); // miss GOLD and return
}
// After:
if(amountt-goldd.length>=winn)
{
playingg = false;
background(imagee1);
textAlign(CENTER);
textSize(50);
fill(255);
text('You win!', windowWidth/2, windowHeight/2-100);
text('You spent ' + timerr + ' seconds to win ' + winn + ' GOLD!', windowWidth/2, windowHeight/2)
text('Click REFRESH to play again.', windowWidth/2, windowHeight/2+100);
}
}
function keyPressed()
{
if(key===' ') startt(); // start ROPE and HOOK
if(key==='1') playingg = 1; // start GAME
}
function startt()
{
plusanglee = 0;
changelengthh = 1;
}
function returnn()
{
plusanglee = 0.03;
changelengthh = 0;
lengthh = 100; // shorten ROPE
}
function misss()
{
plusanglee = 0.03;
changelengthh = 0;
lengthh = 100; // shorten ROPE
}