xxxxxxxxxx
205
// make pixel art of flowers and watering can to try attactch to //the objs.
// make scor and add continueing arrays of flwoers.
//
var p;
var f = [];
var drops = [];
var img = [];
var watercan;
function preload() {
watercan = loadImage("can.png");
// for (var i = 0; i < 6; i++) {
// img[i] = loadImage("flower" + i + ".png");
//}
}
function setup() {
createCanvas(600, 400);
p = new player();
// drop = new water(width/2, height/2);
// for (var i = 0; i < 6; i++) {
// var kitten = img[i];
// f[i] = new flower(i * 80 + 80, 60, kitten);
// }
}
function draw() {
background(55, 155, 100);
p.show();
p.move();
for (var i = 0; i < drops.length; i++) {
drops[i].show();
drops[i].move();
}
}
// for (var j = 0; j < f.length; j++) {
// if (drops[i].hits(f[j])) {
// f[j].grow();
// drops[i].evap();
// //console.log("hit");
// }
// // }
// }
// var edge = false;
// for (var i = 0; i < f.length; i++) {
// f[i].show();
// f[i].move();
// if (f[i].x > width || f[i].x < 0) {
// edge = true;
// }
// if (f[i].y > height) {
// f[i].y = 0;
// }
// }
// if (edge) {
// for (var i = 0; i < f.length; i++) {
// f[i].shiftDown();
// }
// }
// how to go through an array backwards. start at the end //length -1, go down by one and start at 0
// for (var i = drops.length - 1; i >= 0; i--) {
// if (drops[i].toDelete) {
// drops.splice(i, 1);
// }
// }
function keyReleased() {
if (key != ' ') {
p.setDir(0);
}
}
function keyPressed() {
if (key === ' ') {
var drop = new water(p.x, height - 60);
drops.push(drop);
}
if (keyCode === RIGHT_ARROW) {
p.setDir(1);
} else if (keyCode === LEFT_ARROW) {
p.setDir(-1);
}
}
//player class
class player {
constructor() {
this.x = width / 2;
this.xdir = 0;
}
show() {
imageMode(CENTER);
image(watercan, this.x, height - 30, 40, 60);
}
setDir(dir) {
this.xdir = dir;
}
move(dir) {
this.x += this.xdir * 5;
}
}
// flower class
// class flower {
// constructor(x, y, img) {
// this.x = x;
// this.y = y;
// this.kitten = img;
// this.r = 30;
// // this.img = "flower.png";
// this.xdir = 1;
// //this.ydir= 0;
// }
// grow() {
// this.r = this.r + 1;
// // this.y = this.y -this.r;
// // this line of code knocks them up interestingly enough
// }
// move() {
// this.x = this.x + this.xdir;
// //this.y = this.y+ this.ydir;
// }
// shiftDown() {
// this.xdir *= -1;
// this.y += this.r;
// }
// show() {
// //fill (225,0,200);
// // ellipse(this.x, this.y, this.r*2, this.r*2);
// image(this.kitten, this.x, this.y, this.r * 2, this.r * 2);
// }
// }
class water {
constructor(x, y) {
this.x = x;
this.y = y;
this.r = 8;
// this.toDelete = false;
}
show() {
noStroke();
fill(66, 223, 244);
ellipse(this.x, this.y, this.r * 2, this.r * 2);
}
move() {
this.y = this.y - 5;
}
}
//evap() {
// this.toDelete = true;
// }
// hits(flower) {
// var d = dist(this.x, this.y, flower.x, flower.y);
// if (d < this.r + flower.r) {
// return true;
// } else {
// return false;
// }
// }