In my gaming project, I am creating a unique experience where the player needs to collect all the words from a given array. Currently, I am utilizing the shift() method to eliminate elements, as demonstrated in the code snippet below:
if ( bX + bird.width >= words[i].x
&& bX + bird.width <= words[i].x + 40
&& bY+bird.height >= words[i].y
&& bY+bird.height <= words[i].y + 40){
words.shift();
};
Here is the array being referenced:
var nouns = ["dog", "boy", "house","farm", "phone", "plane", "doctor"];
var words = [];
for (var i = 0; i < 20; i++) {
words.push(new word(i * 161 + 200, Math.floor(Math.random() * (400 - 10 + 1)) + 10, nouns[i])); }
However, I have encountered an issue where if the player misses the initial element of the array ("dog"), they are then unable to capture any of the subsequent elements. How can I modify this to allow the player to access the array's elements in any order?