xxxxxxxxxx
137
// code by niky
// illustrations by niky
// sources are in references.txt
// don't forget the [i] to refernce arrays@
let cloud;
let cloudw = 100;
let rain = [];
let flower = [];
let q = 5; // how far car moves left and right
let grass;
let road;
let hills;
let car;
let bgBR = 100;
let grassBR=100;
function setup() {
// createCanvas(windowWidth, windowHeight);
createCanvas(windowWidth, windowHeight);
colorMode(HSB);
noStroke();
frameRate(30);
cloud = new Cloud(cloudw, 50);
hills = new Hills();
grass = new Grass();
road = new Road();
car = new Car();
} // end setup
function draw() {
background(190, 100, bgBR); // sky
cloud.update();
hills.update();
grass.update();
road.update();
car.update();
for (let i = 0; i < rain.length; i++) {
rain[i].update();
rain[i].move();
if (rain[i].y >= height - 50) {
flower.push(new Flower(rain[i].x));
rain.splice(i, 1); // remove 1 element from array at index i (e.g. this one)
print(rain.length + " elements left in array");
}
}
for (let i = 0; i < flower.length; i = i + 1) {
flower[i].update();
}
// move Car with left/right arrow keys
if (keyIsDown(RIGHT_ARROW)) {
car.xmove(q);
}
if (keyIsDown(LEFT_ARROW)) {
car.xmove(-q);
}
if (keyIsDown(UP_ARROW) && car.y >= road.y) {
car.y = car.Top;
}
if (keyIsDown(DOWN_ARROW) && car.y <= grass.y) {
car.y = car.Bottom;
}
if (car.x > width + 100) {
car.x = -100;
} else if (car.x < -100) {
car.x = width + 100
}
if (mouseY >= 0 && mouseY <= 100) {
cloud.x = mouseX;
}
if (rain.y > height / 2) {
print("kjdfhgjkdsfjkghsd.fkg");
flower.push(new Flower(100));
}
// if (mouseY >= road.y && mouseY <= grass.y) {
// car.x = map(mouseX, 0, width, car.w, width - car.w);
// }
// if(frameCount % 30 == 0){
// bgBR = bgBR-1;
// grassBR = grassBR-1}
// if(grassBR <=30){
// grassBR = 30;
// }
} // end draw
function mousePressed() {
if (mouseX >= cloud.x - 50 && mouseX <= cloud.x + 50 &&
mouseY >= cloud.y - 50 && mouseY <= cloud.y + 50) {
rain.push(new Rain(cloud.x));
}
if (mouseX >= flower.x - flower.w && mouseX <= flower.x + flower.w){
flower.splice(i, 1);
}
}
function keyPressed() {
if (keyCode === 32)
{
clear();
}
}