How to make Fortnite in Scratch ep.4

How to make Fortnite in Scratch ep.4
ok-scratch
Let's start spawning enemies and make sure they move naturally with the background scroll!
Starter
Projects
Starter Project
Sample
none
Difficulty
Tags

Make sure to jot down the URL of your Scratch project in progress. It’s a lifesaver when you’re ready to dive back in.

LOADING...

This record is saved on the computer you’re currently using. So, if you switch to a different computer, you won’t see it there.

Last time, we nailed the building aspect of Fortnite! This session, we'll lay the groundwork for another key feature: battle. That's right, it's time to introduce our enemies. This time, Giga will play the role of our formidable enemy. Thanks, Giga!

Today's Goal

ok-scratch ok-scratch

You can see from the short video that enemies are appearing. They aren't attacking yet, but we'll implement it so that three types of enemies appear randomly according to a set pattern.

Stage

Open the stage.

Variable 'DISTANCE'

Create a new variable named 'DISTANCE'. This variable will hold the distance the player has traveled.

Set 'DISTANCE' to 0.

After broadcasting 'Prepare Scrolling', change 'DISTANCE' by 1.

Preview

ok-scratch ok-scratch

It's a bit hard to see, but as the player moves forward and the background scrolls, the DISTANCE variable is being incremented.

Sprite 'Enemy'

Alright! Let's open the 'Enemy' sprite.

Start by hiding the sprite.

Let's wait for 3 seconds. This delay is to prevent enemies from appearing immediately as the game starts, which can confuse players. It's fairer this way.

Place a forever block.

Place an 'if' block with an equality condition inside the loop.

Create the expression as described below.

Insert this expression into the left of the equality condition.

ok-scratch ok-scratch

This condition will be true every time the player advances 40 coordinates.

Create clone of myself and wait for 1 second.

Block Definition 'Set Position'

Create a new block definition named 'Set Position' that sets the enemy's initial position.

When I start as a clone, set position.

Variable 'enemy type'

Create a new variable named 'enemy type' for this sprite only.

In the 'Set Position' definition, randomly set 'enemy type' to a value between 1 and 3.

Then change the costume to match the value of 'enemy type'.

ok-scratch ok-scratch

By the way, the enemy costumes are named "enemy1," "enemy2," and "enemy3," as shown in the screenshot below.

Set the position of each enemy

Before placing enemies, make sure the stop button is pressed. Then, drag and drop the enemies to the desired position on the screen.

This will change their X and Y positions' values, so copy the Y coordinate value to use it shortly afterward.

enemy1

Create an 'if' block to check if 'enemy type' is 1.

Point in direction 90, set x to 240, and then set y to the copied value, which in my case was -138.

enemy2

Do the same for when 'enemy type' is 2.

Drag and drop it and copy the y position.

Then create an 'if' block and within it, point in direction 90, set x to 240, and y to the copied value.

enemy3

Next, do the same for 'enemy3'.

For 'enemy3', since it is facing diagonally, set 'point in direction' to -125, x to 240, and assign y to the value determined by dragging and dropping.

Finally, show it.

Sprite 'Stairs'

All the enemies start at an X coordinate of 240, which means they appear on the right edge of the screen. As the background scrolls, we need to adjust the enemies' positions accordingly. We've already implemented this for the stairs and walls sprites, so it would be easiest to simply copy that process from the stairs sprite. This will keep the implementation straightforward and consistent.

Open the 'Stairs' sprite.

Drag and drop 'Scroll' and 'Off Screen' definitions to the 'Enemy' sprite.

Sprite 'Enemy'

Back to the 'Enemy' sprite.

Add a forever block and place the 'Scroll' and the 'Off Screen' definitions within it.

Preview

Awesome! Now enemies are continuously appearing from the edge of the screen and moving naturally with the scroll. That sets up the basics for enemy behavior. Next, let's implement attacks from these enemies! We'll make our Fortnite-style project even more exciting by dodging enemy bullets! Let's get to it!

Thank you for reading! Thank you for reading!
Bookmark and share this article, if you like.

Scratch Games

    • You can find popular scratch projects with reviews.