xxxxxxxxxx
141
let sceneNum = 0;
let guys = [];
let speed = 0
let gFace = [];
let guySaysText = '';
/*
function preload() {
let gFace1 = loadImage('g1.jpg');
let gFace2 = loadImage('g2.jpg');
gFace = [gFace1, gFace2];
}
*/
function setup() {
createCanvas(400, 400);
background(220);
// Guy1 = new Guy(100,100)
for (let i = 0; i < 20; i++) {
guys[i] = new Guy(random(0, 400), random(100, 400));
}
}
function draw() {
switch (sceneNum) {
case 0:
background(220);
console.log("scene 0");
textSize(32);
textAlign(CENTER);
text("Ask him out", 200, 40)
textSize(14);
text("Pick a guy and CLICK", 200, 65)
fill(255)
for (let i = 0; i < 20; i++) {
guys[i].body();
guys[i].move();
}
break;
case 1:
/*
console.log("scene 1");
guyText();
*/
printGuyText(guySaysText);
fill(100);
ellipse(130, 250, 50, 30);
ellipse(270, 250, 50, 30);
break;
case 2:
console.log("scene 2");
background(0)
break;
}
}
function mousePressed() {
for (let i = 0; i < 20; i++) {
guys[i].click1()
}
if (mouseX < 180 && mouseX > 80 && mouseY < 280 && mouseY > 220) {
sceneNum = sceneNum - 1
} else if (mouseX < 320 && mouseX > 220 && mouseY < 280 && mouseY > 220) {
sceneNum = sceneNum + 1
}
}
function printGuyText( txt ) {
noStroke();
fill(255);
rect(50, 100, 300, 200, 20);
fill(0);
textSize(16);
text(txt, 200, 200);
}
function generateNewText() {
let guyName = ['a', 'b', 'c', 'd'];
let guyBeh = ['e', 'f', 'g'];
let rName = random(guyName);
let rBeh = random(guyBeh);
let gText = rName + ' says ' + rBeh + '.';
/*guySaysObject = {
name : rName,
beh : rBeh,
text : gText
};*/
guySaysText = gText;
}
class Guy {
constructor(x, y) {
this.x = x;
this.y = y;
}
body() {
noStroke()
let ranGface = random(gFace);
imageMode(CENTER)
image(ranGface, this.x, this.y, 60, 60);
// ellipse(this.x,this.y,60,60)
}
move() {
this.x = this.x + speed
if (this.x <= 100 && this.x >= -50) {
speed = random(0, 1.5)
}
if (this.x >= 300 && this.x <= 400) {
speed = -random(0, 1.5)
}
}
click1() {
let d = dist(mouseX, mouseY, this.x, this.y);
if (d < 30) {
sceneNum++;
generateNewText();
}
}
}