ShapeGen

The muscles.

Home

Classes

• TileMap
• ShapeGen
• TerrainGenerator

Extra

• Tutorials
• Demo

Description

ShapeGen is intended to separate the geometric tile math from the terrain generation logic. Three shapes are currently implemented; rectangles, triangles, and circles. This may seem bare bones but we were surprised by the amount of realistic terrain we could make with rectangles and circles alone.

ShapeGen handles renderable creation, and provides two options for the types of renderables created. A simple renderable can be used, and only a color array is required to make the shape. Alternatively, a texture and UV array can be passed to make a SpriteRenderable. Textures should be loaded in the main game class before drawing any shapes. The UV coordinate array is our method of reducing the size and complexity of our function signatures. It follows the form:

[ Left_Bound, Right_Bound, Bottom_Bound, Top_Bound ]

Where each bound is the UV coordinate of the sprite you would like to draw. If you want to use the entirety of a texture rather than part of a sprite sheet, simply use the array:

[0, 1, 0, 1].

Otherwise, use the fraction of the pixel coordinate of your desired bound divided by the respective length or width of the sprite sheet.

Constructor

new ShapeGen (tileMap)

Constructor that creates a ShapeGen object

tileMap | TileMap | The TileMap that ShapeGen will operate on

Methods

rectangle (x, y, height, width, color)

Creates a colored rectangle at given tile x and y

x | int | The tile x to put the rectangle at
y | int | The tile y to put the rectangle at
height | int | The height in tiles of the rectangle
width | int | The width in tiles of the rectangle
color | [float] | The color array for the tiles to be colored


texturedRectangle (x, y, height, width, texture, color, UVArray)

Creates a textured rectangle at given tile x and y

x | int | The tile x to put the rectangle at
y | int | The tile y to put the rectangle at
height | int | The height in tiles of the rectangle
width | int | The width in tiles of the rectangle
texture | string | The texture file to use
color | [float] | The color array for the tiles to be colored
UVArray | [float] | The UV coordinates the specify the texture


triangle (x, y, width, color)

Creates a colored triangle at given tile x and y

x | int | The tile x to put the triangle at
y | int | The tile y to put the triangle at
width | int | The width in tiles of the triangle
color | [float] | The color array for the tiles to be colored


texturedTriangle (x, y, width, texture, color, UVArray)

Creates a textured triangle at given tile x and y

x | int | The tile x to put the triangle at
y | int | The tile y to put the triangle at
width | int | The width in tiles of the triangle
texture | string | The texture file to use
color | [float] | The color array for the tiles to be colored
UVArray | [float] | The UV coordinates the specify the texture


circle (xc, yc, r, color, fill)

Creates a colored circle centered at given tile x and y

xc | int | The tile x to put the circle at
yc | int | The tile y to put the circle at
r | int | The radius of the circle
color | [float] | The color array for the tiles to be colored
fill | boolean | True for filled in circle, false for empty circle


texturedCircle (xc, yc, r, texture, color, UVArray, fill)

Creates a textured circle centered at given tile x and y

xc | int | The tile x to put the circle at
yc | int | The tile y to put the circle at
r | int | The radius of the circle
texture | string | The texture file to use
color | [float] | The color array for the tiles to be colored
fill | boolean | True for filled in circle, false for empty circle
UVArray | [float] | The UV coordinates the specify the texture


_drawCircle (xc, yc, x, y, color)

Private helper function that draws the colored circle

xc | int | The x center of the circle
yc | int | The y center of the circle
x | int | The calculated x offset
y | int | The calculated y offset
color | [float] | The color array for the tiles to be colored


_drawTexturedCircle (xc, yc, x, y, texture, color, UVArray)

Private helper function that draws the textured circle

xc | int | The x center of the circle
yc | int | The y center of the circle
x | int | The calculated x offset
y | int | The calculated y offset
texture | string | The texture file to use
color | [float] | The color array for the tiles to be colored
UVArray | [float] | The UV coordinates the specify the texture