grid

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2013 License: BSD-2-Clause-Views, Zlib Imports: 4 Imported by: 0

Documentation

Overview

Package grid is used to generate random maze or skirmish levels. Maze levels have dead ends such that there is only one path to get from one spot in the maze to another. Skirmish levels have no dead ends in order to provide plenty of movement options.

Expected usage:

maze := grid.New(PRIM_MAZE)  // Create a type of grid.
maze.Generate(width, height) // Generate the grid.
for x := 0; x < width; x++ {
   for y := 0; y < height; y++ {
      if maze.isWall(x, y) {
          // Do something with a wall.
      } else {
          // Do something with a passage.
      }
   }
}

Package grid is provided as part of the vu (virtual universe) 3D engine.

Index

Constants

View Source
const (
	// PRIM_MAZE is a Randomized Prim's Algorithm (see wikipedia).
	PRIM_MAZE = iota

	// SPARSE_SKIRMISH creates a skirmize grid by randomly traversing all the
	// grid locations and adding random walls as long as there are more than
	// two ways out of the grid location.
	SPARSE_SKIRMISH

	// ROOMS_SKIRMISH is a skirmish grid created by subdividing the area
	// recursively into rooms and chopping random exits in the rooms walls.
	ROOMS_SKIRMISH

	// DENSE_SKIRMISH is a corridor only skirmish grid. It is a Prim's maze
	// where the dead-ends have been eliminated.  Additionally each side of
	// the grid is guaranteed to have one exit to the level exterior.
	DENSE_SKIRMISH
)

Currently supported grid types that are used as the input to grid.New().

Variables

This section is empty.

Functions

This section is empty.

Types

type Grid

type Grid interface {

	// Generate creates a grid full of walls and passages based on
	// the given depth and width.
	//
	// The minimum maze dimension is 7x7, and grids must be odd numbered.
	// The given grids width and height are modified, if necesary, to ensure
	// valid values.
	//
	// Generate needs to be called first in order for the other methods to return
	// meaningful results.  It can be called any time to create a new grid.
	Generate(width, depth int) Grid

	// Size returns the current size of the grid.  This will be 0, 0 if Generate
	// has not yet been called.
	Size() (width, depth int)

	// IsWall returns true if the cell at the given location is a wall.
	IsWall(x, y int) bool

	// Band returns the depth into the based on concentric squares. Numbering
	// starts at 0 on the outside and increases towards the center.  Using band
	// implies (makes more sense if) the grid width and height are the same.
	Band(x, y int) int
}

Grid generates a random floorplan where each grid cell is either a wall or a passage. The expected usage is to generate a random level and then to use the level by traversing it with the Size and IsWall methods.

func New

func New(gridType int) Grid

New creates a new grid based on the given gridType. Returns nil if the gridType is unknown.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL