xxxxxxxxxx
194
let props = []; // empty array
let emoji1;
let propNum = 10;
let sceneNum = 0;
let tries = 1;
let index = 0;
function setup() {
createCanvas(600, 400);
textSize(40)
for (let i = 0; i < propNum; i++){
prop[i] = new prop (random(width), random(height-100));
}
emoji1 = new emoji();
}
function draw() {
background(255,255,0);
switch (sceneNum) {
case 0:
for (let i = 0; i < propNum; i++){
prop[i].school();
prop[i].move();
prop[i].checkCollision();
}
emoji1.teacher();
emoji1.move();
emoji1.home();
break;
case 1:
for (let i = 0; i < propNum; i++){
prop[i].write();
prop[i].move();
prop[i].checkCollision();
}
emoji1.student();
emoji1.move();
emoji1.home();
break;
case 2:
for (let i = 0; i < propNum; i++){
prop[i].art();
prop[i].move();
prop[i].checkCollision();
}
emoji1.artist();
emoji1.move();
emoji1.home();
break;
case 3:
for (let i = 0; i < propNum; i++){
prop[i].tech();
prop[i].move();
prop[i].checkCollision();
}
emoji1.techno();
emoji1.move();
emoji1.home();
break;
case 4:
textSize(25);
text('the only failure is giving up', 150,200);
}
if (mouseIsPressed){
sceneNum = 0;
tries=1
}
fill(0)
textSize(25)
text("tries: "+tries, 50,350)
textSize(50)
}
class emoji {
constructor(){
this.x = width/2;
this.y = height - 50;
this.w = 30;
this.h = 30;
}
teacher(){text('🧑🏽🏫', this.x, this.y);
}
techno(){
text('🧑🏾💻', this.x,this.y)
}
artist(){
text('🧑🏾🎨', this.x,this.y)
}
student(){
text('🧑🏾🎓', this.x, this.y)
}
move(){
if (keyIsDown(38)){
this.y-=3;
}
if (keyIsDown(40)){
this.y+=3;
}
}
home(){
if (this.y < 0){
sceneNum++;
this.y = height-50;
}
}
}
class prop {
constructor(x, y){
this.x = x;
this.y = y;
this.w = 50;
this.h = 35;
}
school(){text('🏫', this.x, this.y);
}
write(){
text('📝', this.x, this.y);
}
art(){
text('🎨', this.x, this.y);
}
tech(){
text(' 🖥️', this.x, this.y);
}
move(){
this.x++;
if (this.x > width){
this.x = 0;
}
}
checkCollision(){
if (emoji1.x + emoji1.w/2 > this.x && emoji1.x < this.x + this.w && emoji1.y + emoji1.h/2 > this.y && emoji1.y < this.y + this.h){
emoji1.y = height - 50;
tries++
}
}
}