Hey there, in this lecture, we will implement shooting. For that we create a bullet object, that object will always keep moving, and when it goes out of the room, it will be destroyed. So we'll make it so when the player presses the space key, a bullet instance is created at the player's position, this way the player will be able to shoot. So let's get to it. I've imported a sprite for the bullet here. Now make sure that its origin is set to middle center.
Now we'll go to objects and create a new one, I'll name it or bullet, I'll assign the bullets cried to it. Now in this object, a lot of the creative end in this event or at the set speed, action, or change direction to vertical since I wanted to move up and to mover, the why needs to be reduced. So I'll set the speed to minus 20. Now it'll go up at a high speed. Now we need the outside room event. In this event allowed to destroy this transaction.
Now we'll open the room and go to the Layers panel. I'll create a new instance layer and name it bullet. Now this is the layer where the bullets will be created. It will be below the stances layer so that the bullets appear below the player ship. Now I'll open up layer, I'll click on Add event and go to the key press events, as you know the key down event thrown as long as the key is being held. But the key press events run when you first hit the key only once, so you have to release the key and then hit it again to run the event again, salsa like the space key.
Now in this event under the Create instance action for the object or select or bullet. For the x, y position, I'll enter x and y, x and y are built in variables to store the position of an instance since this action is running in the player object, the bullet will be created at the player position. Now here I'll enter the layers name, which is bullet. And again, I'll leave target empty. Now around the game, I can shoot by hitting space. Now I have a small challenge for you.
The challenge is to create two bullet instances when the player shoots instead of one. Here's a hint, you can add or subtract a value to the explanation of a new instance to place it to the left or the right. Now let's move on to the next lecture we will start working on the enemies