xxxxxxxxxx
187
// City Skyline
//Kristy Lee
// importing paintings
// painting of city in the day broken up into 3 parts
let day_frame;
let day_building;
let day_bg;
//clouds
let cloud1;
let cloud2;
let cloud3;
//birds
let bird1;
let bird2;
let bird3;
//sun
let sun;
// day or night
let day = true;
//variables
//cloud position
var cloudx = 0;
var cloudy = 0;
//wind = speed of cloud movement ranging from 1-5
var wind = 0;
//appear_clouds determines which cloud appears. has a range of random(3)
var appear_clouds = 0;
//bird position
var birdx = 0;
var birdy = 0;
//bird speed range of random(8)
var bird_speed = 0;
//determines if the bird flies up or down -1 for down 0 for straignt 1 for upwards
var bird_direction = 0;
//appear_birds determines which bird appears. has a range of random(3)
var appear_birds = 0;
//sun position
var sunx = 0;
var suny = 0;
//time of day
var time=0;
//loading images
function preload(){
day_frame = loadImage('city frame day.png');
day_building = loadImage('city building day.png');
day_bg = loadImage('city bg day.png');
cloud1 = loadImage('cloud 1.PNG');
cloud2 = loadImage('cloud 2.PNG');
cloud3 = loadImage('cloud 3.PNG');
bird1 = loadImage('bird 1.PNG');
bird2 = loadImage('bird 2.PNG');
bird3 = loadImage('bird 3.PNG');
sun = loadImage('sun.PNG');
night_bg = loadImage('City night.JPG');
}
function setup() {
createCanvas(625, 417);
cloudy = random(height/2);
wind = random(6);
appear_clouds = random(3);
appear_birds = random(3);
bird_speed = random(8);
bird_direction = random(-1,1);
sunx = width - 50;
suny = 60;
}
function draw() {
background(220);
if (time <= 1800){
day = true;
}else {
day = false;
}
if (day == true){
image(day_bg, 0,0);
image(day_building, 0,0);
//Sun
image(sun, sunx, suny, 50, 50);
if (time > 0 && time <600){
suny -= 0.1;
sunx -= 0.4;
} else if (time >= 600 && time <1500){
suny = 0;
sunx -= 0.2;
} else if (time >= 1500 && time < 1800){
suny += 0.1;
sunx -= 0.5;
}
//clouds
if (appear_clouds <= 1){
if (cloudx <=width){
image(cloud1, cloudx, cloudy, 75,75);
cloudx+=wind;
}
else{
cloudx = 0;
cloudy = random(height/2);
wind = random(6);
appear_clouds = random(3);
}
}else if (appear_clouds > 1 && appear_clouds <= 2){
if (cloudx <= width){
image(cloud2, cloudx, cloudy, 50,50);
cloudx+=wind;
}
else{
cloudx = 0;
cloudy = random(height/2);
wind = random(6);
appear_clouds = random(3);
}
}else {
if (cloudx <= width){
image(cloud3, cloudx, cloudy, 75,75);
cloudx+=wind;
}
else{
cloudx = 0;
cloudy = random(height/2);
wind = random(6);
appear_clouds = random(3);
}
}
//birds
if (appear_birds <= 1){
if (birdx <= width && birdy > 0 && birdy < height){
image(bird1, birdx, birdy, 50,50);
birdx += bird_speed;
birdy += bird_direction;
}
else{
birdx = 0;
birdy = random(height/2);
bird_speed = random(8);
bird_direction = random(-1,1);
}
}else if (appear_birds > 1 && appear_birds <= 2){
if (birdx <= width && birdy > 0 && birdy < height){
image(bird2, birdx, birdy, 50,50);
birdx += bird_speed;
birdy += bird_direction;
}
else{
birdx = 0;
birdy = random(height/2);
bird_speed = random(8);
bird_direction = random(-1,1);
}
}else {
if (birdx <= width && birdy > 0 && birdy < height){
image(bird3, birdx, birdy, 50,50);
birdx += bird_speed;
birdy += bird_direction;
}
else{
birdx = 0;
birdy = random(height/2);
bird_speed = random(8);
bird_direction = random(-1,1);
}
}
image(day_frame, 0,0);
}
if (day == false){
image(night_bg, 0, 0, width, height);
}
time +=1;
//reset day
if (time > 2400){
time = 0;
sunx = width - 50;
suny = 60;
}
}