The workshop I attended in this recitation is the Object Oriented Programming workshop.
What the exercise required us to accomplish in the end was class objects with certain level of interactivity. In this exercise, I tried to create a design that enables users to use the mouse to avoid the incoming blocks.
Specifically, I first created a Ball class, where they have a set of default value for X and Y coordinates. Then, I created the display function in order to draw an ellipse and indicate the position of the point.
In the next class Obstacles, I’ve also created the X and Y coordinates in the constructor. In this class, I added another parameter speed, which would be used in the move function and let it move according to the preset speed value. In the display function, I used the rect() function to show a 20 * 20 rectangle drew on the X and Y coordinates.
In the main code, I first declared the ArrayList obs, which would hold the obstacles objects. In the main draw loop, I used mouseX and mouseY as parameters passing into the Ball class, which would make the mouse’s position as the position of the ellipse. The obstacles, then, will be generated at the right side of the screen with random height and speed. The obstacles then would move leftwards, and the user need to avoid being hit by the obstacles by carefully manipulating the position of the mouse.