Last week in ICM class, I learnt how to re-organizing my code by using functions.
After I re-organized the three codes in my last homework, I tried to learn and write something new.
I tried to learn Array from video 6.1 - 6.5, and also got some inspirations from Coding Challenge #1.
The code in Coding challenge #1 is written in Processing, so I rewrote it in P5.js. I wrote a star function and put it in an array, and then I used for loop to iterate over its contents. So there are 800 stars appearing in random position at each time the draw function runs.
I also made the background color change with the mouse movement.
Then I began to write the spaceship part. I made three functions for the spaceship, the spaceship function, the shot function and the open fire function. The first one is to draw the spaceship. The second one is to draw the shots. The last one is for making the shots move.
So the main part of my code, without those functions I made, looks like this.
Click to see the whole codes in my Github.
What can be updated?
- Make the spaceship move based on the arrow keys (LEFT, RIGHT, UP, DOWN).
- Make the shots change directions when the spaceship goes to the left or right. (Maybe rotate the shots by a certain degree to let them always point toward the center.)