marchingsquares

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2020 License: Apache-2.0 Imports: 3 Imported by: 0

README

Marching squares

Simple Marching Squares implementation in ebiten. Based on Sebastian Lague's Marching Squares tutorial.

Running

Make sure you cloned the project.

go get github.com/gocs/viewdrag
# clean modules
go mod tidy
Basic

This showcases the basic Marching Squares implementation. There are nothing more than just an image.

go run ./cmd/1_basic/main.go
Aggregate

This features a square that can be moved on the marching squares map. To move the square, press and hold Mouse 3 as if you are panning. Aggregate in this context is adding a square with moving functionality on the marching squares map.

go run ./cmd/2_aggregate/main.go
Product

This features the whole marching squares map to be dragged. This also offers the same keyboard input as the Aggregate. Product in this context means dragging functionality on the marching squares map itself.

go run ./cmd/3_product/main.go

Limitations

  • Drawing in Triangles.
  • OpenGL vertex limit

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountWalls

func CountWalls(atlas [][]int, width, height int, gridX, gridY int) int

CountWalls gives the number of neighbors of a cell in a grid

func CreateTriangle

func CreateTriangle(triangles []uint16, a, b, c Node) []uint16

CreateTriangle adds an aggregate indexes of three nodes/vertices

func InvertMap

func InvertMap(atlas [][]int, width, height int) [][]int

InvertMap inverts map

func RandomFillMap

func RandomFillMap(w, h, percent int) (atlas [][]int)

RandomFillMap fills map with random values if using random seed

func SmoothMap

func SmoothMap(atlas [][]int, width, height int) [][]int

SmoothMap smoothes map to look like an actual map

Types

type ControlNode

type ControlNode struct {
	// contains filtered or unexported fields
}

ControlNode contains current, above, and right nodes, and active

func NewControlNode

func NewControlNode(pos Vector2, active bool, squareSize float32) *ControlNode

NewControlNode set an above node and right node depending on the given size when active

type MapGenerator

type MapGenerator struct {
	// contains filtered or unexported fields
}

MapGenerator contains map generator state

func NewMapGenerator

func NewMapGenerator(randomFillPercent, width, height int, squareSize float32) *MapGenerator

NewMapGenerator instantiates a map

func (*MapGenerator) GenerateMap

func (mg *MapGenerator) GenerateMap() error

GenerateMap generates map by filling, smoothing and generating mesh

func (*MapGenerator) GetTriangles

func (mg *MapGenerator) GetTriangles() ([]ebiten.Vertex, []uint16)

GetTriangles returns the verteces and the indices after generating the mesh

type MeshGenerator

type MeshGenerator struct {
	// contains filtered or unexported fields
}

MeshGenerator provides struct for DrawTriangle based on the atlas from map generator

func (*MeshGenerator) AssignVertices

func (mg *MeshGenerator) AssignVertices(points []Node) []Node

AssignVertices connects triangles' verteces to another point

func (*MeshGenerator) GenerateMesh

func (mg *MeshGenerator) GenerateMesh(atlas [][]int, squareSize float32)

GenerateMesh generates mesh based on atlas, squareSize, and displacement

func (*MeshGenerator) GetTriangles

func (mg *MeshGenerator) GetTriangles() ([]ebiten.Vertex, []uint16)

GetTriangles returns the verteces and the indices after generating the mesh

func (*MeshGenerator) MeshFromPoints

func (mg *MeshGenerator) MeshFromPoints(points ...Node)

MeshFromPoints sets triangle points to meshes

func (*MeshGenerator) TriangulateSquare

func (mg *MeshGenerator) TriangulateSquare(square Square)

TriangulateSquare translate square configs to ebiten verteces and indeces

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node gives position based on index

func NewNode

func NewNode(pos Vector2) *Node

NewNode initializes node with default index, given position

func (*Node) Consume

func (n *Node) Consume()

Consume will be used if vertexindex is set

func (*Node) IsConsumed

func (n *Node) IsConsumed() bool

IsConsumed gives true if vertexIndex is already consumed or set

type Square

type Square struct {
	// contains filtered or unexported fields
}

Square ...

func NewSquare

func NewSquare(topLeft, topRight, bottomRight, bottomLeft *ControlNode) *Square

NewSquare ...

type SquareGrid

type SquareGrid struct {
	// contains filtered or unexported fields
}

SquareGrid ...

func NewSquareGrid

func NewSquareGrid(atlas [][]int, squareSize float32) *SquareGrid

NewSquareGrid ...

type Triangle

type Triangle struct {
	// contains filtered or unexported fields
}

Triangle ...

func NewTriangle

func NewTriangle(a, b, c int) *Triangle

NewTriangle generates new Triangle

func (*Triangle) At

func (t *Triangle) At(i int) int

At accepts vertex index returns vertex number

type Vector2

type Vector2 struct {
	// contains filtered or unexported fields
}

Vector2 similar to unity2d Vector2

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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