xxxxxxxxxx
87
let cake, alice, medicine;
let w1, w2, w3;
let h1, h2, h3;
let myFont;
let i = 1;
let cnv;
let t, q;
let counter = 0;
function preload() {
cake = loadImage("assets/cake.png");
alice = loadImage("assets/Alice.png");
medicine = loadImage("assets/bottle.png");
myFont = loadFont('assets/Parisienne-Regular.ttf');
}
function setup() {
cnv = createCanvas(400, 400);
w1 = int(cake.width);
h1 = int(cake.height);
w2 = medicine.width;
h2 = medicine.height;
imageMode(CENTER);
rectMode(CENTER);
}
function draw() {
background("#EEA9A9");
fill(0);
textFont(myFont);
textSize(36);
text("Alice", 10, 50);
if(counter ===0){
i=1;
}else{
i = counter;
}
image(alice, width / 4 * 3, height / 2, 400 / i, 420 / i);
// i= map(mouseX,0,width,2,20);
textSize(20);
noStroke();
if (mouseX > 0 && mouseX < 95 && mouseY > 162 && mouseY < 237) {
fill(255, 50);
rect(50, width / 2, 100, 80);
t = random(-1, 1);
fill(0);
text("Eat me.", 100, width / 2);
} else {
t = 0;
}
if (mouseX > 45 && mouseX < 92 && mouseY > 270 && mouseY < 370) {
fill(255, 50);
rect(70, width / 2 + 120, 50, 100);
q = random(-1, 1);
fill(0);
text("Drink me.", 100, width / 2 + 120);
} else {
q = 0;
}
push();
translate(50, width / 2);
image(cake, 0, 0, 100 + t, 80 + t);
image(medicine, 20, 120, 50 + q, 100 + q);
pop();
}
function mousePressed() {
if (mouseX > 45 && mouseX < 92 && mouseY > 270 && mouseY < 370) {
if(counter<5){
counter += 1;
}else{
counter=5;
}
print(counter);
}
if (mouseX > 0 && mouseX < 95 && mouseY > 162 && mouseY < 237) {
print("drink drug!");
if(counter<=5&&counter>1){
counter -= 1;
}else{
counter=1;
}
print(counter);
}
}