How to make Fortnite in Scratch ep.6

How to make Fortnite in Scratch ep.6
ok-scratch
Let’s implement the player’s attack, enemy defeat, and a game-over process when the player gets hit by enemy attacks.
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 successfully implemented enemy attacks and the animations for walls and stairs breaking when hit. This time, we’ll work on the player’s attack, defeating enemies, and creating a game-over process when the player gets hit by enemy attacks. Let’s dive in!

Today's Goal

Player Attack

Game Over

ok-scratch ok-scratch

Ahh! Our beloved Scratch Cat has fallen to Giga’s merciless bullet! Just kidding, haha! 😄

Sprite 'Player'

First, let’s make the player fire bullets. When the space key is pressed, bullets will shoot straight forward from the player’s current position. Let’s set that up!

Open the 'Player' sprite.

Block Definition 'Player Attack'

Create a new block definitiono named 'Player Attack'.

Place this definition in the forever loop under the green flag.

In the definition, check if the space key is pressed.

Switch costume to 'shoot'.

This one! Nice isn't it?

Message 'Player Attack'

Create a new message named 'Player Attack'.

Place this broadcasting block inside of the 'if' block.

Then, wait until the space key is released to prevent continuous firing. Depending on game balance, allowing rapid fire could be fine, but since there’s no ammo limit here, it would be overpowered and consume too many clones. So, we’ll stick to a single-shot design for now.

Sprite 'Player Bullet'

Alright, let’s implement the bullet so that when it receives the message, it starts moving straight from the specified position.

Hide the sprite itself when the game starts.

Create a clone when the "Player Attack" message is received.

Set the X and Y values by including an addition operation for X and a subtraction operation for Y.

Set X to Player's x position + 30 and Y to Player's y position - 5. This will determine the initial position from which the bullet is fired. Feel free to tweak these numbers to get a position that feels just right for your game.

Set size to 30% and show.

Place a forever block and include a move 10 steps block inside it. With this, the bullet will continue moving straight.

Delete the clone

Next, let’s create the conditions for deleting the clone.

Off Screen

If the bullet goes off-screen, delete the clone.

Hitting an Enemy

Additionally, delete the bullet if it hits an enemy. This will also tie into the enemy defeat process.

Wait for 0.1 seconds and delete the clone.

Sprite 'Enemy'

Defeat an enemy by deleting the one that gets hit.

Open the 'Enemy' sprite.

When a clone is created, execute a forever block to continuously monitor if it gets hit.

Delete the clone if it touches the Player Bullet.

Preview

Smash! As Scratch Cat lands with a stylish shooting pose, the enemy is perfectly defeated! This is what a shooting game is all about!

Sprite 'Hitbox'

Finally, let’s create the game-over process. We’ll implement the detection of enemy attacks hitting the player in the Hitbox sprite. Let’s get started!

Open the 'Hitbox' sprite.

Block Definition 'Game Over'

Create a new block definition named 'Game Over'.

Place this definition block in the forever loop under the green flag.

In the difinition, check if this sprite hits the 'Enemy Bullet'.

Message 'Game Over'

Create a new message named 'Game Over'.

When the hitbox sprite touches the 'Enemy Bullet', then broadcast the 'Game Over' message and stop all.

Sprite 'Splash Screen'

When the game-ending message is received, display a splash screen with the text "Game Over" to signal the end of the game.

Open the 'Splash Screen' sprite.

Hide the sprite itself when the game starts.

Display it when the message is received.

Preview

Ah, now getting hit by an enemy bullet results in a game over… But having an ending makes the game more thrilling, doesn’t it?

END

Alright! With all the planned coding complete, our Fortnite-inspired Scratch game is officially finished! This serves as the foundation for your own unique Fortnite creations, so feel free to share your original works. I can’t wait to play your games. Fortnite forever!

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.