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 theupdate()
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 thedamaged
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()
andlineTo()
methods to define the shape instead of using therect()
method.
utils.js
- Added a new function
polysIntersect()
that checks if two polygons intersect with each other. - Modified the
getIntersection()
function to returnnull
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 anif
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 conditionalif
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 returnstrue
if the polygons intersect, andfalse
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.