# Magical Castle

8-10 yrs old

11-13 yrs old

Computer Science

Using code for real time positional sensing of the player. The map was created by Faith Shupee, who kindly agreed to let me use it for this lesson.

Submitted By: Philip Golden

January 25, 2019

#### Skills

• Creativity
• Critical Thinking

### External References

Chapter 2 of this book deals with positional sensing (albeit using Python) in Minecraft. Much of this material was the inspiration behind this lesson.

Slightly modified version of the CompaCastle map created by Faith Shupee (@FaithShupee), who kindly agreed to allow me to use it for this lesson.

This code uses the Makecode editor to perform all of the assignments.

### Learning Objectives

• Students will learn how to sense the players position in real time, and then use simple calculations and events based on player location.
• As well as an appreciate for 3D co-ordinate geometry, students will use conditional and event based coding techniques.
• This game is an example of the 'sense, calculate, action' framework that is the foundation of many Minecraft mini-games. Emphasising this framework is particularly useful to allow students to use decomposition on games they play, which in turn can enhance both their analytical skills and understanding.

### Guiding Ideas

Real time sensing of the players position is a fundamental concept behind this lesson.

Do we need to calculate the y co-ordinate?

Conditional event triggering raises some interesting considerations.

How could we modify the 'if' statements to instead sense if the player is within a region (e.g. a room)?

Sequencing of events can cause unintended consequences.

Why might it not be a good idea to spawn mobs 'continually' when a player is at a certain location (clue: you may find that Minecraft crashes!)? If waits/pauses are used, what considerations could be used to determine how long to wait for?

Events are largely limited by the student's imagination.

What sort of experience do you want to create for players?

### Student Activities

• Use code builder to create two variables that continually sense the players x and z location
• Ensure that 'show co-ordinates' is on. Fly to the entrance to the castle and note the co-ordinates at the door
• Use code to display a 'Welcome to ***' chat message when the player's x and z co-ordinates match those at the castle entrance. Note that this message continually shows when standing at the co-ordinate
• Create a second event when the player enters the castle, here making a number of bats spawn in front of the player. Consider whether a 'pause' block/method could be useful here, as without it a large number of bats can be spawned quickly which risks crashing Minecraft!
• Create a third event for the room immediately on the left of the entrance (with the cake on the table). If the player touches the cake, teleport the player to the top of the flag on the roof of the castle!
• Explore the rest of the castle and create some cool reactions to players entering different rooms.

### Performance Expectations

Students should have a good knowledge of how co-ordinates are used to both sense a player in real time, and trigger events based on the players location.

Students should also gain an appreciation for sequencing events, in particular the need to add delays when spawning mobs.

Significant creative scope is possible for students to experiment with different behaviours. Here an emphasis can be placed on user experience, and students should be encouraged to consider how they are designing the users experience in the castle.

#### Skills

• Creativity
• Critical Thinking

### External References

Chapter 2 of this book deals with positional sensing (albeit using Python) in Minecraft. Much of this material was the inspiration behind this lesson.

Slightly modified version of the CompaCastle map created by Faith Shupee (@FaithShupee), who kindly agreed to allow me to use it for this lesson.

This code uses the Makecode editor to perform all of the assignments.