6 November 2016

Day Seven - Space Invaders

Hello everyone, bit by bit here and today I will explain how I made a basic Space Invaders game.

 First I will explain the enemy's code. There is a while true block: it's use is like a forever loop. The repeat 4 allows the enemy to move with the change X block and the pause ms slow down the enemy. This apply's for both loops except the other one goes in the opposite direction. 


The bomb mechanism works by changing the y of the bomb. It spawns on the position of the enemy with the set sprite block (it was also used at the top of the section of code, generating the ship at (2,4) and the enemy at (0,0). Then, it immediately fires with the change y block, which is in a repeat 4 block. It is slowed down by 200ms. But if the bomb misses, which the micro:bit can tell with the if statement, y of bomb is bigger or equal to row 4. Next, the bomb is sent back to its original position and its brightness 0 so it isn't seen. Above that is the if statement, bomb touching ship: game over.  Then duplicate it on to the other movement loop.



 OK, so now lets see how the ship is controlled. There is a when button A pressed: change  x of  ship by -1. This is the same for when B is pressed except -1 is 1.

Now, lets get on to the ship's firing system. When A + B are pressed together, missile is generated at ship, then there is a repeat 4 loop under and the y of the missile is changed by  -1 (or up as the micro:bit grid is the opposite of our up.) The next if statement is similar to the bomb one. If missile is equal to or greater than 0, it resets the position and the brightness is 0. In the first if statement is a second, if missile is touching enemy: change score by one.


My channel: https://www.youtube.com/channel/UCBM75CLZnKs5J2Ri2UpmAg 








No comments:

Post a Comment