//Object Oriented Toy Assignment
//"Cloudy Day" by Ivy Zhao
//Use W and D to move left and right
//Hold W to shoot
//Did you think the lasers would actually kill bunnies? Why would you want to kill bunnies?!
boolean laserShoot;
//arrays
Clouds[] cloudArray = new Clouds[15];
Dustball dust = new Dustball();
Bunnies bunnies = new Bunnies();
void setup () {
size(400, 400);
noStroke();
rectMode(CORNERS);
ellipseMode(CENTER);
//initialize cloud object
for (int i = 0; i < cloudArray.length; i++) {
cloudArray[i] = new Clouds((random(0, 800)), (random(0, 500)), random(0.5, 1)); //gives float x, y, v in Clouds
}
}
void draw() {
background(#B6F4F1);
fill(#68FFA5);
rect(0, 350, 400, 400);
//draw clouds
for (int i = 0; i < cloudArray.length; i++) {
cloudArray[i].display();
cloudArray[i].move();
}
//call rest of drawn stuff
dust.displayDust();
dust.moveDust();
bunnies.displayBuns();
//plat.platformWall();
}
void keyPressed() {
if (key == 'a' || key == 'A') {
dust.left = true;
}
if (key == 'd' || key == 'D') {
dust.right = true;
}
if (key =='w' || key == 'W') {
//laser.shoot = true;
laserShoot = true;
}
}
void keyReleased() {
if (key == 'a' || key == 'A') {
dust.left = false;
}
if (key == 'd' || key == 'D') {
dust.right = false;
}
if (key == 'w' || key == 'W') {
laserShoot = false;
}
}class Bunnies {
Laser laser;
float bunPosX, bunPosY;
Bunnies() {
bunPosX = random(0, 400);
bunPosY = random(0, 300);
}
void displayBuns() {
bun1();
if (bunPosX < 400) {
bunPosX += 1;
} else if (bunPosX >= 400) {
bunPosX = 0;
bunPosY = random(0, 300);
} else if (laser.laserPos.x - bunPosX <= 20 && laser.laserPos.y - bunPosY <= 40) {
bunPosX = 0;
bunPosY = random(0, 300);
}
}
void bun1() {
fill(#FFCAD9);
rect(bunPosX, bunPosY, bunPosX + 15, bunPosY + 10, 2);
rect(bunPosX + 8, bunPosY - 10, bunPosX + 20, bunPosY, 2);
rect(bunPosX + 8, bunPosY - 15, bunPosX + 10, bunPosY - 10);
rect(bunPosX + 18, bunPosY - 15, bunPosX + 20, bunPosY - 10);
fill(255);
rect(bunPosX + 10, bunPosY - 8, bunPosX + 11, bunPosY - 5);
rect(bunPosX + 16, bunPosY - 8, bunPosX + 17, bunPosY - 5 );
}
}class Clouds {
float cloudPosX;
float cloudPosY;
float cloudVel;
//gets float x, y ,v from NOM
Clouds(float x, float y, float v) {
cloudPosX = x;
cloudPosY = y;
cloudVel = v;
}
//draws clouds
void display() {
cloud1();
//cloud2();
//cloud3();
}
//moves clouds across screen
void move() {
if (cloudPosX < 600) {
cloudPosX = cloudPosX + cloudVel;
} else {
cloudPosX = -100;
cloudPosY = random(0, 300);
}
}
void cloud1() {
fill(255);
rect(cloudPosX, cloudPosY, cloudPosX + 60, cloudPosY + 10, 10);
rect(cloudPosX + 10, cloudPosY - 10, cloudPosX + 50, cloudPosY, 10);
rect(cloudPosX + 30, cloudPosY - 17, cloudPosX + 40, cloudPosY - 7, 10);
}
//void cloud2() {
// fill(255);
// rect(cloudPosX, cloudPosY + 40, cloudPosX + 50, cloudPosY + 50, 10);
// rect(cloudPosX + 10, cloudPosY + 50, cloudPosX + 20, cloudPosY + 60, 10);
// rect(cloudPosX + 10, cloudPosY + 30, cloudPosX + 40, cloudPosY + 40, 10);
// rect(cloudPosX + 20, cloudPosY + 20, cloudPosX + 30, cloudPosY + 30, 10);
//}
//void cloud3() {
// fill(255);
// rect(cloudPosX + 450, cloudPosY + 40, cloudPosX + 510, cloudPosY + 50, 10);
// rect(cloudPosX + 460, cloudPosY + 50, cloudPosX + 500, cloudPosY + 60, 10);
// rect(cloudPosX + 470, cloudPosY + 30, cloudPosX + 500, cloudPosY + 40, 10);
// rect(cloudPosX + 480, cloudPosY + 20, cloudPosX+ 490, cloudPosY + 30, 10);
//}
}class Dustball {
Laser laser;
boolean left;
boolean right;
//boolean jump;
//boolean fall;
PVector position;
float move;
float gravity;
Dustball() {
gravity = 2;
left = false;
right = false;
//jump = false;
//fall = false;
move = 0;
position = new PVector(50, 325);
laser = new Laser(position.x, position.y + 10);
}
//draws the dustball
void displayDust() {
fill(0);
rect(position.x, position.y, position.x + 20, position.y + 20, 5);
rect(position.x + 6, position.y + 20, position.x + 8, position.y + 25);
rect(position.x + 13, position.y + 20, position.x + 15, position.y + 25);
fill(255);
rect(position.x + 8, position.y + 10, position.x + 10, position.y + 15);
rect(position.x + 15, position.y + 10, position.x + 17, position.y + 15);
}
void moveDust() {
laser.shoot();
laser.movement();
laser.displayLaser();
//limit dustball to screen
if (position.x < 0) {
position.x = 0;
} else if (position.x > 380) {
position.x = 380;
} else if (position.y < 20) {
position.y = 20;
} else if (position.y > 350) {
position.y = 350;
}
//moving the dustball left and right
if (right == true) {
move = 2;
position.x += move;
}
if (left == true) {
move = 2;
position.x -= move;
}
//if (jump == true) {
// gravity = 2;
// position.y -= gravity;
//}
//if (fall == true) {
// gravity = 2;
// position.y += gravity;
//}
}
}
//BEEN SITTING HERE FOR 30+ HOURS some things just don't workclass Laser {
boolean hit;
PVector laserPos = new PVector();
PVector laserVel = new PVector();
Laser(float laserX, float laserY) {
//setting laser x, y to where dustball is
laserPos.x = laserX;
laserPos.y = laserY;
laserVel.y = 0;
laserVel.x = 0;
}
void shoot() {
//if W is pressed, laserShoot = true, changes laser velocity to 4
if (laserShoot) {
laserVel.y = -10;
}
}
void movement() {
laserPos.add(laserVel);
//sets the laser to be with the dustball
if (dust.right == true) {
laserPos.x = dust.position.x;
} else if (dust.left == true) {
laserPos.x = dust.position.x;
}
//resets laser if hits top of screen
if (laserPos.y < 0) {
laserPos.y = dust.position.y - 5;
}
}
void displayLaser() {
fill(0);
if (laserShoot) {
rect(laserPos.x + 9, laserPos.y, laserPos.x + 11, laserPos.y - 5);
}
}
}