Skip to content

Commit

Permalink
feat: add color and damage color properties to car [#1]
Browse files Browse the repository at this point in the history
  • Loading branch information
d3p1 committed Nov 10, 2024
1 parent e21c25e commit eaa48f9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export default class App {
this.canvas.height - this.canvas.height * 0.2,
50,
100,
'hsl(10,100%,50%)',
'hsl(0,0%,30%)',
200,
this.carControl,
)
Expand Down
27 changes: 21 additions & 6 deletions docs/js/core/car.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export default class Car {
*/
height

/**
* @type {string}
*/
color

/**
* @type {string}
*/
damageColor

/**
* @type {Control}
*/
Expand All @@ -77,15 +87,19 @@ export default class Car {
* @param {number} centerY
* @param {number} width
* @param {number} height
* @param {string} color
* @param {string} damageColor
* @param {number} force
* @param {Control} control
* @param {Sensor} sensor
*/
constructor(
centerX,
centerY,
width,
height,
width = 50,
height = 100,
color = 'hsl(200,100%,50%)',
damageColor = 'hsl(0,0%,30%)',
force = 200,
control = new Control(),
sensor = new Sensor(),
Expand All @@ -94,6 +108,8 @@ export default class Car {
this.centerY = centerY
this.width = width
this.height = height
this.color = color
this.damageColor = damageColor
this.force = force
this.control = control
this.sensor = sensor
Expand All @@ -106,7 +122,7 @@ export default class Car {
* @param {{x: number, y: number}[][]} roadBorders Road borders
* @returns {void}
*/
update(t, roadBorders) {
update(t, roadBorders = []) {
if (!this.isDamage) {
this.control.update(t)

Expand All @@ -129,13 +145,12 @@ export default class Car {
*
* @param {CanvasRenderingContext2D} context
* @returns {void}
* @todo Define car color normal and damage fill style as property
*/
draw(context) {
context.save()
context.fillStyle = 'hsl(0,0%,0%)'
context.fillStyle = this.color
if (this.isDamage) {
context.fillStyle = 'hsl(0,0%,30%)'
context.fillStyle = this.damageColor
}
this.#draw(context)
context.restore()
Expand Down

0 comments on commit eaa48f9

Please sign in to comment.