• Elvin Ou

Adding data source

Continuing what I did from last creating the game for halloween, I added a new class of bats that the users are supposed to avoid while trying to collect candy. I had difficulties when I was trying to make the if statements for the game when the arrays becomes "0" (when all the floating candy are collected, it is going to trigger another function). I thought it was as easy as making an if statements saying "if (game1.length == 0){ .....}", but it did not work as what I expected. I thought there was a problem in my code so I started seriously reading and organizing the code I did for the game class etc. Eventually after I worked with Eva, she told me that I should try the if statements/ arrays backward, using the first variable I = game1.length, and then it decreases.. However that did not quite work well, so we went back to watch Shifman's video about this and figure out the way to fix this is simple as

for (var i = game1.length - 1; i >= 0; i--) {

game1[i].run();

if (game1[i].isNearCandy(x,y ) ){

game1.splice(i, 1);

console.log(game1.length);

if (game1.length == 0) {

background(0);

noLoop();

output=1;

serial.write(output + "\n");

}

}

}

Eventually, the whole game works and it just needs to be made visually complete.

In terms of data source, HTML, API, JSON.. I am so so confused and not even sure how to start... Instead of creating a new project of my own, I decided to just look at quiz and realized I still did not know what was going on. Instead of that I eventually decided to just try to read what people write for the quiz and see if I understand them or not, and believe me, it was a process.. And then I rewatched Shiffman's video...