The Unit Circle is a circle with a radius of 1. The unit circle identifies coordinates by using the angles of sine, cosine, and tangent. The image below is an example of the unit circle:
The sine of an angle in a video game tells us that the motion is changing for y axis. So this means that an object when in motion is changing by the y axis.
The cosine of an angle in a video game tells us that the motion is changing for the x axis.
The sine and cosine of an angle helps give the coordinates of an image because they give where the x and y coordinates are.
To finish off my game I need to swap the images when the key “b” is pressed.
In order to do that I need to add another image to my program and another variable.
a typed out explanation (or guess) of why the movement code needs to be so complicated
In version 4 of my program I added the image movement code by pressing the key “b” – (the movement code is highlighted in yellow):
The reason why the movement code is so complicated because the x and y movement are different. The cosine is how the x motion changed and the sine of y is how the y motion is changed. The spiral now accelerates and moves across the window where it does not come back on the screen.
In version 5 the spiral teleports to the other edge of the screen when it disappears of the screen.
The code highlighted shows how the spiral is able to transport to different edges of the screen when it goes off the screen.
Rotation for an image needs the following code that is highlighted in yellow:
Since there is no keyReleased code the rotation on the spirals is going to continue until the game is not running anymore. In the next version (03) I added the keyReleased which stops the rotation if the key is no longer being pressed.
In Processing there is a number of steps you have to take to place an image in a window as shown below.
The code is the following:
Moving forward with buttonFly, I have to add the following behaviors to my image
- Motion + Acceleration
- Swapping the image
To finish off my game I had to create different speeds for my squares.
The middle square – which is controlled by the users click of the control button, moves faster than the right and left squares.
The left square – chases the middle square at a slower speed than the middle and right square.
The right square – chases the middle square at a faster speed than the left square but slower than the middle square.
In order to not have my squares get stuck on top of each other I had to set a timer which starts off the squares at different times.
The slow square is the left square. Here is the code that I used to chase the middle square. The timer sets off the square to move, this time period gives the user some time to move the middle square and give it a “head start”.
For the right square I did the same thing but changed the starting time higher than the left square.
The Final game looks something like this.