The following C++ function does line-of-sight testing for a 2D game that uses tiles. The level map is a multidimensional array of integers (levelmap[LEVEL_HEIGHT][LEVEL_WIDTH]) that represent each tile; 0 signifies and empty tile, any number higher than that is solid. A vector2 is just a datatype that contains an object's x and y position.
// Check line of sight between two points (usually the camera/player)
Continue Reading »