//player position
int playerX = 375;
int playerY = 650;
int playerD = 2;
int pTriX = 375;
int pTriY = 650;
//Boulders
int numBlocks = 10;
int bSize = 75;
float[] x = new float[numBlocks];
float[] y = new float[numBlocks];
//Background Change
float BG = 200;
void setup()
{
size (750, 750);
noStroke();
for (int i = 0; i < numBlocks; i++) {
x[i] = (int)random(width);
y[i] = (int)random(height)-height-bSize/2;
}
}
void draw()
{
//Aesthetics
background(BG, 50, 50);
textSize(24);
text("Tap a Key!", 325, 300);
text("Dodge the Boulders!", 270, 330);
//Player
noStroke();
fill(0);
ellipse(playerX, playerY, 75, 75);
fill(255);
ellipse(playerX, playerY, 50, 50 );
//Player movement
if (playerD==2)
{
playerX-=7;
if (playerX <=width-width)
{
playerD=1;
}
}
if (playerD==3)
{
playerX+=7;
if (playerX >=width)
{
playerD=4;
}
}
//
for (int i = 0; i < numBlocks; i++) {
if (y[i] > height+bSize/2) {
x[i] = (int)random(width);
y[i] = (int)random(height)-height-bSize/2;
}
y[i]+=5;
fill(0);
ellipse(x[i], y[i], bSize, bSize);
//collision calculator
if (dist(x[i], y[i], playerX, playerY) <= 70)
{
exit();
}
}
}
//Move command
void keyPressed()
{
BG = random(0,255);
if (playerD==1||playerD==2)
{
playerD = 3;
} else if (playerD==3||playerD==4)
{
playerD = 2;
}
}