xxxxxxxxxx
65
// Vivianna Mo
// Intro to IM - Michael Shiloh
// Oct. 13, 2022
// Midterm Project
// Description: A game where you catch the food falling, and if you miss one it's game over!
// Things needed for this: one shape, one image, one sound
// one on screen text, OOP, instruction slide
let gameState = 'play';
let bkgImg;
let character;
let addCharacter;
let foods = [];
let addFoods = [];
function preload() {
bkgImg = loadImage("Assets/background.jpg")
character = loadImage("Assets/noFace.png");
for (let i = 0; i < 5; i++) {
foods[i] = loadImage("Assets/food" + i + ".png")
}
}
function setup() {
createCanvas(685, 575);
addCharacter = new NoFaceCharacter();
addFoods.push(new Food()); // This makes sure that the food keeps on getting added
}
function draw() {
background(220);
drawGame();
}
function drawGame() {
bkgImg.resize(685, 575);
image(bkgImg, 0, 0);
addCharacter.show();
// From The Coding Train Flappy Bird Coding Challenge:
// https://editor.p5js.org/codingtrain/sketches/FtBc2BhHM
for(let i = addFoods.length - 1; i >= 0; i--) {
addFoods[i].rainingFood();
addFoods[i].show();
}
// A new food is pushed every time the frameCount is divisible by 50 or 100
if(frameCount % 50 == 0) {
addFoods.push(new Food());
} else if(frameCount % 100 == 0) {
addFoods.push(new Food());
}
// print(frameCount);
}