Skip to main content
1 of 5
Engineer
  • 30.3k
  • 4
  • 75
  • 123

See working code here. For your future reference:

  • This algorithm is called DDA (digital differential analyser). The canonical implementation requires cell co-ordinates to be a floating point value with each increment of 1 denoting the width of a full cell. Thus in x, the start of the first cell's edge is 0, the middle of the second cell is 1.5, 2/3s through the third cell is 2.67, etc. The first thing you needed to do was to divide your mouseVector values by CELLSIZE and work only in this form, never in CELLSIZEd form.
  • use canonical / industry standard naming e.g. raycastCollision -> rayMarch.
  • simplify your naming: drawCellOutline -> outlineCell (matches your fillCell)
  • do not repeat yourself in function call parameters which you can include within the function itself e.g. fillCell(x * CELLSIZE, y * CELLSIZE) -> fillCell(x, y); since they are grid-aligned they must all be of CELLSIZE, not so?
  • if you are learning from example code as in this case, do not change variable names within the function(s). Rather copy out your values from your custom vector mouseVector into x0, y0, x1, y1 as per the original as this helps you avoid at least one class of mistakes / errors.
  • do not expect to use the advanced / optimised version of an algorithm until you have studied and understood the basic version.
Engineer
  • 30.3k
  • 4
  • 75
  • 123