Git Diff: Understanding Changes in Code Files

Git Diff: Understanding Changes in Code Files

Overview

In the car.js file, the #move() method is now only called when the car is not damaged. Additionally, a new #createPolygon() method was added to calculate the car's polygon for collision detection and a #assesDamage() method to assess damage based on road borders. The draw() method now uses the polygon to draw a car and changes its color to gray if the car is damaged.

In the utils.js file, a new polysIntersect() function was added to check if two polygons intersect. This function is used in the #assesDamage() method in car.js to determine if the car has collided with a road border.

File wise changes made

car.js

  • Removed the line this.#move(); from the update() function and added an conditional check to see if the car is damaged before moving it.
  • Added a new function #createPolygon() that calculates the vertices of the car's polygon shape based on its width, height, and angle.
  • Added a new function #assesDamage() that checks if the car's polygon intersects with any of the road borders and updates the damaged property accordingly.
  • Modified the draw() function to fill the car's shape with a gray color if it is damaged, otherwise fill it with black.
  • Changed the way the car's polygon is drawn by using the moveTo() and lineTo() methods to define the shape instead of using the rect() method.

utils.js

  • Added a new function polysIntersect() that checks if two polygons intersect with each other.
  • Modified the getIntersection() function to return null if the lines do not intersect, instead of throwing an error.

Summary

In car.js, the update() method has been modified as follows:

  • The this.#move() function is now conditionally executed within an if statement that checks if the car is not damaged.
  • If the car is not damaged, the this.#move() function is executed, the car's polygon is created using the new #createPolygon() function, and the car's damaged state is assessed using the new #assesDamage() function.
  • The this.sensor.update(roadBorders); line has been moved to be below the conditional if statement.

In utils.js, the following changes have been made:

  • A new function called polysIntersect() has been added. This function takes two polygons as input and returns true if the polygons intersect, and false otherwise.
  • The getIntersection() function has been modified to return a boolean value indicating whether the two line segments intersect.
  • The No newline at end of file comment has been removed.