Skip to content

mewbak/2d-vision

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

2D vision

Implementing a some game graphic concepts in Go, using ebiten 2d graphics library. Thanks to @hajimehoshi for support. Examples are hosted at jsgo.io. Latest version here: https://jsgo.io/kyeett/2d-vision

Heavily inspired by Red Blob Games' article on 2D visibility. Also found this excellent wikipedia article on Visibility polygon)

Disclaimer

The code in this library is quite messy. Use with care :-)

Basic ray casting

Simple algorithm. Send rays in all directions. If it intersects with one of the lines (walls or boxes), select the point that is closest to the player and draw a line to there. These lines used as vertices for triangles that are removed from the shadows.

Demo here

Basic Ray Casting

Smarter ray casting

Calculate the angles to the corners of all objects, and do the ray cast only in that angle.

Note: At first, I had a lot of problems with the rays stopping ON the corners. I solved this by sending two lines per corner, with a small offset to the angle in both directions. It works well, but doubles the number of lines. I'm not sure if this is the right approach.

Demo here

Smart Ray Casting

Resources:

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%