xxxxxxxxxx
287
let kids1;
let scene = 0;
let sofa;
let table;
let bed;
let studytable;
let fridge;
let phone;
let tableImg = null;
let fridgeImg = null;
let studytableImg = null;
let bedImg = null;
let sofaImg = null;
let kidImg = null;
let phoneImg = null;
let furniture = [];
let ifclick;
let times = [3,7,10];
let trustBarW = 300;
let trustBarH = 10;
let boringBarW =0;
let boringBarH =10;
let doorcloseImg = null;
let dooropenImg = null;
let happyImg = null;
let sadImg = null;
let peaceImg = null;
let angryImg = null;
let mom;
let doorX, doorY;
let isDoorOpen;
let r;
let isMomvisible;
function preload() {
fridgeImg = loadImage('fridge.png');
tableImg = loadImage('table.png');
sofaImg = loadImage('sofa.png');
bedImg = loadImage('bed.png');
studytableImg = loadImage('studytable.png');
kidImg = loadImage('kid.png');
phoneImg = loadImage('phone.png');
doorcloseImg = loadImage('doorclose.png');
dooropenImg = loadImage('dooropen.png');
happyImg = loadImage('happy.png');
sadImg = loadImage('sad.png');
peaceImg = loadImage('peace.png');
angryImg = loadImage('angry.png');
}
function setup() {
createCanvas(600, 600);
kids1 = new Kids1(500,500,100,100,kidImg);
// x value y value w h color value img
sofa = new Sofa(random(0,150), random(0, 80), 200, 200, sofaImg);
table = new Sofa(random(200,300), random(250, 350), 200, 200, tableImg);
fridge = new Sofa(random(0,150), random(350, 400), 200, 200, fridgeImg);
studytable = new Sofa(random(350,450), random(0, 100), 150, 150, studytableImg);
bed = new Sofa(random(200,300), random(120, 200), 150, 150, bedImg);
phone = new Phone(height/3,width/3,300,300,phoneImg);
furniture.push(sofa);
furniture.push(table);
furniture.push(fridge);
furniture.push(studytable);
furniture.push(bed);
let randomHasPhone = int( random( 1 , furniture.length ) );
console.log(randomHasPhone)
for( let i = 0; i < furniture.length; i++ ){
if( randomHasPhone === (i+1) ){
furniture[i].hasPhone = true;
}
}
ifclick = false;
doorX = 300;
doorY = 10;
isDoorOpen = false;
isMomvisible = false;
r = random(times);
console.log(r)
}
function draw() {
switch (scene) {
case 0:
background(211,194,173);
kids1.body();
kids1.move();
textFont('Courier New');
textSize(20);
textStyle(BOLD);
fill(0);
text('Level 1-Find out your phone', 10, 570)
for( let i = 0; i < furniture.length; i++ ){
furniture[i].body();
}
break;
case 1:
background(211,194,100);
phone.body();
textFont('Courier New');
textSize(20);
textStyle(BOLD);
fill(0);
text('Congratulations!You got your phone 🎉', 80, 200)
text('click to go to the next level', 120, 400)
if(ifclick === true){
scene = 2;
}
else{
scene = 1;
}
if(mouseIsPressed === true){
ifclick = true;
}
break;
case 2:
background(200,159,156);
// mom check in time
let s =int(millis()/100);
// let r = random(times);
// console.log(r);
// if (s % r == 0){
// console.log(s);
// }
// trust bar
rect(20, 20, trustBarW, trustBarH);
rect(20, 40, boringBarW, boringBarH);
if(isDoorOpen === true){
image(dooropenImg, doorX, doorY,400,400);
}
else{
image(doorcloseImg,doorX, doorY,400,400);
}
if(checkState(mouseX, mouseY, mouseX, mouseY,100,100) === true && mouseIsPressed === true){
image(sadImg, 50, 200,400,400);
boringBarW = boringBarW + 0.1;
}
else{
image(happyImg, 50, 200,400,400);
trustBarW = trustBarW - 0.02;
}
// console.log( s , r*10 )
console.log(frameCount,r*60)
if (frameCount % r*60 === 0){
isDoorOpen = !isDoorOpen;
console.log(isDoorOpen)
if(isDoorOpen === false){
isMomvisible = false;
}
}
if( frameCount-60 % r*60 == 0){
if(isMomvisible === false){
isMomvisible = true;
}
}
if (isMomvisible===true&&isDoorOpen === true && mouseIsPressed === true){
image(peaceImg, doorX, doorY,400,400);
}
if ( isMomvisible===true&&isDoorOpen === true && mouseIsPressed === false) {
image(angryImg, doorX, doorY,400,400);
trustBarW = trustBarW - 1;
}
function checkState(mX, mY, posX, posY, w, h) {
if((mX >= posX && mX <= posX + w) && (mY >= posY && mY <=posY + h)){
return true;
}
else{
return false;
}
}
break;
}
}
class Sofa {
constructor(x, y, w=50, h=35, img, hasPhone = false) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.img = img;
this.hasPhone = hasPhone; // boolean
}
body() {
if( this.img ){
image(this.img, this.x, this.y, this.w, this.h);
}
this.checkCollision();
}
checkCollision() {
if (kids1.x + kids1.w / 2 > this.x && kids1.x + 120 < this.x + this.w && kids1.y + kids1.h / 2 > this.y && kids1.y +100 < this.y+ this.h) {
console.log('bumped!');
if( this.hasPhone === true ){
// text('here is the phone 🎉', 0, 30)
scene = 1;
}else {
text('here is no phone :( ', 10, 30)
}
}
}
}
class Kids1 {
constructor(x, y, w=50, h=35, img) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.img = img;
}
body() {
if( this.img ){
image(this.img, this.x, this.y, this.w, this.h);
}
}
move() {
if (keyIsDown(38)) {
this.y -= 3;
}
if (keyIsDown(40)) {
this.y += 3;
}
if (keyIsDown(37)) {
this.x -= 3;
}
if (keyIsDown(39)) {
this.x += 3;
}
}
}
class Phone {
constructor(x, y, w=50, h=35, img) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.img = img;
}
body() {
if( this.img ){
image(this.img, this.x, this.y, this.w, this.h);
}
}
}