xxxxxxxxxx
// Instructions:
//You (player) are a cat, trying to collect as much food as
//possible. There are good foods, and bad foods.
//The bad foods are poisonous to cats,so be careful!
let cat;
let sushi;
let shrimp;
let waffle;
let bagel;
let fries;
let banana;
let dumpling;
let chocolateBar;
let garlic;
let grapes;
let score = 0;
//let gameOver = false;
let coinSound;
function preload() {
coinSound = loadSound("coin.wav");
} // Sound effects goes here
function setup() {
new Canvas(windowWidth, windowHeight);
cat = new Sprite (0, height/2);
//Loading in food sprites
sushi = new Group();
sushi.width = 20;
sushi.height = 20;
sushi.image = '🍣';
for (let i = 0; i < 5; i++) {
let su = new sushi.Sprite();
su.x = random(width);
su.y = random(height);
}
shrimp = new Group();
shrimp.width = 20;
shrimp.height = 20;
shrimp.image = '🍤';
for (let i = 0; i < 5; i++) {
let sh = new shrimp.Sprite();
sh.x = random(width);
sh.y = random(height);
}
waffle = new Group();
waffle.width = 60;
waffle.height = 60;
waffle.image = '🧇';
for (let i = 0; i < 3; i++) {
let w = new waffle.Sprite();
w.x = random(width);
w.y = random(height);
}
bagel = new Group();
bagel.width = 50;
bagel.height = 50;
bagel.image = '🥯';
for (let i = 0; i < 3; i++) {
let b = new bagel.Sprite();
b.x = random(width);
b.y = random(height);
}
fries = new Group();
fries.width = 50;
fries.height = 50;
fries.image = '🍟';
for (let i = 0; i < 4; i++) {
let f = new fries.Sprite();
f.x = random(width);
f.y = random(height);
}
banana = new Group();
banana.width = 40;
banana.height = 40;
banana.image = '🍌';
for (let i = 0; i < 4; i++) {
let ban = new banana.Sprite();
ban.x = random(width);
ban.y = random(height);
}
dumpling = new Group();
dumpling.width = 20;
dumpling.height = 20;
dumpling.image = '🥟';
for (let i = 0; i < 5; i++) {
let d = new dumpling.Sprite();
d.x = random(width);
d.y = random(height);
}
chocolateBar = new Group();
chocolateBar.width = 40;
chocolateBar.height = 40;
chocolateBar.image = '🍫';
for (let i = 0; i < 5; i++) {
let c = new chocolateBar.Sprite();
c.x = random(width);
c.y = random(height);
}
garlic = new Group();
garlic.width = 25;
garlic.height = 25;
garlic.image = '🧄';
for (let i = 0; i < 4; i++) {
let g = new garlic.Sprite();
g.x = random(width);
g.y = random(height);
}
grapes = new Group();
grapes.width = 40;
grapes.height = 40;
grapes.image = '🍇';
for (let i = 0; i < 5; i++) {
let gr = new grapes.Sprite();
gr.x = random(width);
gr.y = random(height);
}
}
function draw() {
background('rgb(117,164,117)');
//Camera POV
camera.x = cat.x
camera.y = cat.y
// Keyboard commands
cat.speed = 5;
if (kb.pressing('up')) {
cat.direction = -90;
} else if (kb.pressing('down')) {
cat.direction = 90;
} else if (kb.pressing('left')) {
cat.direction = 180;
} else if (kb.pressing('right')) {
cat.direction = 0;
} else {
cat.speed = 0;
}
// Score Display
fill('rgb(203,158,219)');
textSize(30);
text(`Score: ${score}`, 20, 50);
// Player collections
cat.overlaps(sushi, collectsushi);
cat.overlaps(shrimp, collectshrimp);
cat.overlaps(waffle, collectwaffle);
cat.overlaps(bagel, collectbagel);
cat.overlaps(fries, collectfries);
cat.overlaps(banana, collectbanana);
cat.overlaps(dumpling, collectdumpling);
cat.overlaps(chocolateBar, collectchocolateBar);
cat.overlaps(garlic, collectgarlic);
cat.overlaps(grapes, collectgrapes);
//cat.text = score;
}
//Collections
// Good Foods
function collectsushi(p, su) {
//coinSound.play();
su.remove();
score +=2;
}
function collectshrimp(p, sh){
//bigCoinsSound.play();
sh.remove();
score +=2;
}
function collectwaffle(p, w){
//poisonousCoinsSound.play();
w.remove();
score += 5;
}
function collectbagel(p, b) {
coinSound.play();
b.remove();
score +=4;
}
function collectfries(p, f) {
coinSound.play();
f.remove();
score +=4;
}
function collectbanana(p, ban) {
coinSound.play();
ban.remove();
score +=3;
}
function collectdumpling(p, d) {
coinSound.play();
d.remove();
score +=2;
}
// Poisonous Foods
function collectchocolateBar(p, c) {
coinSound.play();
c.remove();
score -= 5;
}
function collectgarlic(p, g) {
coinSound.play();
g.remove();
score -= 5;
}
function collectgrapes(p, gr) {
coinSound.play();
gr.remove();
score -= 5;
}