text
stringlengths
0
897
]td.cellSize = 64
]td.overlap = 0
]td.clear 16
```
Remember that the 16 used on line 4 is just the tile index for a white circle in our tile set. If you look back at the tile set, you'll see that right below that, at index 24, is a hexagon with a flat top and points on its left/right sides. That means when we're all done, the cells are going to overlap a bit horizont...
```terminal
]td.overlap = [11, 0]
]td.oddColOffset = 0.5
]td.clear 24
```
{gap:20}
{width: "50%"}
![Hexagonal grid with offset columns.](Hex24.png)
The next row in our tile set, at index 32, is the opposite kind of hexagon: it's flat on the sides, and pointy on top and bottom. To fit together neatly, it needs to overlap in Y, and have the odd rows shifted over by half a cell.
```terminal
]td.clear 16
]td.oddColOffset = 0
]td.overlap = [0, 11]
]td.oddRowOffset = 0.5
]td.clear 32
```
The first two lines above are just undoing our previous demo; lines 3-5 do the actual setup for this kind of hexagonal display.
{width: "50%"}
![Hexagonal grid with offset rows.](Hex32.png)
## Exploring the Demos
`TileDisplay` is used by quite a few of the demos in `/sys/demo/`. Here's a quick run-down of how each of them use it, and what you might be able to learn.
{i:"`/sys/demo`,`drumMachine`"}
**drumMachine**: this demo uses two overlaid tile displays, in display layers 5 and 6. Both use the same `TileShapes.png` tile set you've been working with in this chapter. The frontmost layer uses the square with rounded corners, and uses a *negative* `overlap` value to spread them apart so there's a nice gap betwee...
{i:"`/sys/demo`,`levelEditor`"}
**levelEditor**: this is an interesting one, because it's not just a demo, but also a useful tool. It sets up `display(6)` as the tile display, with `display(5)` used in pixel mode to draw on top of the tiles. It then provides functions to define the pattern of tiles in a tile display, save these out to disk as a dat...
{i:"`/sys/demo`,`platformer`"}
**platformer**: this game demo uses a layout defined by `levelEditor`, and also adds a sprite character who can run, jump, and climb. The very first figure in this chapter was a screen shot of this demo and its tile set. The code illustrates how to check the tile display where the character is trying to walk or climb...
{i:"`/sys/demo`,`speedConquest`"}
**speedConquest**: this turn-based strategy game also uses the `TileShapes.png` tile set, with a hexagonal layout (using `oddColOffset`). In this case it uses only the white tile, and then tints them to each player's color to make their territories clear. There's also a sprite layer, used to draw the units and flags ...
{i:"`/sys/demo`,`wumpusTrap`"}
**wumpusTrap**: this puzzle game also uses a hex grid, but this time using `oddRowOffset` because the hexagons are in the other orientation. Also, it uses different color tiles from the tile set rather than using tint. Like `speedConquest`, it has some handy functions for converting between pixels and tile coordinate...
A> **Chapter Review**
A> - You explored the `TileDisplay` class, the last type of Mini Micro display.
A> - You learned how to load a tile set, and configure the tile display.
A> - You discovered how to control what a tile display shows by assigning a tile index or tint color to each cell.
A> - You learned about the overlap and offset properties that enable you to make an isometric or hexagonal display.
A> - You toured the built-in demos that illustrate some of the many ways a tile display can be put to use.
{gap:250}
{width:"25%"}
![](chinchilla-05.svg)
{chapterHead: "Day 26: Treasure Hunt", startingPageNum:319}
{width: "50%"}
![](Chapter26.svg)
Q> No more training do you require.
Q> Already know you that which you need.
Q>— Yoda (Star Wars: Episode VI - Return of the Jedi)
A> **Chapter Objectives**
A> - Build and enjoy the *Treasure Hunt* game.
A> - See how `TileDisplay` is used in a real program.
A> - Practice installing resources onto your user disk, so you're not limited to only the stuff on the `/sys` disk.
Your introduction to MiniScript and Mini Micro are essentially complete at this point. You learned the basics of coding, and flexed your skills via the Try-It! page, in the first week. The second week you learned to use command-line MiniScript, while also learning about lists, maps, and classes. Since then you've be...
However, just as with Luke's journey to master the Force, your journey is not yet over. Your head is full of knowledge, but can you actually *use* that knowledge to create your own software? For most readers, the answer at this point will be "not yet," and that's OK. Learning to apply what you have learned takes pra...
So the next few chapters of the book will be practice and review, in the form of programs for you to type in. I urge you not to skip this exercise! It will make your programming skills stronger.
(And to any eager readers who skipped the first half of the book to get to the "good stuff," I say welcome! But please remember to go back and go through the rest of the book at some point. It will give you a strong foundation in the basics, and ultimately save you a lot of time learning things the hard way.)
## *Treasure Hunt*
The program for this chapter is a game based on the classic *Minesweeper*. The basic idea behind *Minesweeper* dates all the way back to the era of mainframe computers in the 1960s. For many years a version of *Minesweeper* was included with the Microsoft Windows operating system, leading to a great surge in populari...
The core game play for all *Minesweeper* variants is the same: you click squares on a map to discover what they contain. If they contain a mine, it's game-over. Otherwise, the square reveals how many mines there are in the neighboring squares. Using these numbers, you can usually find a safe place to try next.
Our version of the game is called *Treasure Hunt*, and adds a little twist: hidden along with the bombs are half a dozen treasures, and uncovering these treasures scores you points. The faster you discover them, the more points you earn!
{width: "80%"}
![Screen shot of *Treasure Hunt*.](TreasureHuntGame.png)
Incidentally, this game is so much fun, and the code so straightforward, that it almost didn't make it into this book. I was very tempted to add it to the built-in demos in `/sys/demo/` in the final version of Mini Micro. But in the end I decided to instead include it here, as a reward for those of you who took the t...
## Getting the Tile Set