xxxxxxxxxx
var leftHeld, rightHeld, upHeld, downHeld, fKey;
var time = 0;
var lastTime = 0;
var show;
var traitSet = ['Beautiful', 'Kind', 'Graceful', 'Great Cook', 'Loves to Clean', 'Elegant', 'Am a Mother','Intelligent', 'Ambitious', 'Opinionated', 'Breadwinner', 'Career-Oriented'];
var playerFemale;
// var playerMale;
// TRIED TO CREATE A MALE PLAYER BUT INCLUDING THIS CREATED BUGS IN MY CODE THAT I COULDNT FIGURE OUT
var state = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
playerFemale = new Female(width/2, height/2);
// playerMale = new Male(width/2, height/2);
}
function draw() {
if (state == 0) {
background(0);
homeScreen();
}
if (state == 1) { // game state
background(0);
activateKeys(); // calls keys to allow player movements
traits();
playerFemale.display(); // calls player
}
// if (state == 2) {
// background(255);
// activateKeys();
// playerMale.display();
// }
}
function homeScreen() {
push();
fill(255);
textAlign(CENTER);
textSize(40);
translate(width/2, height/2 - 50);
text("Are you ready to embark on this journey towards becoming the perfect woman?",0,0);
pop();
push();
fill(100);
textAlign(CENTER);
textSize(30);
translate(width/2, height/2 + 50);
text("Here are the Instructions: \n Traits of a perfect woman will pop up on the screen. \n Catch a trait and win the game!",0,0);
pop();
push();
fill(255,0,155);
textAlign(CENTER);
textSize(25);
translate(width/2, height/2 + 200);
text("Press 'F' Key to Start",0,0);
pop();
// push(); //originally represented the male character
// fill(0,0,255);
// translate(width/2 - 100, height/2 + 200);
// ellipse(0,0,100,100);
// pop();
// push(); //originally represented the female character
// fill(255,0,155);
// translate(width/2 + 100, height/2 + 200);
// ellipse(0,0,100,100);
// pop();
}
function traits() { //objective entities
time = millis();
if(time - lastTime >= 2000) { // controls when trait pops up, don't know how to make it not flash
fill(255);
textAlign(CENTER);
textSize(25);
text(random(traitSet), random(width), random(height));
lastTime = millis();
}
}
var Female = function(startX, startY) { // player class
this.position = createVector(startX, startY);
this.displayPosition = createVector(startX, startY);
this.direction = createVector(1,1);
this.speed = 2;
}
Female.prototype.display = function(){ // creates player
push();
this.displayPosition = p5.Vector.lerp(this.position, this.displayPosition, 0.9);
fill(255,0,155);
noStroke();
translate(this.displayPosition.x, this.displayPosition.y);
ellipse(0,0,40,40);
pop();
}
Female.prototype.move = function(xMove, yMove) { // moves player
print("Moving... " + xMove + ", " + yMove);
this.position.x += xMove;
this.position.y += yMove;
if (this.position.x < 0) { this.position.x = 0; }
if (this.position.x > width) { this.position.x = width; }
if (this.position.y < 0) { this.position.y = 0; }
if (this.position.y > height) { this.position.y = height; }
}
// var Male = function(startX, startY) {
// this.position = createVector(startX, startY);
// this.displayPosition = createVector(startX, startY);
// this.direction = createVector(1,1);
// this.speedM = 2;
// }
// Male.prototype.display = function(){
// push();
// this.displayPosition = p5.Vector.lerp(this.position, this.displayPosition, 0.9);
// fill(255,0,155);
// noStroke();
// translate(this.displayPosition.x, this.displayPosition.y);
// ellipse(0,0,40,40);
// pop();
// }
// Male.prototype.move = function(xMove, yMove) {
// print("Moving... " + xMove + ", " + yMove);
// this.position.x += xMove;
// this.position.y += yMove;
// if (this.position.x < 0) { this.position.x = 0; }
// if (this.position.x > width) { this.position.x = width; }
// if (this.position.y < 0) { this.position.y = 0; }
// if (this.position.y > height) { this.position.y = height; }
// }
function activateKeys (startX, startY, directionX, directionY) { // allows player to move
this.position = createVector(startX, startY);
this.direction = createVector(directionX, directionY);
if (upHeld) { playerFemale.move(0,-playerFemale.speed); }
if (downHeld) { playerFemale.move(0,playerFemale.speed); }
if (leftHeld) { playerFemale.move(-playerFemale.speed,0); }
if (rightHeld) { playerFemale.move(playerFemale.speed,0); }
// if (upHeld) { playerMale.move(0,-playerMale.speed); }
// if (downHeld) { playerMale.move(0,playerMale.speed); }
// if (leftHeld) { playerMale.move(-playerMale.speed,0); }
// if (rightHeld) { playerMale.move(playerMale.speed,0); }
}
function keyPressed() {
print(key + " pressed.");
if (key == "f"){ //changes state
fKey = true;
state = 1;
}
// if (key == "m"){
// mKey = true;
// state = 2;
// }
if (key === "ArrowUp"){ upHeld = true; }
if (key === "ArrowDown"){ downHeld = true; }
if (key === "ArrowLeft"){ leftHeld = true; }
if (key === "ArrowRight"){ rightHeld = true; }
}
function keyReleased() {
print(key + " released.");
if (key === "ArrowUp"){ upHeld = false; }
if (key === "ArrowDown"){ downHeld = false; }
if (key === "ArrowLeft"){ leftHeld = false; }
if (key === "ArrowRight"){ rightHeld = false; }
}