Home

Awesome

raycaster-go

Golang raycasting engine using the Ebitengine 2D Game Library to render a 3-Dimensional perspective in a 2-Dimensional view. It was originally converted from the C# based OwlRaycastEngine, which in turn was created based on a raycasting tutorial.

To see it in action visit the YouTube playlist.

Screenshot

Demo

The raycaster-go-demo project is available as an example of how to use the raycaster-go engine as a module.

Developer setup

To get started with your own project using the raycaster-go engine as a Go module:

  1. Download, install, and setup Golang https://golang.org/dl/
  2. Setup your project to use go modules: go mod init github.com/yourname/yourgame
  3. Download the raycaster-go module: go get github.com/harbdog/raycaster-go

NOTE: Depending on the OS, the Ebitengine game library may have additional dependencies to install.

Creating your own raycaster project

You will first want to become familiar with how to use the Ebitengine 2D Game Library. It has all of the APIs needed to render images on a 2D canvas, handle inputs from the player, and even play sounds. The raycaster-go-demo is available for reference.

Ebitengine interfaces

Just like any other Ebitengine game, there are a few game interface functions required from your game implementation:

Refer to the Ebitengine tour pages for detailed explanation about the usage of these interface functions needed for basic game flow.

Raycaster-go interfaces

There are additional raycaster-go specific interfaces that will be required to render the map levels, wall textures, and sprites.

Map interfaces

Interface functions required to provide layout of wall positions on the 2-dimensional array representing the game map.

Level(levelNum int) [][]int

NumLevels() int

TextureHandler interfaces

Interface functions required for rendering texture images for the walls and floor.

TextureAt(x, y, levelNum, side int) *ebiten.Image

FloorTextureAt(x, y int) *image.RGBA

Sprite interfaces

Interface functions required to determine sprite images and positions to render in game.

Pos() *geom.Vector2

PosZ() float64

VerticalAnchor() raycaster.SpriteAnchor

Scale() float64

Texture() *ebiten.Image

TextureRect() image.Rectangle

SetScreenRect(rect *image.Rectangle)

Illumination() float64

IsFocusable() bool

Raycaster-go camera

After implementing all required interface functions, the last step is to initialize an instance of raycaster.Camera and make the function calls needed to update and draw during your game loop.

func NewCamera(width int, height int, texSize int, mapObj Map, tex TextureHandler) *Camera

camera.SetPosition(pos *geom.Vector2)

camera.SetPositionZ

camera.SetHeadingAngle

camera.SetPitchAngle

camera.SetFloorTexture(floor *ebiten.Image)

camera.SetSkyTexture(sky *ebiten.Image)

camera.Update(sprites []Sprite)

camera.Draw(screen *ebiten.Image)

Optional camera functions

camera.SetRenderDistance(distance float64)

camera.SetLightFalloff(falloff float64)

camera.SetGlobalIllumination(illumination float64)

camera.SetLightRGB(min, max color.NRGBA)

camera.GetConvergencePoint() *geom3d.Vector3

camera.GetConvergenceDistance() float64

camera.GetConvergenceSprite() Sprite

camera.SetAlwaysSetSpriteScreenRect(b bool)

Limitations