Adrian Herbez Rotating Header Image

Posts Tagged ‘Python’

Collectible Dart Game: paper prototype

I was playing Magic: The Gathering recently with a friend at a local bar that so happens to have a dedicated darts room.

That got me thinking- why not have a collectible darts game? After some thought, I nailed down a rough draft of a design, with the following elements:

  • The collectible/swappable component is the fins of the dart (“flight”) on which is printed stats and abilities
  • The setting/theme of the game is future fantasy, with players competing to mine resources from a planet (the dartboard) by sending units down to the surface (throwing darts)
  • All units have:
    1. a mining stat, combined with the value of the section the dart hits to determine amount of resources gathered
    2. a combat stat, used to resolve combat between units
    3. [optionally] an activated ability of some kind, for example: [R] + 5 to mining, which would mean that if the dart lands inside a red section of the board, it earns 5 extra units of resources
  • Play proceeds with players alternating to throw darts
  • Combat is resolved at the end of a round, and the resource totals are added to each player’s running tally
  • The first player to gather a set number of resources (100?) wins

I’m still thinking through the combat system, but in the meantime I wanted to be able to generate some prototype pieces to start playtesting. As such, I wrote a small Python program that accepts a text file describing units and generates a printable PDF that can be used to make flights. I’ll likely be changing the design of the flights a bit (altering the shape and making them slightly bigger), but it’s a good start. To see the generated PDF, go here.

projects ,

Binary rings (via OpenSCAD)

So a while ago, I started in on a project to create a tool for generating wearable ring models with text encoded in binary based on the ASCII values of each character. I put the project aside a while back, but recently I discovered OpenSCAD, a fantastic tool for programmatically defining 3d models.

OpenSCAD totally rocks, but is a little strange in that variables aren’t, strictly speaking variable, since you can’t change their value. As a result, instead of writing openSCAD directly, I created a Python script that takes a string as a command line argument and generates the OpenSCAD code to make a ring with that phrase around it. The above image encodes ‘OpenSCAD rocks my world’.

The next steps are to make the script take a ring size and thickness, and then I’ll likely be setting up shop on Shapeways to sell these.

projects , , , ,

Cryptogram maker script

I sat down to work on the cryptogram solving interface from the last post a bit, only to find that the CoronaSDK API reference site was down. So, I decided to spend the allotted time working on a support tool instead. I wrote a simple Python script that:

  • reads in a list of statements from a file and, for each of them:
  • randomly generates a substitution cipher
  • encodes the statement into ciphertext
  • prints the original statement and the ciphertext version to a file

Nothing spectacular here, but it will make testing a lot easier, and will eventually grow into a proper content-creation tool. It’s almost usable as such as-is, but I want to add in some heuristics for estimating (and perhaps even adjusting) the difficulty of the resulting cryptogram.

projects , ,

Procedural Snakes

001This was a small, one-night project to explore the procedural creation of snakeskin-like patterns. The main trick is to use overlapping sine waves and a bit of noise to create mirrored, snakeskin patterns, which ended up being both straightforward to implement and fairly effective.

To see more examples, go here.

If you would like to play with the code yourself, it’s in github.

projects ,

Tex Calc

screenshot of the texture calculator

screenshot of the texture calculator

While Second Life offers everything you need to apply complex textures to your objects on a per-face basis, it can be really tricky to determine the appropriate repetitions and offsets to get a specific portion of the texture onto a specific face.

I’ve created a tool that sidesteps the issue and allows users to interactively click and drag a selection box around a given portion of a texture. The program then calculates the necessary offset / repetition values to have the selected region appear on a face.

To use the program, download the zip file from here. Read the instructions below, or scroll down for a video.

After opening the program, load your texure image (JPG, GIF, BMP, or Targa) by clicking on the “load texture” button. Once you’ve done that, click and drag anywhere in the image to define a rectangular region. As you drag, you’ll see the region you’re selecting highlighted in red. When you let go of the mouse, the program will display the necessary repetition and offset values in the top-right. Using the specified values in SecondLife will give you the selected portion of your texture.

If the highlight color isn’t to your liking, click somewhere in the color swatch region to select a color that you would prefer to use (something that will contrast with your texture), and click on the “dot” button. The color of the selection dot will change to the color you selected, and further selections will be in that color.

You can also change the color of the horizontal and vertical guide lines to provide better contrast. To do that, select a color from the swatch and click the “guide” button.

projects , ,

Node-based crafting mockup

I’ve started in on a project that I’ve been kicking around for awhile- an approach to gameplay based on the node-based interfaces in apps like Maya and Pd.

What I’m thinking is to have a game world in which players can build things by “hacking” (in the Make-magazine sense) things together to create useful items. But rather than having some pre-determined set of possibilities (as in games like Notrium), I plan on having it be completely open-ended (a ‘la Pd), by keeping things as modular as possible.

What I have so far is a working mockup of the object-creation interface, implemented with Python/Pygame. A list of objects is given at the bottom, and the user can click-drag any of them to the workspace to create a node. Then, the user can create linkages from the outputs of a given node to the inputs of another. Links update automatically to maintain themselves as the nodes are moved around the work area, and deleting a node (by clicking on the X) also deletes any linkages attached to it. The nodes themselves are declared in a separate text file and can be easily added to. So far, all that’s stored is the name of the node, the image to use for its icon, and the number of input/output connections. As the object-model grows more complex, I’ll be adding information to the nodes, such as what kind of connections they require (electric, mechanical, etc) and how much of each.

projects ,