xxxxxxxxxx
151
let sceneNum = 0
let itemNum = 5
let items = []
let needs = []
let makeup = []
let collectedmakeup = []
let collecteditems = 0
let avoidedneeds = []
let girl
let d
function setup() {
createCanvas(400, 400);
for (let i = 0; i < 5; i++) {
items[i] = new Item (random(width),random(height-100));
}
girl = new Girl()
}
function draw() {
background(220);
scene1();
// switch (sceneNum) {
// case 0:
// scene0();
// break;
// case 1:
// scene1();
// break;
// case 2:
// console.log("scene2")
// break;
// }
}
function scene0(){
clear();
background(194, 239, 194);
fill(255,255,255);
textSize(30);
textAlign(CENTER);
text('click to start!', width/2, height/2);
playbutton = createButton('Play');
playbutton.position(180, 375);
playbutton.mousePressed(playsound);
}
function scene1(){
clear();
background(0);
//draw items
for (let i = 0; i < 5 ; i++) {
items[i].body();
items[i].move();
items[i].checkCollison();
}
//draw player
girl.body();
girl.move();
}
class Girl {
constructor(){
this.x = width/2;
this.y = height - 20;
this.w = 20;
this.h=20;
}
body(){
ellipse(this.x, this.y, this.w, this.h)
}
move(){
if (keyIsDown(39)) {
girl.x++
}
if (keyIsDown(37)) {
girl.x--
}
}
}
class Item {
constructor(x,y){
this.x = x;
this.y = y;
this.w = 30;
this.h = 30;
this.collided = false;
}
body(){
rectMode(CENTER)
rect(this.x, this.y, this.w, this.h);
}
move(){
this.y++
if (this.y > height) {
this.y = 0
this.collided = false
}
}
checkCollison(){
d = int(dist(this.x,this.y,girl.x,girl.y));
//console.log(d);
if (d < girl.w/2 + && this.collided == false ) {
console.log("bumped!");
this.collided = true
collecteditems+=1
console.log(collecteditems)
}
}
}
// class Need {
// constructor(){}
// }