In this project, we'll build on the previous bomb detonating project by making our explosion radius configurable from the controller and also display that radius on the LED Matrix.

For this project, we'll need the LED Matrix and three buttons wired on the breadboard. For our code below, we assume the buttons are wired to GPIO12, GPIO14 and GPIO15. Here's what your breadboard should look like:

This code is similar to the code from the previous project, except that we've added a few things:

- A variable called `radius` that is increased or decreased using two new up and down buttons that we've added to the hardware.

- The LED Matrix displays the current explosion radius.

## Full Code

Here is what the code for this project should look like at this point (with new changes highlighted with arrows):

from rstem.button import Button from rstem.mcpi import minecraft, control, block from rstem.mcpi.vec3 import Vec3 *from rstem.led_matrix import FrameBuffer, Text import time fb = FrameBuffer() control.show() mc = minecraft.Minecraft.create() *bomb = Button(12) *up = Button(14) *down = Button(15) def detonate(mc, pos, radius=1): r_vector = Vec3(radius,radius,radius) mc.setBlocks(pos - r_vector, pos + r_vector, block.AIR) place_mode = True *radius = 1 while True: if place_mode: if bomb.presses(): control.hit(duration=.2) hits = mc.events.pollBlockHits() if hits: tnt_pos = hits[0].pos mc.setBlock(tnt_pos, block.TNT) place_mode = False else: if bomb.presses(): * detonate(mc, tnt_pos, radius) place_mode = True * radius += up.presses() * radius -= down.presses() * radius = max(min(9, radius), 0) * fb.erase() * fb.draw(Text(str(radius))) * fb.show() time.sleep(0.01)

This code should be pretty self-explanatory at this point, but should also give you some ideas on how you can continue to create new and interesting games and events in the Minecraft world.

1. Assuming you still have your controller wired up, add this bomb code to the Minecraft controller code ( project) so that you can place a bomb while using the CREATOR Kit as a controller.

2. Can you add a bomb explosion sound when the detonation occurs? Note: "hit.wav" is a reasonable sound to use.

3. Can you make the explosion occur near, but not exactly at, the TNT position? Hint: You might want to use a random function.