Search Array with certain features

Asked

Viewed 35 times

1

Hello, I am developing a very basic game with Javascript, but I came across a little thing that I could not solve so far, the question would be, I have an Array, in which I include randomly 28 objects, and these objects have a position x, y and color, which are also determined randomly, when filling this Array, they are displayed through the element <canvas>, what I would be trying to do, would be, check if the elements are aligned on the screen (in groups of 3 or more) and remove them from the Main Array, as the positions are determined randomly, elements may be displayed in the order they are stored in the Array or not

Ex:

Screenshot Game

the green cubes in the image follow the pattern, like in those old games, I have a "demo" on Codepen, I hope I was able to explain

  • It has how to better describe what the elements would be aligned in groups?

  • as in the image above, three elements of the same color formed a combination on screen, type the position of item 1 is {x: 40, y: 0, color: 'green'} in item 2 {x: 40, y: 40, color: 'green'} and item 3 {x: 40, y: 80, color: 'green'} imagining that it was a Cartesian plane, these three items would be aligned vertically, imagine an array full of items with these same characteristics, what I wanted to do is remove all those that enter this pattern (3 items or more) if their color is equal, taking into account, the items aligned horizontally and vertically

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.