xxxxxxxxxx
656
/*
Tanya Kler
ARTG2260: Programming Basics
Final Project - Tanya's Pizzeria
Based on the game Papa's Pizzeria
Avatar and customer images are from original papas pizzeria gaame from Flipline Studios.
Pick an avatar then take customers orders and create corresponding pizzas. Add toppings by clikcing on them and dragging to pizza, let pizza cook in oven for correct amount of time, and cut to desired number of slices. Customers will score your pizza and give you a tip based on how well you matched their order.
funcion classes:
- sketch.js
- gamestates.js
classes:
- customer.js
- order.js
- pizzacut.js
- player.js
- toppings.js
*/
//set up
let stage = 0; //stage of gameplay (toppingss baking, etc)
let gameState = 0; //state of game (start, gameplay, and end)
//variables
let level = 1; //level
let dayOver = false; //is day over?
let customersLeft = 1; //number of customers left in a level
let avatar = ""; //avatar
//characters
//players
let roy;
let joy;
//customers
let allCustomers = []; // all possible customers
let gameCustomers = []; //customers used in game
let currentCustomer = 1; //num of customer you are on
let currCustomer; //current custoemr you are on
let penny; //penny variable usesd for testing
//toppings
let dropped = false; //if topping is dropped while adding
let locked = false; //if topping is being held on to and able to be dragged
let drawD = false; //should dough ball be drawn
let drawS = false; //should sauce be drawn
let drawC = false; //should cheese be drawn
let drawT = false; //should toppings be drawn
let alreadyDrawn = false; //has this topping been drawn already
let toppingsAdded; //toppings added to pizza
let o; //order created to store pizza made by player
let created; //using o, pizza created by player
let currToppings = []; //current toppings on pizza
let currTop; //curreent topping beeing added
let numCuts = 0; //number of pizza cuts
let cuts = []; //cuts stored in array to draw
let topTypesOn = []; //types of toppings on pizza with no duplicates
let timer = 0; //timer for how long pizza has been cooked for
//pizza cut line points
let x1; //first x point for pizza cut line
let y1; //first y point for pizza cut line
let tscore = 0; //scoroe for topppings
let oscore = 0; //score for oven
let cscore = 0; //score for cutting
let score = 0; //pizza score
let dayScore = 0; //score in one day
let totalScore = 0; //score across game
//images
//avatars
let royImg;
let joyImg;
//backgrounds
let lobby;
let cView;
let doughView;
let sauceView;
let cheeseView;
let toppingsView;
let oven;
let cutting;
let scoreView;
//customers
let pennyImg;
let pennyHalf;
let alImg;
let alHalf;
let jamesImg;
let jamesHalf;
let hankImg;
let hankHalf;
let johnnyImg;
let johnnyHalf;
let utahImg;
let utahHalf;
let lisaImg;
let lisaHalf;
let trishnaImg;
let trishnaHalf;
//toppings
let mushroom;
let olive;
let pineapple;
let pepperoni;
let pepper;
// sound
let bell;
function preload() {
joyImg = loadImage("joy.png");
royImg = loadImage("roy.png");
lobby = loadImage("lobby.png");
cView = loadImage("cView.png");
doughView = loadImage("dough.png");
sauceView = loadImage("sauce.png");
cheeseView = loadImage("cheese.png");
toppingsView = loadImage("toppings.png");
oven = loadImage("oven.png");
cutting = loadImage("cutting.png");
pennyImg = loadImage("Penny.png");
pennyHalf = loadImage("PennyHalf.png");
alImg = loadImage("Alberto.png");
alHalf = loadImage("AlbertoHalf.png");
jamesImg = loadImage("James.png");
jamesHalf = loadImage("JamesHalf.png");
hankImg = loadImage("Hank.png");
hankHalf = loadImage("HankHalf.png");
johnnyImg = loadImage("Johnny.png");
johnnyHalf = loadImage("JohnnyHalf.png");
utahImg = loadImage("Utah.png");
utahHalf = loadImage("UtahHalf.png");
trishnaImg = loadImage("Trishna.png");
trishnaHalf = loadImage("TrishnaHalf.png");
lisaImg = loadImage("Lisa.png");
lisaHalf = loadImage("LisaHalf.png");
mushroom = loadImage("Mushroom.png");
olive = loadImage("Olive.png");
pineapple = loadImage("Pineapple.png");
pepperoni = loadImage("Pepperoni.png");
pepper = loadImage("GreenPepper.png");
scoreView = loadImage("score-17.png");
bell = loadSound("bell.mp3");
}
//sets up canvas and all the customers available
function setup() {
createCanvas(1000, 800);
allCustomers = ["penny", "alberto", "james", "hank", "johnny", "utah", "trishna", "lisa"];
}
//draws game depending on gamestates
function draw() {
background(243, 230, 255);
switch(gameState) {
case 0: //avatar screen
startScreen();
break;
case 1: //game
game();
break;
case 2: //end game screen and play again button
end();
break;
}
}
//handles button presses and game state traversal
function mouseClicked(){
switch(gameState) {
case 0:
level = 1;
customersLeft = 1;
totalScore = 0;
if(overRoy){
avater = "roy";
gameState++;
} else if(overJoy) {
avater = "roy";
gameState++;
}
generateCustomers();
break;
case 1:
switch(stage){
case 1:
if (takeOrder) {
bell.stop();
tscore = 0;
oscore = 0;
cscore = 0;
score = 0;
topTypesOn = [];
currToppings = [];
numCuts = 0;
cuts = [];
toppingsAdded = false;
stage++;
}
break;
case 2:
if (startOrder) {
o = new Order();
stage++;
}
break;
case 6:
if (toOven && toppingsAdded) {
timer = 0;
topTypesOn = toppingTypes(currToppings);
stage++;
}
break;
case 7:
if (doneBaking) {
stage++;
}
break;
case 8:
if (donePizza) {
//created pizza that represents the pizza made by player
o.createPizza(topTypesOn, timer, 2*numCuts);
//resets everything for next customer
dropped = false;
locked = false;
drawD = false;
drawS = false;
drawC = false;
drawT = false;
alreadyDrawn = false;
stage++;
}
break;
case 9:
getScore(currCustomer.getOrder(), o);
customersLeft--;
stage++;
break;
case 10:
if (nextCustomer) {
if (customersLeft>0){
nextCust();
bell.play();
stage = 1;
} else if(level===1){
nextCust();
level = 2;
customersLeft = 3;
stage++; //to stage 11
} else if(level===2){
nextCust();
level = 3;
customersLeft = 3;
stage++; //to stage 11
} else if(level===3){
gameState++; //to gameState 2;
}
}
break;
case 11:
dayScore = 0;
bell.play();
stage = 1;
break;
}
break;
case 2:
if (playAgain){
gameState = 0;
}
break;
}
}
//handles starting the game
function keyPressed() {
if (keyCode === 32 && stage === 0) {
bell.play();
stage++;
//add doorbell sound here
}
}
//ceates custoomers for the game from all the possible choices
function generateCustomers(){
//make a copy
let copy = [];
for (let j = 0; j < allCustomers.length; j++){
let p = allCustomers[j];
copy.push(p);
}
for(let i = 0; i < 8; i++) {
//add name to game ensuring no duplicates
let c = random(copy);
let ind = copy.indexOf(c);
gameCustomers[i] = c;
copy.splice(ind, 1);
}
currCustomer = new Customer(gameCustomers[0]);
}
//gets next customer
function nextCust(){
currentCustomer++;
currCustomer = new Customer(gameCustomers[currentCustomer]);
}
//gets score of pizza
function getScore(order, pizza) {
let toppingsScore;
let ovenScore;
let cutScore;
//getting toppings score
let extraToppings = 0;
let missingToppings = order.getNumToppings();
for (let i = 0; i <pizza.getNumToppings(); i++){
let isIn;
isIn = false;
for (let j = 0; j < order.getNumToppings(); j++){
if (!isIn){
isIn = (pizza.toppings[i] === order.toppings[j]);
}
if (j === order.getNumToppings()-1){
if(!isIn){
extraToppings++;
}
}
}
if (isIn){
missingToppings--;
}
}
toppingsScore = 100 - ((missingToppings + extraToppings)*20);
//getting bake time score
if (order.cookTime > pizza.cookTime) {
ovenScore = 100 - (order.cookTime - pizza.cookTime)*4;
} else {
ovenScore = 100 - (pizza.cookTime - order.cookTime)*4;
}
//getting slices score
if (order.numSlices > pizza.numSlices) {
cutScore = 100 - (order.numSlices - pizza.numSlices)*10;
} else {
cutScore = 100 - (pizza.numSlices - order.numSlices)*10;
}
//making sure negative scores don't happen
if (cutScore < 0){
cutScore = 0;
}
if (ovenScore < 0){
ovenScore = 0;
}
tscore = toppingsScore;
oscore = ovenScore;
cscore = cutScore;
score = (toppingsScore + ovenScore + cutScore) / 3;
dayScore += score;
totalScore += score;
}
//handles adding toppings to pizza and cutting
function mousePressed() {
switch(stage) {
case 3:
if (overDough) {
dropped = false;
locked = true;
} else {
locked = false;
}
break;
case 4:
if (overSauce) {
dropped = false;
locked = true;
} else {
locked = false;
}
break;
case 5:
if (overCheese) {
dropped = false;
locked = true;
} else {
locked = false;
}
break;
case 6:
if (overRoni) {
alreadyDrawn=false;
dropped = false;
locked = true;
currTop = new Topping("pepperoni", mouseX - 40, mouseY - 40);
} else if(overMush) {
alreadyDrawn=false;
dropped = false;
locked = true;
currTop = new Topping("mushroom", mouseX- 40, mouseY- 40);
} else if(overPep) {
alreadyDrawn=false;
dropped = false;
locked = true;
currTop = new Topping("pepper", mouseX- 70, mouseY- 70);
} else if(overPine) {
alreadyDrawn=false;
dropped = false;
locked = true;
currTop = new Topping("pineapple", mouseX - 40, mouseY - 40);
} else if(overOlive) {
alreadyDrawn=false;
dropped = false;
locked = true;
currTop = new Topping("olive", mouseX- 40, mouseY- 40);
}else {
locked = false;
}
break;
case 8:
if(!donePizza){
x1 = mouseX;
y1 = mouseY;
cuts.push(new PizzaCut(x1, y1, mouseX, mouseY));
}
break;
}
}
//handles dragging toppings and cutting pizza
function mouseDragged() {
switch(stage){
case 3:
if (locked) {
drawD = true;
}
break;
case 4:
if (locked) {
drawS = true;
}
break;
case 5:
if (locked) {
drawC = true;
}
break;
case 6:
if (locked) {
drawT = true;
}
break;
case 8:
if (!donePizza){
if (cuts.length>0) {
cuts[cuts.length-1].x2 = mouseX;
cuts[cuts.length-1].y2 = mouseY;
}
}
break;
}
}
//handles adding toppings and adding cuts to pizza
function mouseReleased() {
switch(stage) {
case 3:
if (overPizza && locked){
locked = false;
stage++;
} else {
dropped = true;
drawD = false;
}
break;
case 4:
if (overPizza && locked){
locked = false;
stage++;
} else {
dropped = true;
drawS = false;
}
break;
case 5:
if (overPizza && locked){
locked = false;
stage++;
} else {
dropped = true;
drawC = false;
}
break;
case 6:
if (overPizza&& locked){
locked = false;
let ind = currToppings.length;
drawT = false;
if (!alreadyDrawn){
toppingsAdded = true;
if (currTop.type === "pepper") {
currToppings[ind] = new Topping(currTop.type, mouseX - 70, mouseY -70);
} else {
currToppings[ind] = new Topping(currTop.type, mouseX-40, mouseY-40);
}
}
alreadyDrawn = true;
} else {
dropped = true;
drawT = false;
locked = false;
}
break;
case 8:
if (!donePizza){
numCuts++;
}
break;
}
}
//draw dough while dragging to pizza
function drawDough(){
noStroke();
fill(240, 180, 94);
ellipse(mouseX, mouseY, 100, 70);
}
//draw sauce while dragging to pizza
function drawSauce(){
noStroke();
fill(195, 71, 34);
ellipse(mouseX, mouseY, 100, 100);
}
//draw cheese while dragging to pizza
function drawCheese(){
noStroke();
fill(255, 252, 119);
ellipse(mouseX, mouseY, 100, 100);
}
//draw one topping when dragging
function drawCurrTop(){
if (currTop.type === "pepper") {
currTop.display2(mouseX - 70, mouseY - 70);
} else {
currTop.display2(mouseX - 40, mouseY - 40);
}
drawToppings();
}
//draw all toppings on pizza
function drawToppings(){
for (let i = 0; i < currToppings.length; i++){
currToppings[i].display();
}
}
//draw lines representing tthe cuts on the pizza
function drawLines(){
for(let i = 0; i < cuts.length; i++) {
cuts[i].display();
}
}
//create an array of the types of toppings on the pizza
function toppingTypes(toppings){
let newArray = [];
for(let i = 0; i < toppings.length; i++){
if(!newArray.includes(toppings[i].type))
newArray.push(toppings[i].type);
}
return newArray;
}