Homework due Monday November 6: Deleting Balls using Light Sensors

The game I created uses light sensors to delete moving balls on the screens. The balls are in 6 colors: red, yellow, blue, orange, purple, and green. On my Arduino, I use 3 sensors color-coded red, yellow, and blue.

If the red sensor is covered, red balls will be deleted. The same applies to the yellow and blue sensors. When the red and yellow sensors are covered at the same time, orange balls will be deleted (red + blue = purple; blue + yellow = green). 

Because I want the game to keep adding balls after some of them have been deleted, I tried to find a function that can add objects to an array, and there is actually one that does this: append(). I used this tutorial by Daniel Shiffman to learn how to use append(). On the website Learning Processing by Daniel Shiffman, there are also a lot of simple but very useful examples. It is a great resource to learn Processing. 

The difficulty that I encounter with this project is that in order to delete the balls, I change their color to white. Thus, they only disappear, not really deleted from the program. After a while, there will be too many balls on the sketch and the program will run very slowly. I have not found a way to remove certain objects from an array yet, but I thought of restarting the program after a period of time to free up memory. Thanks to Michael, I have been able to restart my game by resetting the array. However, the reset works for the about first 10 times, but after that, the reset does not make the balls disappear anymore. I have not figured out this problem yet, but I think it has something to do with the program taking up too much of my computer’s memory. 


Arduino code

Processing code


Leave a Reply

Your email address will not be published. Required fields are marked *