PROJECT 3
MONSTER ARENA IS A MULTILEVEL MINECRAFT MINIGAME WHERE THE PLAYER IS IN A LARGE ARENA WITH MONSTERS THAT SPAWN AROUND A MELON CUBE BLOCK. The player’s goal is to reach the melon cube without being attacked by the monsters. Every time the player reaches the melon cube, he moves on to the next level, which has more monsters that are harder to beat.
In this project you make a Monster Arena mod. Then you can play Monster Arena with your friends and see who can defeat the most monsters!
Draw the gameplay loop (see the next page) for the Monster Arena game. It will work just how it did in the project before this one.
This project helps you make each iteration of the gameplay loop harder to beat. To start, you have a simple arena with one melon block, one monster, and one level.
Here’s one way to tackle the first iteration of the gameplay loop:
Start: Create a basic arena enclosed by a fence.
In Monster Arena, the arena is round. A large fence surrounds the arena to keep the player and monsters inside it.
Goal: Add a melon block to break.
For this minigame, you also need to write code to reset the arena when the player breaks the melon block.
Challenge: Add monsters to the arena.
You add one monster to the arena, and the player has to avoid the monster while trying to break the melon block. If the player breaks the melon block, the game resets.
Ask your friends to test your game after you add monsters. They’ll probably say that it isn’t hard to play, but they can tell you what kinds of challenges they like. Do they want more monsters or a bigger arena?
Reward: Replay the first level.
In the first iteration, the user who breaks the melon block is the one who gets to play Level 1 again. In Iteration 2, you add more levels.
After you plan out the gameplay loop in Steps 1–4, it’s time to build Monster Arena.
Whenever you build any game, the first thing you need is a basic scene.
You may already know that the radius is the line from the middle of a circle to any point on the circle’s edge. Everything in Minecraft is made with blocks.
Monster Arena needs this stuff:
For this basic scene, you create
In the Spleef project you built an arena using the LearnToMod library named sarah-ArenaBuilder. That library makes square arenas. This time you need a round one. Use WorldEdit commands to make the arena in LearnToMod!
A WorldEdit command can run in Minecraft to edit the world.
Before you make the arena, test out the WorldEdit commands in Minecraft.
First you type the code to make
Type this: //cyl stone 20. Then you see the platform.
Try making the fence with WorldEdit commands. If you don’t move, you can make a wooden fence inside the stone fence. Just enter the code that follows the kind of fence:
If you call //cyl stone 20 and //hcyl stone 20 4 and //hcyl fence 19 4 without moving, you wind up with an arena with a fence around it.
After you test the WorldEdit commands, call them from the LearnToMod mod. Crazy idea — I know.
When you use a PerformCommand block, the first slash mark (/) is already included, so you need to have only one slash mark to make the platform and fences. You can see here what the main function looks like for the initial scene.
Test your mod to make sure that it’s the right kind of arena.
Before you add a goal, refactor your code so that the main function stays simple. You can see here how to refactor your code to clean up the main function.
The arena function stays the same, but now add a melon block on the opposite side of the arena from the player.
Here’s the new function, SetupGame, which places the melon block and puts the player in the starting position. The next steps help you make the SetupGame function.
To add a melon block, follow these steps:
Add a new drone named d and move it to one side of the arena.
The drone should move only 18 blocks because the stone and the fence take up 2 blocks, and you want the player inside the fence.
Move the drone up by 2.
This makes the player start above the platform and fall into the arena.
Move the player to the location of the drone.
Now the player’s at the starting spot.
Move the drone 33 blocks to the opposite side of the arena.
That leaves two blocks empty between the melon block and the fence.
Place the melon block and move the drone backward by 1 block.
For right now, nothing happens when the player breaks the melon block. You write that code in Iteration 2.
Test your mod by dragging it from your mod chest into your HotBar and then clicking to run it. You should see this scene when you run the mod.
After your game is all set up, you can start making it playable. On the first iteration of the gameplay loop, add one monster for the player to beat (or to avoid, at least).
This time, write the code to spawn the monster in a separate function from the beginning. This code makes a monster spawn near the melon block. The drone is at the melon block, so it moves backward (toward the player) and then spawns the creeper.
Now when you test your game, you see a screen like this. That’s one nasty monster!
In other iterations you reward players with harder levels. (Who’d think of a harder game as a reward?) For this first iteration, however, just let people replay the first level.
First you make a function that gets called when the break block event happens. The on_block_break function checks to see if the melon block was broken. If it was, you see the message “Yay! You broke the Melon Block!”
Follow the steps to make this function:
Create a variable called event_block and put an info’s block inside the variable.
The event_block is in the Variables category. The info’s block is in the Misc category.
Send this message: Yay! You broke the Melon Block!
Next, you’ll actually call the on_block_break function when the player breaks a block.
Grab an Event block from under the Minecraft and then Events category. Change the event to block_break by clicking the blue down arrow.
You’ve made an event that calls the on_block_break function whenever the player breaks any block. This code shows how to add this event call into the main function.
If you don’t remember how to do some (or any) of these parts, look at the pictures in this book and go through all the categories until you find the right blocks. You can also post on the forum at forum.learntomod.com
and ask for help, or go back and earn badges under the Learn tab at mod.learntomod.com
.
Now you want that person to restart the level.
Add two variables to the SetupGame function:
This code shows how to add these two variables.
Write a ResetGame function that does this stuff:
This code shows the new function.
This code shows how to call it from the on_block_break function.
After you finish the four parts of Iteration 1, you can test your game and make sure that everything works. Your code should look like this.
On Iteration 2 of the Monster Arena gameplay loop, you can
Add some designs to the arena floor. Take your time. Be creative. Use the platform or the fences. You might even want to add a ceiling to the arena!
I used two //hcyl WorldEdit commands to make one hollow cylinder (tube) of glass and one of diamond.
You can see the code for changed arena function.
Sometimes when you’re going through the gameplay loop, you don’t want to change one of the sections — like when your goal is still the same. No problem. You don’t have to make any changes to the goal this time around.
Kick back. Relax for a minute.
Moving around one creeper isn’t the hardest thing in the world. It’s time to add more monsters.
By making one small change to the spawn_monster function with the number 5, you can spawn five creepers instead of one. Now your player is outnumbered!
In Monster Arena, levels are different based on what monsters there are. To add a second level, follow these steps:
Create a variable named Level. Start the variable at 1.
It keeps track of which level the player is on. It starts at 1 because the player starts on the first level.
Add two types of monsters: creepers and zombies.
This code shows how to create these two variables in the SetupGame function.
Change the spawn_monster function to spawn a different monster depending on what level you’re on.
If you change your code in your spawn_monster function to look just like the following code, the monsters change based on the level.
The code you change chooses the correct item from the list.
If the player reaches the final level (right now that’s Level 2), tell her that the game is finished. If she hasn’t reached the last level yet, this game should reset with the new monsters.
The code on the next page shows what changes you have to make in on_block_break that need to happen to start the new level.
After you add the changes to the spawn_monster function, test your mod. When you start the test, you should see five creepers.
If you break the melon block, the game resets and you see five zombies.
If you break the melon block again, you see the message “Yay! You beat all of the levels! Good job!”
After you start getting the hang of making the Monster Arena minigame, you can feel good adding a few more levels and challenges.
You may have noticed that it’s pretty easy for a player to get past all the creatures. That’s because the player is in Creative mode.
Add a perform command block.
The code shows the changes you make to the SetupGame function to do this. You only change the last block of the function — just add the perform command block.
When the game starts, the player goes into Survival mode.
Now that you’ve made it easier for the player to die, you should include an event that happens when the player respawns.
Change the main function and create the new RespawnPlayer function.
Look at code in the book and compare it to your code. You should be able to figure out what’s missing in your code and how to add it. But don’t worry! If you ever get stuck, just go to forum.learntomod.com
and ask for help!
Create a new function called RespawnPlayer. It should look exactly like this code.
I’ll let you figure out how to make it by looking at the correct code here in the book. Create it from scratch. I know you can do it! After you have made the new RespawnPlayer function and made the changes to the main function, the player teleports back to the arena when she respawns.
Adding levels is pretty easy because you already set up the levels to be based on a list. To make more levels, follow these steps:
Change the conditional statement so it’s based on the list length.
To refactor means to change the way code looks without changing what it does.
You’re making sure that you iterated through all the monsters in the Monster List (instead of a specific number, like 2).
The code shows how to change the conditional statement to have it based on the list length. Figure out the one place you should change your code. (Hint: You aren’t checking if Level is less than 2. You’re checking if Level is less than the length of a list.)
A conditional statement is one that compares two things. You can read it like a sentence. For example, if level is greater than the length of monsters, then send a message; otherwise, reset the game.
Change the SetupGame function to add monsters to your Monster List.
The code shows the updated SetupGame function. Add entities to the Monster List. You can find them under Minecraft and then Entities. Change which one you’re adding by clicking the yellow arrow and choosing from the list.
To add more positions into a list, click the star on next to the words create list with and drag item blocks into the list block.
Change the spawn_monster function.
This code shows how to spawn more monsters as the levels get harder.
If you followed the steps in this project, you created an entire multilevel Monster Arena minigame! (Yay! You made so many levels! Good job!)
Keep iterating on the gameplay loop to make more challenges, new rewards, and different goals. You can change the arena by adding patterns to the platform.
For example, at Level 1 you add five creepers, and at Level 2 you add ten monsters that are (randomly) creepers or zombies. At Level 3, you add a total of 15 monsters that are (randomly) creepers, zombies, or spiders.
This code shows how to add randomness to the spawn_monster function.