/*/////////////////
Life is Hard
--Kai Banks
Choose what your life is like.
Use the arrow keys to move around your chosen life.
(P.S. calm things aren't usually very interesting)
/*//////////////////
Rain[] rains = new Rain[50];
BackRain[] backRains = new BackRain[250];
Grass[] grassBlade = new Grass[100];
Light[] lights = new Light[60];
Star[] stars = new Star[150];
Cloud[] clouds = new Cloud[10];
Fae fae;
Girl girl;
float lifeStatus = 0;
boolean hard = false;
boolean odd = false;
boolean Peaceful = false;
boolean goLeft = false;
boolean goRight = false;
boolean goDown = false;
boolean goUp = false;
void setup() {
size(400, 400);
//create an instance of all classes
for (int i = 0; i < 50; i++) {
rains[i] = new Rain();
}
for (int i = 0; i < 250; i++) {
backRains[i] = new BackRain();
}
for (int i = 0; i < 100; i++) {
grassBlade[i] = new Grass();
}
fae = new Fae();
girl = new Girl();
for (int i = 0; i < 60; i++) {
lights[i] = new Light();
}
for (int i = 0; i < 150; i++) {
stars[i] = new Star();
}
for (int i = 0; i < 10; i++) {
clouds[i] = new Cloud();
}
}
void draw() {
background(0, 0, 0);
textAlign(CENTER);
fill(#ffffff);
// text of opening screen
text("Life is...", width/2, 20);
text(" Hard Odd Peaceful ", width/2, 40);
//separate player choices into different events
if (lifeStatus == 1) {
hard = true;
lifeIsHard();
} else if (lifeStatus == 2) {
odd = true;
lifeIsOdd();
} else if (lifeStatus == 3) {
Peaceful = true;
lifeIsPeaceful();
} else if (lifeStatus == 0) {
noStroke();
fill(120, 120, 120, 100);
rect(90, 25, 65, 20, 10);
fill(120, 120, 120, 100);
rect(167, 25, 65, 20, 10);
fill(120, 120, 120, 100);
rect(244, 25, 65, 20, 10);
}
}
//create bounding box for starting screen's text
void mouseClicked() {
if (lifeStatus == 0 && mouseX > 90 && mouseX < 155 && mouseY > 25 && mouseY < 50) {
lifeStatus = 1;
} else if (lifeStatus == 0 && mouseX > 167 && mouseX < 232 && mouseY > 25 && mouseY < 50) {
lifeStatus = 2;
} else if (lifeStatus == 0 && mouseX > 244 && mouseX < 309 && mouseY > 25 && mouseY < 50) {
lifeStatus = 3;
}
}
void lifeIsHard() {
//sky
background(0, 35, 70);
noStroke();
fill(0, 0, 0);
rect(0, 0, width, 50);
fill(0, 5, 10);
rect(0, 50, width, 50);
fill(0, 10, 20);
rect(0, 100, width, 50);
fill(0, 15, 30);
rect(0, 150, width, 50);
fill(0, 20, 40);
rect(0, 200, width, 50);
fill(0, 25, 50);
rect(0, 250, width, 50);
fill(0, 30, 60);
rect(0, 300, width, 50);
//background rain
for (int i = 0; i < 250;
i++) {
backRains[i].display();
backRains[i].update();
}
//grass
fill(#000000);
rect(0, height-20, width, height);
if (lifeStatus != 0) {
for (int i = 0; i < 100; i++) {
grassBlade[i].display();
}
}
//display and move character
girl.display();
girl.move();
//foreground rain
for (int i = 0; i < 50; i++) {
rains[i].display();
rains[i].move();
}
}
void lifeIsOdd() {
//sky
background(150, 240, 180);
noStroke();
fill(0, 100, 120);
rect(0, 0, width, 50);
fill(20, 115, 125);
rect(0, 50, width, 50);
fill(40, 130, 130);
rect(0, 100, width, 50);
fill(60, 150, 140);
rect(0, 150, width, 50);
fill(80, 175, 150);
rect(0, 200, width, 50);
fill(100, 200, 160);
rect(0, 250, width, 50);
fill(120, 220, 170);
rect(0, 300, width, 50);
//stars
for (int i = 0; i < 150; i++) {
stars[i].display();
}
//back mushrooms
fill(95, 190, 155);
ellipse(330, 370, 40, 100);
ellipse(330, 330, 80, 45);
fill(75, 170, 145);
ellipse(200, 330, 60, 250);
ellipse(200, 230, 110, 50);
fill(50, 140, 139);
ellipse(35, 330, 80, 260);
ellipse(35, 200, 170, 70);
fill(40, 140, 130);
ellipse(155, 390, 90, 260);
ellipse(155, 290, 200, 90);
//NPC lights
for (int i = 0; i < 60; i++) {
lights[i].display();
lights[i].update();
}
//grass
if (lifeStatus != 0) {
for (int i = 0; i < 100; i++) {
grassBlade[i].display();
}
}
fill(40, 130, 130);
rect(0, height-20, width, height);
//front mushroom
fill(25, 120, 130);
ellipse(410, 350, 150, 450);
ellipse(410, 160, 230, 100);
//display / move player
fae.display();
fae.move();
}
void lifeIsPeaceful() {
//sky
background(255, 255, 220);
noStroke();
fill(255, 145, 80);
rect(0, 0, width, 50);
fill(255, 165, 100);
rect(0, 50, width, 50);
fill(255, 185, 120);
rect(0, 100, width, 50);
fill(255, 205, 140);
rect(0, 150, width, 50);
fill(255, 225, 160);
rect(0, 200, width, 50);
fill(255, 245, 180);
rect(0, 250, width, 50);
fill(255, 255, 200);
rect(0, 300, width, 50);
//sun
fill(255, 255, 200);
ellipse(50, 50, 50, 50);
fill(255, 255, 200, 100);
//sun's pulsing light
ellipse(50, 50, 60 + sin(frameCount*0.07) *7, 60 + sin(frameCount*0.07) *7 );
fill(255, 255, 200, 50);
ellipse(50, 50, 70 + sin(frameCount*0.07) *9, 70 + sin(frameCount*0.07) *9 );
//display/ move character
girl.display();
girl.move();
//grass
if (lifeStatus != 0) {
for (int i = 0; i < 100; i++) {
grassBlade[i].display();
}
}
fill(255, 165, 100);
rect(0, height-20, width, height);
//display 10 clouds and move them
for (int i = 0; i < 10; i++) {
clouds[i].display();
clouds[i].update();
}
}
//set player movement to arrow keys
void keyPressed() {
if (keyCode == UP) {
goUp = true;
}
if (keyCode == DOWN) {
goDown = true;
}
if (keyCode == LEFT) {
goLeft = true;
}
if (keyCode == RIGHT) {
goRight = true;
}
}
void keyReleased() {
if (keyCode == UP) {
goUp = false;
}
if (keyCode == DOWN) {
goDown = false;
}
if (keyCode == LEFT) {
goLeft = false;
}
if (keyCode == RIGHT) {
goRight = false;
}
}class BackRain {
float xpos;
float ypos;
color c;
float fade = random(30, 150);
float speed = random (9, 10);
//start rain at random coordinates above the top of the screen
BackRain() {
c = color(0);
xpos = random(width);
ypos = 0-(random(height));
}
void display() {
//draw rain
rectMode(CORNER);
noStroke();
fill(#ffffff, fade);
rect(xpos, ypos, 1, 2);
fill(#ffffff, 30);
rect(xpos, ypos-3, 2, 4);
//if rain reaches the bottom of the screen, begin again at top
if (ypos > height+10) {
ypos = 0-(random(height));
}
}
//accelerate rain towards bottom of screen
void update() {
ypos = (ypos + speed)*1.005;
}
}class Cloud {
//start clouds at random position off-screen near top of sky
PVector cloudPosition = new PVector(random (-1000, -50), random(150));
PVector cloudSize = new PVector(random(60, 100), random(20, 60));
float move = random(0.3, 0.8);
Cloud() {
}
//draw the cloud
void display() {
fill(#ffffff, 70);
rect(cloudPosition.x, cloudPosition.y, cloudSize.x, cloudSize.y, 30);
}
//move cloud to the right; if it moves offscreen move it back to the left
void update() {
cloudPosition.x += move;
if (cloudPosition.x > width + 200) {
cloudPosition.x= random(-400, -200);
}
}
}class Fae {
PVector faeSpeed = new PVector(0, 0);
PVector faePosition = new PVector(width/2, height/2);
Fae() {
}
//draw the playable character
void display() {
fill(125, 255, 255);
ellipse(faePosition.x, faePosition.y, 15, 15);
//pulsing light around character
fill(255, 255, 255);
ellipse(faePosition.x, faePosition.y, 5 + sin(frameCount*0.07) *4, 5 + sin(frameCount*0.07) *4 );
fill(105, 255, 255, 100);
ellipse(faePosition.x, faePosition.y, 20 + sin(frameCount*0.07) *4, 20 + sin(frameCount*0.07) *4 );
}
//move character with arrow keys. deaccelerate when not being moved until stopped.
void move() {
if (goDown == true && faePosition.y < height-15) {
faeSpeed.y = 1.5;
} else if (goDown == false && faeSpeed.y > 0) {
faeSpeed.y -= 0.05;
} else if (goDown == true && faePosition.y > height-15) {
faeSpeed.y = 0;
}
faePosition.y += faeSpeed.y;
if (goUp == true && faePosition.y > 0) {
faeSpeed.y = -1.5;
} else if (goUp == false && faeSpeed.y < 0) {
faeSpeed.y += 0.05;
} else if (goUp == true && faePosition.y < 0) {
faeSpeed.y = 0;
}
if (goLeft == true && faePosition.x > 0) {
faeSpeed.x = -1.5;
} else if (goLeft == false && faeSpeed.x < 0) {
faeSpeed.x += 0.05;
} else if (goLeft == true && faePosition.x < 0) {
faeSpeed.x = 0;
}
faePosition.x += faeSpeed.x;
if (goRight == true && faePosition.x < (width)) {
faeSpeed.x = 1.5;
} else if (goRight == false && faeSpeed.x > 0) {
faeSpeed.x -= 0.05;
} else if (goRight == true && faePosition.x > width) {
faeSpeed.x = 0;
}
faePosition.x += faeSpeed.x;
faePosition.y += faeSpeed.y;
}
}class Girl {
float x1 = 200;
float x2;
float x3;
float y1 = 340;
float y2 = y1+20;
float y3 = y1+30;
boolean flip = false;
float xSpeed;
Girl() {
}
//display girl for Life is Hard // Peaceful, change color accordingly
void display() {
if (lifeStatus == 1) {
fill(#000000);
} else if (lifeStatus == 3) {
fill(235, 125, 60);
}
triangle(x1, y1, x2, y2, x3, y3);
//if moving to the right, face right-- if moving to the left, face left
if (flip == false) {
x2 = x1-10;
x3 = x1 +15;
} else if (flip == true) {
x2 = x1 + 10;
x3 = x1 -15;
}
triangle(x1-3, y1+20, x1+5, y1+20, x1, y1+50);
rectMode(CENTER);
rect(x1, y1, 7, 7);
rectMode(CORNER);
}
//flip character when pressing arrow keys and move left // right
void move() {
if (goLeft == true && x1 > -5) {
flip = true;
x1--;
} else if (goRight == true && x1 < width +5) {
flip = false;
x1++;
}
}
}class Grass {
float x1;
float y1;
float x2;
float x3;
float y2;
//randomize grass triangles
Grass() {
x1 = random(width);
y1 = height-20;
x2 = x1+5;
x3 = random(x1, x2);
y2 = y1-random(5, 15);
}
//change color according to life is Hard/ Odd / Peaceful
void display() {
if (lifeStatus == 1) {
fill(0, 0, 0);
} else if (lifeStatus == 2) {
fill(40, 130, 130);
} else if (lifeStatus == 3) {
fill(255, 165, 100);
}
triangle(x1, y1, x2, y1, x3, y2);
}
}class Light {
//randomize lights' locations
PVector lightsPosition = new PVector(random(width), random(height-400, height-30));
float pulse = random(0.05, 0.1);
float move = random(-0.3, 0.3);
float fade = lightsPosition.y-120 + random(-100, 50);
Light() {
}
//draw small, pulsing lights
void display() {
fill(125, 255, 255, fade);
ellipse(lightsPosition.x, lightsPosition.y, 5, 5);
fill(255, 255, 255, fade);
ellipse(lightsPosition.x, lightsPosition.y, 5 + sin(frameCount*pulse) *3, 5 + sin(frameCount*pulse) *3 );
fill(105, 255, 255, fade - 50);
ellipse(lightsPosition.x, lightsPosition.y, 9 + sin(frameCount*pulse) *3, 9 + sin(frameCount*pulse) *3 );
}
//move lights at random speeds in random directions when the arrow keys are pressed
void update() {
if (goUp == true) {
lightsPosition.x += move/2;
}
if (goDown == true) {
lightsPosition.x -= move/2;
}
if (goRight == true) {
lightsPosition.y -= move;
}
if (goLeft == true) {
lightsPosition.y += move;
}
}
}class Rain {
float xpos;
float ypos;
float fade = random(100, 155);
Rain() {
//start rain at random coordinates above the top of the screen
xpos = random(width);
ypos = 0-(random(height));
}
void display() {
//draw rain
noStroke();
fill(#ffffff, fade);
rect(xpos, ypos, 2, 4);
fill(#ffffff, 40);
rect(xpos, ypos-3, 2, 4);
//if rain reaches the bottom of the screen, begin again at top
if (ypos > height+10) {
ypos = 0-(random(height));
}
}
//accelerate rain towards bottom of screen
void move() {
ypos = (ypos + 9)*1.005;
}
}class Star {
float starSize = (random(3));
PVector starPosition = new PVector(random(width), random(height));
float fade = 300-(starPosition.y);
Star() {
}
void display() {
fill(#ffffff, fade);
rect(starPosition.x, starPosition.y, starSize, starSize);
}
}