Step 2

Creating the first enemy


Create a new function that will be used to create our enemy. Call it “createEnemy”

Here we see a block having to do with velocity, “vx (velocity x)”. This block is found similary we got the previous acceleration block, by getting the “set mySprite x” block from Sprites and changing it to “vx (velocity x)”.

Velocity is how fast something changes its position. Acceleration is how fast something changes its speed. An object with a high vecloity moves quickly, an object with a high acceleration speeds up quickly.

We also make sure there is a 50% chance this enemy will spawn, to help add variety in our game.

Creating the second enemy


Still inside the same function, under the else, complete the code shown below.

This is basically the same code as before, the only differences are now the x we spawn at is 165 instead of 5 and that the vx (velocity x) is -25 instead of 25.

This code will now spawn a second enemy type, this time moving to the right.

Lastly, we tell the enemy sprite to bounce when it hits a wall, making it move in the opposite direction. We get this block by getting the “set mySprite stay in screen” block and changing it.

Spawning and testing the enemies


Lastly, add the code shown to the right to spawn your enemies. There should be enemies spawning on both sides now!