Screen shot from the video game 'Return of the Dead Pixels' showing zombies

Step 1: Make a Puzzlescript game and export it as HTML.

Step 2: Add a toggle switch (a checkbox) inside of the HTML body. Preferably right after the opening <body> tag.

<label for="musicToggle"><input type="checkbox" id="musicToggle" name="musicToggle" onclick="playBgMusic()" checked>🎵</label>

Step 3: Add the audio component and the Javascript code. Preferably right before the closing </body> tag. Change YOUR-FILE-NAME-HERE.mp3 to the name of your music file.

<audio id="audio" controls style="display:none">
  <source src="YOUR-FILE-NAME-HERE.mp3" type="audio/mpeg"> Your browser does not support the audio element.
</audio>
<script>
  function playBgMusic(){
    if(document.getElementById("musicToggle").checked){
      document.getElementById('audio').play();
    }else{
      document.getElementById('audio').pause();
    }
  }
  document.addEventListener('keyup', playBgMusic);  
  document.addEventListener("click", playBgMusic);
</script>

Step 4: THAT’S IT!

Check it out by playing Return Of The Dead Pixels, my Puzzlescript zombie game:

https://ohiofi.itch.io/return-of-the-dead-pixels

Screen shot from the video game 'Return of the Dead Pixels' showing player surrounded by zombies


You can spawn a random amount of chicken jockeys with the third Minecraft mod from “Absolute Beginner’s Guide To Minecraft Mods Programming, second edition” by Rogers Cadenhead.

Demo of the /zombiepig command

Challenges

1. Can you create a “/zombiepig” command that generates pig-riding zombie-pigmen?

In the onCommand method add an if-else statement for if (label.equalsIgnoreCase("zombiepig")) then call a new method named executeZombiePigCommand(sender). You can copy/paste the executeCommand method and just change the title to executeZombiePigCommand. Next, update the line that says Chicken clucky = world.spawn(chickenSpot, Chicken.class); so that it will spawn an instance of the Pig class and save it a variable type Pig (you can still use the variable name clucky if you want). Finally, update the line that says Zombie rob = world.spawn(chickenSpot, Zombie.class); so that it spawns an instance of the PigZombie class and saves it in a variable type PigZombie.

2. Can you create a “/villagersheep” command that generates random-color sheep with villager jockeys?

In the onCommand method add an if-else statement for if (label.equalsIgnoreCase("villagersheep")) then call a new method named executeVillagerSheepCommand(sender). You can copy/paste the executeCommand method and just change the title to executeVillagerSheepCommand. First, make it spawn an instance of the Sheep class and save it a variable type Sheep (you can still use the variable name clucky if you want). Next, make it spawn an instance of the Villager class and saves it in a variable type Villager. Look at the Spigot API for the Villager class and find the setBaby method. Notice that unlike the setBaby method for the Zombie class, this method does NOT require any arguments. Finally, look at the Spigot API for the Sheep class and the DyeColor class in order to create an array of type DyeColor that contains several colors, randomly select a DyeColor from the list, and set the sheep’s wool color.

3. Can you generate a “normal distribution” of chicken jockeys?

A normal distribution (also known as a bell curve) will expect that median values are more likely and extreme values are less likely. Consider rolling two dice. You have about a 44% change of rolling a 6, 7, or 8, but you only have about a 3% chance of rolling a 12. We would simulate rolling two dice in Java like this (int) (Math.random() * 6 + 1) + (int) (Math.random() * 6 + 1) and we would get a bell curve of values ranging from 2 to 12. How can you change that code to generate a bell curve of values ranging from 8 to 16?

Demo of the /villagersheep command

ZombieChicken Starter Code

Source: https://javaminecraft.com/source/ZombieChicken/ZombieChicken.java

package com.javaminecraft;

import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Player;
import org.bukkit.entity.Zombie;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;

public class ZombieChicken extends JavaPlugin {
    public static final Logger LOG = Logger.getLogger("Minecraft");

    @Override
    public boolean onCommand(CommandSender sender, Command command,
        String label, String[] arguments) {

        if (label.equalsIgnoreCase("zombiechicken")) {
            if (sender instanceof Player) {
                executeCommand(sender);
                return true;
            }            
        }
        return false;
    }

    public void executeCommand(CommandSender sender) {
        Player me = (Player) sender;
        Location spot = me.getLocation();
        World world = me.getWorld();

        // spawn 1-10 chicken-riding zombies
        int quantity = (int) (Math.random() * 10) + 1;
        for (int i = 0; i < quantity; i++) {
            // set chicken and zombie location
            Location chickenSpot = new Location(world,
                spot.getX() + (Math.random() * 15),
                spot.getY() + 5,
                spot.getZ() + (Math.random() * 15));
            // create the mobs
            Chicken clucky = world.spawn(chickenSpot, Chicken.class);
            Zombie rob = world.spawn(chickenSpot, Zombie.class);
            rob.setBaby(true);
            clucky.setPassenger(rob);
            // increase the chicken's speed
            int speed = (int) (Math.random() * 10);
            PotionEffect potion = new PotionEffect(
                PotionEffectType.SPEED,
                Integer.MAX_VALUE,
                speed);
            clucky.addPotionEffect(potion);
        }
        LOG.info("[ZombieChicken] Created " + quantity + " chicken-riding zombies");
    }
}


