xxxxxxxxxx
104
let snow;
let snows = [];
let snowNum = 500;
let img;
let cat
let br = 0;
let step = 3;
function preload() {
img = loadImage("bckgrnd.jpg");
}
function setup() {
createCanvas(800,600);
frameRate(30);
//talk = new p5.Speech(voiceReady);
cat = new Sprite(100,540,50,50);
catAni = loadAnimation('cat01.png','cat02.png')
catAni.scale=0.3;
cat.addAni(catAni);
snow = new Snow();
for (let i = 0; i < snowNum; i++) {
let snow = new Snow();
snows.push(snow);
}
}
function draw() {
background(133, 158, 232);
imageMode(CENTER);
image(img, 400, 300, 800, 600);
snow.display();
snow.descend();
snow.update();
cat.x += step;
br++;
strokeWeight(5);
stroke(20);
textSize(25);
fill(90+ br%10*15, 100+ br%9*15, 120+br%8*15);
text("Весела Коледа!", cat.x+step*25-70, cat.y-70);
if (br>50){
br = 0
let dir = random(0, 2)
if (dir>1){
step = step * -1;
catAni.scale.x = -1*catAni.scale.x;
}
}
if (cat.x>width || cat.x<0 ){
step = step * -1;
catAni.scale.x = -1*catAni.scale.x;
}
for (let i = 0; i < snows.length; i++) {
snows[i].display(0, 0);
snows[i].update();
}
}
for (let i = snows.length - 1; i >= 0; i++) {
if (snows[i].isDead()) {
snows.splice(i, 1);
}
}
class Snow {
constructor() {
this.x = random(width);
this.y = random(height);
this.size = random(3, 6);
this.speed = random(0, 5);
this.speedx = random(-2, 2);
}
display() {
noStroke();
ellipse(this.x, this.y, this.size);
fill(239, 245, 255, 200);
ellipse(this.x + 100 * sin(this.speed), this.y + 50 * cos(this.speed), this.size);
}
descend() {
this.y = this.y + this.speed;
this.x = this.x + random(-2, 2);
}
update() {
this.y = this.y + this.speed;
this.x = this.x + this.speedx;
if (this.x > width) {
this.x = 0;
}
if (this.x < 0) {
this.x = width;
}
//this.speed = this.speed + 0.01;
if (this.y > height) {
this.y = 0;
}
}
}