xxxxxxxxxx
75
let agent;
let target;
let targetsImg = [];
let candy;
let lollipop;
let cottonCandy;
let pug;
let points = 0;
let gifFrames = [];
const numberOfFrames = 8;
const agentW = 112;
const agentH = 74;
const targetSize = 48;
function preload(){
candy = loadImage('assets/candy.png');
lollipop = loadImage('assets/lollipop.png');
cottonCandy = loadImage('assets/cotton-candy.png');
iceCream = loadImage('assets/ice-cream.png');
cupcake = loadImage('assets/cupcake.png');
for (let i = 1; i <= numberOfFrames; i++) {
let framePath = `assets/gif/pug-${i}.gif`;
let frameImage = loadImage(framePath);
gifFrames.push(frameImage);
}
soundFormats('mp3');
bark = loadSound('assets/sound/bark');
}
function setup() {
createCanvas(1000, 500);
targetsImg.push(candy);
targetsImg.push(lollipop);
targetsImg.push(cottonCandy);
targetsImg.push(iceCream);
targetsImg.push(cupcake);
agent = new Agent(
random(agentW, width-agentW),
random(agentH, height-agentH),
agentW,
agentH,
gifFrames);
target = new Target(
targetSize,
random(targetSize, width-targetSize),
random(targetSize, height-targetSize),
targetsImg);
}
function draw() {
background(200);
agent.follow(target.position);
target.show();
agent.show();
if(agent.position.dist(target.position) < agent.h/2){
target.randomize();
bark.play();
points++;
}
fill(0);
textSize(25);
textStyle(BOLD);
text("Score: " + points, 10, 25);
console.log("Score: " + points);
}