xxxxxxxxxx
649
let sceneNum = 0;
let greendress = []; // empty array
let greendressNum = 8;
let girl1;
let gain = 0;
let otherdress = [];
let otherdressNum = 6;
let checkFail = 0;
let dressbg;
let girlImage;
let greendressImage;
let otherdressImage = [];
let gamescene1Image;
let gamescene3Image;
let greenstarImage;
let pollumonImage;
let failImage;
let dressbgImage;
let myMusic;
let mySoundvic;
let mySounddef;
let directionImage
function preload(){
girlImage = loadImage('assets/girl.png');
greendressImage = loadImage('assets/dressgreen.png');
gamescene1Image = loadImage('assets/gamescene1.jpg')
gamescene3Image = loadImage('assets/gamescene3.jpg')
greenstarImage = loadImage('assets/greenstar.png')
pollumonImage = loadImage('assets/pollumon.png')
failImage = loadImage('assets/fail.png')
dressbgImage = loadImage('assets/dressbg.png')
directionImage = loadImage('assets/direction.png')
myMusic = loadSound('assets/musicbgm.mp3');
// mySounddef = createAudio('assets/sounddef.mp3');
mySoundvic = createAudio('assets/soundvic.mp3');
for (let i = 0; i < 6; i++){
otherdressImage[i] = loadImage('assets/dress' + i + '.png');
}
}
function setup() {
createCanvas(400, 600);
// myMusic.play();
// myMusic.loop();
// myMusic.setVolume(0.2);
// dress Generation
for (let i = 0; i < greendressNum; i++) {
greendress[i] = new Greendress(
random(50, width - 100),
random(50, height - 100),
"#ffffff"
);
}
// for (let i = 0; i < otherdressNum; i++){
// otherdress[i] = new Otherdress (random(width), random(height-100), color(random(255), random(255), random(255)));
// }
// Main Character
girl1 = new Girl();
}
function draw() {
background(255);
switch (sceneNum) {
case 0:
image(gamescene1Image,0,0,400,600);
// Scene Console
console.log("scene 0");
fill(0);
rect(147, 277, 120,40);
fill(255,0,0);
textAlign(CENTER, CENTER);
textSize(32);
// text("welcome", width / 2, height / 2 - 40);
text(" Start ENTER Game", width / 2, height / 2);
// Next Scene
if (keyIsDown(13)) {
myMusic.play();
myMusic.loop();
myMusic.setVolume(0.5);
sceneNum = 1;
}
break;
case 1:
// image(dressbgImage,200,300,400,600);
fill(255, 179, 179)
rect(0,0,400,600)
image(directionImage, 340, 570, 100,60)
// fill(0)
// textAlign(CENTER, CENTER);
// textSize(16);
// text("Use Direction Keys", width/2, 590);
// image(pollumonImage,200,300,370,370)
// fill(255,255,255,150)
// rect(0,0,400,600)
// Scene Console
console.log("scene 1");
// greendress Generation
for (let i = 0; i < 2; i++) {
greendress[i].body();
// greendress[i].move();
greendress[i].checkCollision();
}
// Main Character
girl1.body();
girl1.move();
//me1.home();
// dress gain
currentGain();
// Enter Next Scene
if (gain == 2) {
// fill(255)
// rect(0,0,400,600)
imageMode(CENTER);
image(greenstarImage,200,400, 100,100)
noFill(0);
rect(140, 277, 120,40);
fill(255,0,0);
textAlign(CENTER, CENTER);
textSize(32);
text("Congrats! Level Up!", width / 2, height / 2-100);
text("ENTER", width / 2, height / 2 );
if (keyIsDown(13)) {
sceneNum = 2;
for (let i = 0; i < greendressNum; i++) {
greendress[i] = new Greendress(
random(50, width - 50),
random(50, height - 100),
"#ffffff"
);
}
}
}
break;
case 2:
fill(255, 179, 179)
rect(0,0,400,600)
image(directionImage, 340, 570, 100,60)
// fill(0)
// textAlign(CENTER, CENTER);
// textSize(16);
// text("Use Direction Keys", width/2, 590);
// Scene Console
console.log("scene 2");
// greendress Generation
for (let i = 0; i < greendressNum; i++) {
greendress[i].body();
// clocks[i].move();
greendress[i].checkCollision();
}
// Character
girl1.body();
girl1.move();
// dress gained
currentGain();
// Enter Next Scene
if (gain == 10) {
imageMode(CENTER);
image(greenstarImage,random(50,400),random(50,600),100,100)
image(greenstarImage,200,420, 200,200)
noFill(0);
rect(140, 277, 120,40);
fill(255,0,0);
textAlign(CENTER, CENTER);
textSize(32);
text("Congrats! Level Up!", width / 2, height / 2-100);
text("ENTER", width / 2, height / 2 );
if (keyIsDown(13)) {
sceneNum = 3;
for (let i = 0; i < greendressNum; i++) {
greendress[i] = new Greendress(
random(50, width - 50),
random(50, height - 100),
"#ffffff" );
}
for (let i = 0; i < otherdressNum; i++) {
otherdress[i] = new Otherdress(random(50, width - 50),
random(50, height - 100), "#ffffff" );
}
girl1.x = 200;
girl1.y = 500;
}
}
break;
case 3:
fill(255, 179, 179)
rect(0,0,400,600)
image(directionImage, 340, 570, 100,60)
// fill(0)
// textAlign(CENTER, CENTER);
// textSize(16);
// text("Use Direction Keys", width/2, 590);
// Scene Console
console.log("scene 3");
// green dress generation
for (let i = 0; i < greendressNum; i++) {
greendress[i].body();
// greendress[i].move();
greendress[i].checkCollision();
}
// Main Character
girl1.body();
girl1.move();
//girl1.home();
// green shopper
//
//
for (let i = 0; i < otherdressNum; i++) {
otherdress[i].body();
otherdress[i].move();
otherdress[i].checkCollision();
}
// dress gain
currentGain();
// Enter Next Scene // play again
//
if (checkFail == 1) {
// mySounddef.play();
image(failImage,200,300,400,600);
noFill(0);
rect(128, 277, 140,40);
fill(0);
textAlign(CENTER, CENTER);
textSize(38);
text("FAIL!", width / 2, height / 2-100);
text("Try Again" , width / 2, height / 2-50);
text("ENTER", width/2, height/2)
if (keyIsDown(13)) {
// mySounddef.stop();
sceneNum = 4;
// girl1.x = 40;
// girl1.y = 60;
// gain = 10;
// checkFail = 0;
// for (let i = 0; i < greendressNum; i++) {
// greendress[i] = new Greendress(
// random(50, width - 50),
// random(50, height - 100),
// "#ffffff"
// );
// }
// for (let i = 1; i < otherdressNum; i++) {
// otherdress[i] = new Otherdress(random(50, width - 50),
// random(50, height - 100), "#ffffff");
// }
// girl1.x = 200;
// girl1.y = 500;
}
}
// Enter Next Scene // play again
if (gain == 18) {
myMusic.stop();
mySoundvic.play();
// mySoundvic.setVolume(0.1)
// fill("#ffffff");
// rect(120, 100, width - 120 * 2, height - 100 * 2);
image(gamescene3Image,200,300,400,600);
// noFill(0);
// rect(128, 277, 140,40);
// fill(0);
// textAlign(CENTER, CENTER);
// textSize(38);
// text("FAIL!", width / 2, height / 2-100);
// text("Try Again" , width / 2, height / 2-50);
// text("ENTER", width/2, height/2)
fill(0);
textAlign(CENTER, CENTER);
textSize(38);
text("WIN!", 60, height / 2);
text("ENTER", 320, 450 )
textSize(20);
text("Play Again", 320, 420);
if (keyIsDown(13)) {
myMusic.play();
mySoundvic.stop();
sceneNum = 1;
gain = 0;
for (let i = 0; i < greendressNum; i++) {
greendress[i] = new Greendress(
random(50, width - 100),
random(50, height - 100),
"#ffffff"
);
}
girl1.x = 200;
girl1.y = 500;
}
}
break;
case 4:
fill(255, 179, 179)
rect(0,0,400,600)
image(directionImage, 340, 570, 100,60)
// Scene Console
console.log("scene 4");
// green Generation
for (let i = 0; i < greendressNum; i++) {
greendress[i].body();
// greendress[i].move();
greendress[i].checkCollision();
}
// Main Character
girl1.body();
girl1.move();
for (let i = 0; i < otherdressNum; i++) {
otherdress[i].body();
otherdress[i].move();
otherdress[i].checkCollision();
//clocks[i].checkCollision();
}
// dress gain
currentGain();
// Enter Next Scene // play this level again
//
if (checkFail == 1) {
// mySounddef.play();
// fill("#ffffff");
// rect(120, 100, width - 120 * 2, height - 100 * 2);
image(failImage,200,300,400,600);
noFill(0);
rect(128, 277, 140,40);
fill(0);
textAlign(CENTER, CENTER);
textSize(38);
text("FAIL!", width / 2, height / 2-100);
text("Try Again" , width / 2, height / 2-50);
text("ENTER", width/2, height/2)
if (keyIsDown(13)) {
// mySounddef.stop();
sceneNum = 3;
checkFail = 0;
girl1.x = 40;
girl1.y = 60;
gain = 10;
for (let i = 0; i < greendressNum; i++) {
greendress[i] = new Greendress(
random(50, width - 50),
random(50, height - 100),
"#ffffff"
);
}
// for (let i = 1; i < otherdressNum; i++) {
// otherdress[i] = new Otherdress(random(50, width - 50),
// random(50, height - 100), "#ffffff");
// }
girl1.x = 200;
girl1.y = 500;
}
}
// Enter Next Scene // play again
if (gain == 18) {
// myMusic.stop();
// mySoundvic.play();
// mySoundvic.setVolume(0.1)
// fill("#ffffff");
// rect(120, 100, width - 120 * 2, height - 100 * 2);
image(gamescene3Image,200,300,400,600);
// noFill(0);
// rect(128, 277, 140,40);
// fill(0);
// textAlign(CENTER, CENTER);
// textSize(38);
// text("FAIL!", width / 2, height / 2-100);
// text("Try Again" , width / 2, height / 2-50);
// text("ENTER", width/2, height/2)
fill(0);
textAlign(CENTER, CENTER);
textSize(38);
text("WIN!", 60, height / 2);
text("ENTER", 320, 450 )
textSize(20);
text("Play Again", 320, 420);
if (keyIsDown(13)) {
// myMusic.play();
// mySoundvic.stop();
sceneNum = 1;
gain = 0;
for (let i = 0; i < greendressNum; i++) {
greendress[i] = new Greendress(
random(50, width - 100),
random(50, height - 100),
"#ffffff"
);
}
girl1.x = 200;
girl1.y = 500;
}
}
break;
}
// make buttons later!!!!
// button(80, 290, 40, 40, "W");
// button(30, 340, 40, 40, "A");
// button(80, 340, 40, 40, "S");
// button(130, 340, 40, 40, "D");
// button(450, 340, 120, 40, "SPACE");
}
class Girl {
constructor() {
this.x = width / 2;
this.y = height - 100;
this.w = 30;
this.h = 30;
this.c = color(153, 102, 51);
}
body() {
// fill(this.c);
// ellipse(this.x, this.y, this.w, this.h);
imageMode(CENTER);
image(girlImage,this.x,this.y,girlImage.width * 0.2, girlImage.height * 0.2);
}
move() {
if (keyIsDown(87) || keyIsDown(38)) {
this.y -= 3;
}
if (keyIsDown(83) || keyIsDown(40)) {
this.y += 3;
}
if (keyIsDown(65) || keyIsDown(37)) {
this.x -= 3;
}
if (keyIsDown(68) || keyIsDown(39)) {
this.x += 3;
}
if (this.x < 0) {
this.x = width;
}
if (this.y < 0) {
this.y = height;
}
if (this.x > width) {
this.x = 0;
}
if (this.y > height) {
this.y = 0;
}
}
// home() {
// if (this.y < 0) {
// sceneNum++;
// this.y = height - 50;
// }
// if (sceneNum > 2) {
// sceneNum = 0;
// }
// }
}
class Greendress {
constructor(x, y, c) {
// a special method that creates the dress object
this.x = x;
this.y = y;
this.w = 50;
this.h = 35;
this.c = c;
}
body() {
// fill(this.c);
// circle(this.x, this.y, this.w);
imageMode(CENTER);
image(greendressImage,this.x,this.y,greendressImage.width * 0.15, greendressImage.height * 0.15);
}
move() {
this.x++;
if (this.x > width) {
this.x = 0;
}
}
checkCollision() {
if (dist(girl1.x, girl1.y, this.x, this.y) <=
this.w / 2 + girl1.w / 2
// me1.x + me1.w / 2 > this.x &&
// me1.x < this.x + this.w &&
// me1.y + me1.h / 2 > this.y &&
// me1.y < this.y + this.h
// //
) {
console.log("Dress Gained!");
// me1.y = height - 50; // reset me pos
this.x = -800;
this.y = -800;
gain++;
}
}
}
class Otherdress {
constructor(x, y, c) {
// a special method that creates the dress object
this.x = x;
this.y = y;
this.w = 50;
this.h = 35;
this.c = c;
}
// constructor(x, y, speedX, speedY) {
// this.x = x;
// this.y = y;
// this.speedX = random([-0.8, -0.4, 0.2, 0, 0.2, 0.4, 0.8]);
// this.speedY = random([0.2, 0.4, 0.8]);
// }
body(index) {
// fill(255, 255, 0);
// circle(this.x, this.y, 40);
imageMode(CENTER);
image(pollumonImage,this.x,this.y,pollumonImage.width * 0.04, pollumonImage.height * 0.04);
}
move(){
this.x++;
if (this.x > width){
this.x = 0;
}
}
// move() {
// this.x = x;
// this.y = y;
// }
checkCollision() {
if (
dist(girl1.x, girl1.y, this.x, this.y) <=
20 + girl1.w / 2
// me1.x + me1.w / 2 > this.x &&
// me1.x < this.x + this.w &&
// me1.y + me1.h / 2 > this.y &&
// me1.y < this.y + this.h
// //
) {
console.log("Wrong Dress");
checkFail = 1;
// me1.y = height - 50; // reset me pos
// this.x = -800;
// this.y = -800;
// gain++;
}
}
}
function currentGain() {
for (let i = 0; i < gain; i++) {
// fill(0,255,0)
// ellipse(30 + i * 12, 30, 10);
imageMode(CENTER);
image(greenstarImage,30 + i * 20, 30, 20,20);
}
//make functional button later!!!!
// function button(x, y, w, h, a) {
// push();
// translate(x, y);
// fill("#ffffff");
// rect(0, 0, w, h);
// fill(0);
// textAlign(CENTER, CENTER);
// textSize(20);
// text(a, w / 2, h / 2);
// pop();
// }
}