Create & Learn
Background

Try Mansion Defense: Knight vs. Ghosts for fun Scratch Project!

Mansion Defense: Knight vs. Ghosts

Platform: Scratch
Level: beginner

This project sets the Knight in a haunted mansion where ghosts are trying to invade. The Knight can shoot magical energy to defend against the ghosts. Players will control the Knight's movements, switch between different costumes for different magic attacks, and repeat actions to defeat enemies, focusing on sound effects when ghosts are defeated and simple repeat loops.

Save to Account
See All Projects

Backdrop And Sprite Images For The Project

background
background
1024 x 1024
Knight
Knight
1024 x 1024

Mansion Defense: Knight vs. Ghosts: Solution Outline

These are the high level steps to create this project. Try to create the project on your own first as much as possible, before checking the detailed solution samples below.

  1. Create the Knight character and set up its movement.
  2. Add the shooting mechanism for the Knight.
  3. Introduce the ghost enemies.
  4. Detect collisions between magic and ghosts.
  5. Switch costumes and add sound effects.

Mansion Defense: Knight vs. Ghosts Sample Solutions

This section provides detailed, step-by-step instructions on how to build the project. There are many ways to create a project, so feel free to explore different approaches. Please note that these instructions are Al-generated, so errors may occur and the coding blocks may not map to Scratch exactly. But it should serve as very valuable references. Stay attentive as you follow along, and enjoy!

Create the Knight character and set up its movement.

Start by creating a Knight sprite. You can either draw your own or choose one from the Scratch library. Make sure the Knight has at least two costumes: one for normal stance and one for shooting magic. Use the arrow keys to move the Knight left and right across the screen.

Add the shooting mechanism for the Knight.

Create a new sprite for the magic energy that the Knight will shoot. When the space key is pressed, the magic sprite should appear at the Knight's position and move upwards. Use a repeat loop to make the magic move continuously until it reaches the top of the screen.

Introduce the ghost enemies.

Create a ghost sprite that will move from the top of the screen to the bottom. Use a repeat loop to make the ghost move continuously. When the ghost reaches the bottom, it should reappear at the top at a random x position.

Detect collisions between magic and ghosts.

Use a conditional statement to check if the magic sprite is touching a ghost. If it is, play a sound effect and make the ghost disappear. You can use the "delete this clone" block to remove the ghost.

Switch costumes and add sound effects.

Switch the Knight's costume back to normal after shooting. Add sound effects for shooting and when a ghost is hit. Use the "play sound" block to add these effects.

Common Potential Issues in Mansion Defense: Knight vs. Ghosts Project

It is common to have bugs in the code. Here are some of issues you might run into.

  • Ensure the Knight's movement is smooth and doesn't allow it to move off the screen.
  • Make sure the magic sprite is deleted after it moves off the screen to prevent clutter.
  • Check that the ghost reappears correctly at a random position after reaching the bottom.

Extra Challenges For Mansion Defense: Knight vs. Ghosts

  • Add a score counter that increases each time a ghost is defeated.
  • Introduce different types of ghosts with varying speeds or sizes.

Learn Scratch Coding Skills

Enroll your child in award-winning online Scratch coding classes led live by experts and designed by professionals from Google, Stanford, and MIT.

Scratch Junior

Scratch Junior

Grades K-2
Start coding with ScratchJr, and make interactive stories and games
Learn More
Scratch Ninja

Scratch Ninja

Grades 2-6
Code games and animations with beginner-friendly Scratch coding
Accelerated Scratch

Accelerated Scratch

Grades 5-9
Fast-paced introduction to coding: build games, stories, and animations
Intermediate Game Building with Scratch

Intermediate Game Building with Scratch

Grades 3-6
Code a new fun Scratch game every week

Explore More Fun Scratch Practice

The challenge continues: Enjoy even more Scratch tutorials dreamed up by other students or use your imagination to make your own!

backgroundTry The Tutorial
Develop My Own Idea

Find Best Classes For Your Child

Explore your child's grade level to find computer science classes and learning pathways that set your student up for success.