The second Minecraft mod from “Absolute Beginner’s Guide To Minecraft Mods Programming, second edition” by Rogers Cadenhead will spawn a random number of chickens in the air above the player when they type the command “/chickenstorm”

This is a very popular mod that I’ve actually had students mention to me in the past. For example… “In our Intro To Programming class, we learned how to make Minecraft mods and we made it rain chickens.”

Demo of the FireStorm Minecraft mod

Challenges

1. Can you spawn 20-30 chickens instead of 1-30 chickens?

Edit line 39 of the starter code for (int i = 0; i < Math.random() * NUM_CHICKENS + 1; i++) { to something like for (int i = 0; i < randomAmount; i++) { then add a new line above in which you declare a variable named randomAmount and set its value to a random number 20-30. Here is how to generate a random range in Java… (int) (Math.random() * (maximum - minimum) + minimum) The key to understanding this is to know that Math.random() will give you a decimal value from 0.0 to 0.9999999999. If we multiply Math.random * 30 then we will get random decimal values from 0.0 to 29.9999999999, but that’s not what we want. We should instead multiply by the number of possible values we want and there are 11 possible values from 20 to 30. Finally, add 20 to the random number.

2. Can you create a “/firestorm” command that generates flaming chickens?

In the onCommand method add an if-else statement for if (label.equalsIgnoreCase("firestorm")) then call a new method named executeFirestormCommand(sender). You can copy/paste the executeCommand method and just change the title to executeFirestorm. Next, remove the code that makes 40% of them babies. Instead we will set them on fire. Check the Spigot API for the Chicken class and look for one of the Entity methods that has “fire” in the method name. You should find 3 methods that have to do with fire, but only one of them is a setter method. Invoke the method on clucky and provide a large integer number (such as 999) as an argument.

3. Can you make the flaming chickens launch fireballs when they are first spawned?

If you completed the last challenge, then you probably created chickens that were on fire for about 4 seconds and then died. This just leaves feathers and roasted chicken all over the place. How can we make a REAL firestorm? First, check the Spigot API for the Chicken class and find how to increase the max health and set the health of clucky. You might also notice that the Chicken class implements the ProjectileSource interface. You can use Fireball flamey = clucky.launchProjectile(Fireball.class); to generate a Fireball projectile. Finally, check the Spigot API for the Fireball class and find out how to set the direction of flamey. You will need to provide a Vector object as an argument, such as new Vector(0, -1, 0)

Another demo of the FireStorm Minecraft mod

ChickenStorm Starter Code

Source: https://javaminecraft.com/source/ChickenStorm/ChickenStorm.java

package com.javaminecraft;

import java.util.logging.Logger;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;

public class ChickenStorm extends JavaPlugin {
    public static final Logger LOG = Logger.getLogger("Minecraft");
    // the maximum number of chickens
    private static final int NUM_CHICKENS = 30;

    @Override
    public boolean onCommand(CommandSender sender, Command command,
        String label, String[] arguments) {

        if (label.equalsIgnoreCase("chickenstorm")) {
            if (sender instanceof Player) {
                executeCommand(sender);
            }
            return true;
        }
        return false;
    }

    // handle the chickenstorm command
    public void executeCommand(CommandSender sender) {
        Player me = (Player) sender;
        Location spot = me.getLocation();
        World world = me.getWorld();

        int quantity = 0;
        // loop from 1 to NUM_CHICKENS times
        for (int i = 0; i < Math.random() * NUM_CHICKENS + 1; i++) {
            // pick a spot for the chicken above the player
            Location chickenSpot = new Location(world,
                spot.getX() - 15 + Math.random() * 30,
                spot.getY() + 10 + Math.random() * 100,
                spot.getZ() - 15 + Math.random() * 30);
            if (chickenSpot.getBlock().getType() != Material.AIR) {
                // don't put the chicken in a solid block
                continue;
            }
            // create the chicken
            Chicken clucky = world.spawn(chickenSpot, Chicken.class);
            if (Math.random() < .4) {
                // make 40% of them babies
                clucky.setBaby();
            } else {
                // make the rest adults
                clucky.setAdult();
            }
            quantity++;
        }
        // tell the server log how many were created
        LOG.info(quantity + " chickens summoned");
    }
}




RECENT POSTS