//SPOOKY FOREST ADVENTURE\\
//Created by Jiveen Liew\\
//Student Number: 991469860\\
//Defeat the spooky ghosts with your flashlight!\\
//VARIABLES//
float ghostX = random(5, 150);
float ghostY = random(0, 500);
float ghostX2 = random(150, 300);
float ghostY2 = random(10, 500);
float ghostX3 = random(300, 400);
float ghostY3 = random(15, 500);
float ghostX4 = random(300, 400);
float ghostY4 = random(20, 500);
float ghostRed = 255;
float ghostGreen =255;
float ghostBlue =255;
int moveX = 1;
int moveY = 30;
int armX = 23;
int armY = 33;
int ghostSizeX = 30;
int ghostSizeY =50;
int treeX = 24;
int treeY = 310;
int score=0;
void setup () {
size (400, 400);
frameRate(60);
}
void draw() {
//purple background//
background (28, 0, 23);
//rays//
drawRays(0, 295, 350);
drawRays(25, 220, 295);
drawRays(45, 148, 220);
drawRays(65, 74, 148);
drawRays(80, 0, 74);
//moon//
noStroke();
fill(250, 239, 182, 30);
ellipseMode(CENTER);
ellipse(326, 62, 90, 90);
fill(173, 167, 139);
ellipse(326, 62, 60, 60);
//trees//
for (int i = -5; i< 7; i++) {
drawTrees(treeX + (i * 60), treeY);
}
//stars//
drawStars(43, 37);
drawStars(112, 40);
drawStars(327, 20);
drawStars(55, 96);
drawStars(147, 150);
drawStars(285, 75);
drawStars(380, 146);
drawStars(200, 200);
drawStars(263, 133);
drawStars(192, 123);
drawStars(340, 222);
drawStars(17, 169);
drawStars(88, 179);
drawStars(197, 55);
drawStars(136, 92);
drawStars(53, 240);
//ghosts//
drawGhost1();
updateGhost1();
drawGhost2();
updateGhost2();
drawGhost3();
updateGhost3();
drawGhost4();
updateGhost4();
//flash//
drawLight (80);
drawLight (150);
//flashlight//
fill(10);
strokeWeight(2);
stroke(255, 214, 8);
quad(mouseX-15, mouseY+40, mouseX+10, mouseY+139, mouseX+30, mouseY+133, mouseX+15, mouseY+32);
//head
quad(mouseX-30, mouseY+30, mouseX-20, mouseY+42, mouseX+20, mouseY+31, mouseX+20, mouseY+15);
strokeWeight(3);
line(mouseX+9, mouseY+50, mouseX+12, mouseY+70);
//if light shines on ghost -> ghost disappears -> score appears//
if (ghostX<=mouseX+100 && ghostY >=mouseX-100 && ghostY<= mouseY+60 && ghostY >=mouseY-60
&&mousePressed) {
println("Spook Defeated:"+score++);
ghostX= -250;
ghostY=800;
}
if (ghostX2<=mouseX+100 && ghostY2 >=mouseX-100 && ghostY2<= mouseY+60 && ghostY2 >=mouseY-60
&&mousePressed) {
println("Spook Defeated:"+score++);
ghostX2=-250;
ghostY2=800;
}
if (ghostX3<=mouseX+100 && ghostY3 >=mouseX-100 && ghostY3<= mouseY+60 && ghostY3 >=mouseY-60
&&mousePressed) {
println("Spook Defeated:"+score++);
ghostX3=-250;
ghostY3=800;
}
if (ghostX4<=mouseX+100 && ghostY4 >=mouseX-100 && ghostY4<= mouseY+60 && ghostY4 >=mouseY-60
&&mousePressed) {
println("Spook Defeated:"+score++);
ghostX4=-250;
ghostY4=800;
}
//if certain number of ghosts defeated, ghosts change colour + message changes//
if (score ==30) {
println ("WOW YOU'VE KILLED SO MANY GHOST!");
ghostRed = random(0, 255);
ghostGreen = random(0, 255);
ghostBlue = random(0, 255);
}
if (score ==60) {
println ("DAMN THAT'S A LOT OF KILLING");
ghostRed = random(0, 255);
ghostGreen = random(0, 255);
ghostBlue = random(0, 255);
}
if (score ==80) {
println ("HMM, THAT'S A LOT OF SOULS YOU'RE DESTROYING...");
ghostRed = random(0, 255);
ghostGreen = random(0, 255);
ghostBlue = random(0, 255);
}
if (score ==90) {
println ("ARE YOU ENJOYING THIS???");
ghostRed = random(0, 255);
ghostGreen = random(0, 255);
ghostBlue = random(0, 255);
}
if (score ==95) {
println ("THEY HAVE CHILDREN!!!");
ghostRed = random(0, 255);
ghostGreen = random(0, 255);
ghostBlue = random(0, 255);
}
if (score ==100) {
println ("MURDERER!");
ghostRed = random(0, 255);
ghostGreen = random(0, 255);
ghostBlue = random(0, 255);
}
if (score ==102) {
println ("PSYCOPATH!!!!");
ghostRed = random(0, 255);
ghostGreen = random(0, 255);
ghostBlue = random(0, 255);
}
}
//RAYS//
void drawRays (int f1, int r1, int r2) {
noStroke();
rectMode(CORNERS);
fill(200, 200, 200, f1);
rect(0, r1, 400, r2);
}
//STARS//
void drawStars(int star1, int star2) {
strokeWeight(2);
stroke(random(40, 255));
point (star1, star2);
}
//DRAW TREES//
void drawTrees(int centerX, int centerY) {
noStroke();
fill (28, 0, 23);
rectMode(CENTER);
rect(centerX, centerY-5, 13, 40);
triangle(centerX, centerY-100, centerX-10, centerY-80, centerX+10, centerY-80);
triangle(centerX, centerY-90, centerX-15, centerY-60, centerX+15, centerY-60);
triangle(centerX, centerY-80, centerX-20, centerY-42, centerX+20, centerY-42);
triangle(centerX, centerY-70, centerX-23, centerY-25, centerX+23, centerY-25);
}
//DRAW FLASHLIGHT//
//flashlight turns on if mouse is clicked//
void drawLight (int light1) {
if (mousePressed) {
noStroke();
ellipseMode (CENTER);
fill (255, 230, 103, 70);
ellipse(mouseX -15, mouseY-40, light1, light1);
}
}
//DRAW GHOSTS//
void drawGhost1() {
fill (ghostRed, ghostGreen, ghostBlue);
noStroke();
ellipseMode(CENTER);
ellipse(ghostX+moveX, ghostY-moveY, ghostSizeX, ghostSizeY);
rectMode(CENTER);
rect(ghostX+moveX, ghostY, ghostSizeX, ghostSizeY);
strokeWeight(15);
stroke(ghostRed, ghostGreen, ghostBlue);
line(ghostX-armX, ghostY-armY, ghostX+1, ghostY+13);
line(ghostX+armX, ghostY-armY, ghostX+1, ghostY+13);
}
void drawGhost2() {
fill (ghostRed, ghostGreen, ghostBlue);
noStroke();
ellipseMode(CENTER);
ellipse(ghostX2+moveX, ghostY2-moveY, ghostSizeX, ghostSizeY);
rectMode(CENTER);
rect(ghostX2+moveX, ghostY2, ghostSizeX, ghostSizeY);
strokeWeight(15);
stroke(ghostRed, ghostGreen, ghostBlue);
line(ghostX2-armX, ghostY2-armY, ghostX2+1, ghostY2+13);
line(ghostX2+armX, ghostY2-armY, ghostX2+1, ghostY2+13);
}
void drawGhost3() {
fill (ghostRed, ghostGreen, ghostBlue);
noStroke();
ellipseMode(CENTER);
ellipse(ghostX3+moveX, ghostY3-moveY, ghostSizeX, ghostSizeY);
rectMode(CENTER);
rect(ghostX3+moveX, ghostY3, ghostSizeX, ghostSizeY);
strokeWeight(15);
stroke(ghostRed, ghostGreen, ghostBlue);
line(ghostX3-armX, ghostY3-armY, ghostX3+1, ghostY3+13);
line(ghostX3+armX, ghostY3-armY, ghostX3+1, ghostY3+13);
}
void drawGhost4() {
fill (ghostRed, ghostGreen, ghostBlue);
noStroke();
ellipseMode(CENTER);
ellipse(ghostX4+moveX, ghostY4-moveY, ghostSizeX, ghostSizeY);
rectMode(CENTER);
rect(ghostX4+moveX, ghostY4, ghostSizeX, ghostSizeY);
strokeWeight(15);
stroke(ghostRed, ghostGreen, ghostBlue);
line(ghostX4-armX, ghostY4-armY, ghostX4+1, ghostY4+13);
line(ghostX4+armX, ghostY4-armY, ghostX4+1, ghostY4+13);
}
//GHOST MOVEMENTS//
//if ghost moves off the screen, floats back in
void updateGhost1() {
ghostX = ghostX +random(-15, 15);
ghostY = ghostY +random(-2, 10);
if (ghostX >width||ghostY > height) {
ghostX = random(-10, 200);
ghostY = random(-100, -1);
}
}
void updateGhost2() {
ghostX2 = ghostX2 +random(-15, 15);
ghostY2 = ghostY2 +random(-2, 10);
if (ghostX2 >width||ghostY2 > height) {
ghostX2 = random(200, 400);
ghostY2 = random(-100, -1);
}
}
void updateGhost3() {
ghostX3 = ghostX3 +random(-15, 15);
ghostY3 = ghostY3 +random(-2, 10);
if (ghostX3 >width||ghostY3 > height) {
ghostX3 = random(200, 400);
ghostY3 = random(-100, -1);
}
}
void updateGhost4() {
ghostX4 = ghostX4 +random(-15, 15);
ghostY4 = ghostY4 +random(-2, 10);
if (ghostX4 >width||ghostY4 > height) {
ghostX4 = random(200, 400);
ghostY4 = random(-100, -1);
}
}
//Thanks for playing!!!\\