
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.
Backdrop And Sprite Images For The Project


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.
- Create the Knight character and set up its movement.
- Add the shooting mechanism for the Knight.
- Introduce the ghost enemies.
- Detect collisions between magic and ghosts.
- 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!
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.
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.
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.
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 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
Grades K-2
Scratch Ninja
Grades 2-6
Accelerated Scratch
Grades 5-9
Intermediate Game Building with Scratch
Grades 3-6
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!
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.