Skip to content

Commit

Permalink
fix: linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
NuclearRedeye committed Nov 26, 2024
1 parent d422319 commit 724260b
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/ts/data/levels/level00.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ export const level00: Level = {
[sw(1), sw(1), sw(5), sw(1), sst(4), sw(2), tw(2), sw(2), sw(2), sw(2)]
],
entities: [],
sprites: [sbnt(4.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM), sb(5.5, 5.5, 5, 1), sb(6.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM | SpriteProperties.STATIC), sb(7.5, 5.5, 5, 0.25, SpriteProperties.ALIGN_TOP)],
sprites: [sbnt(4.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM), sb(5.5, 5.5, 5, 1), sb(6.5, 5.5, 11, 0.25, SpriteProperties.ALIGN_BOTTOM | SpriteProperties.STATIC), sb(7.5, 5.5, 5, 0.25, SpriteProperties.ALIGN_TOP)]
};
9 changes: 4 additions & 5 deletions src/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ function onTick(timestamp: number): void {
// If enabled, draw the minimap
if (minimap) {
const player = getPlayer();
frontBuffer.fillStyle = "green";
frontBuffer.fillStyle = 'green';
frontBuffer.fillRect(frontBufferProps.x + 10, frontBufferProps.y + 10, frontBufferProps.width * 0.2, frontBufferProps.height * 0.2);

// Draw the direction Vector
const directionStart = {
x: frontBufferProps.x + 10 + ((frontBufferProps.width * 0.2) / 2),
y: frontBufferProps.y + 10 + ((frontBufferProps.height * 0.2) / 2)
}
x: frontBufferProps.x + 10 + (frontBufferProps.width * 0.2) / 2,
y: frontBufferProps.y + 10 + (frontBufferProps.height * 0.2) / 2
};

const directionEnd = vu.add(directionStart, vu.scale(player.direction, 20));

Expand Down Expand Up @@ -174,7 +174,6 @@ function onTick(timestamp: number): void {
frontBuffer.fillText(`Angle: ${player.getAngle().toFixed(2)} Degrees`, 15, 15);
frontBuffer.fillText(`FOV: ${player.getFOV().toFixed(2)} Degrees`, 15, 30);
}

}

window.requestAnimationFrame(onTick);
Expand Down
2 changes: 1 addition & 1 deletion src/ts/interfaces/circle.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Vector } from "./vector";
import type { Vector } from './vector';

export interface Circle {
position: Vector;
Expand Down
10 changes: 5 additions & 5 deletions src/ts/objects/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import type { Level } from '../interfaces/level';

import * as vu from '../utils/vector-utils.js';
import { radiansToDegrees } from '../utils/math-utils.js';
import { isBlocked, isInteractive, isSolid } from '../utils/cell-utils.js';
import { isBlocked, isSolid } from '../utils/cell-utils.js';
import { getCell } from '../utils/level-utils.js';

export class Entity implements Dynamic{
export class Entity implements Dynamic {
position: Vector;
direction: Vector;
camera: Vector;
Expand Down Expand Up @@ -44,12 +44,12 @@ export class Entity implements Dynamic{
update(elapsed: number): void {}

rotate(amount: Radian): void {
this.direction = vu.rotate(this.direction, amount)
this.camera = vu.rotate(this.camera, amount)
this.direction = vu.rotate(this.direction, amount);
this.camera = vu.rotate(this.camera, amount);
}

move(amount: number, level: Level): void {
const position = vu.add(this.position, vu.scale(this.direction, amount))
const position = vu.add(this.position, vu.scale(this.direction, amount));

// Check for a collision on the X Axis
const xCell = getCell(level, Math.floor(position.x), Math.floor(this.position.y));
Expand Down
2 changes: 1 addition & 1 deletion src/ts/raycaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getAnimationFrame } from './utils/time-utils.js';
import { applyEffectTint, getTextureById, isTextureAnimated, isTextureStateful } from './utils/texture-utils.js';
import { isSpriteAlignedBottom, isSpriteAlignedTop, isSpriteStatic, isSpriteTinted } from './utils/sprite-utils.js';
import { radiansToDegrees } from './utils/math-utils.js';
import * as vu from './utils/vector-utils.js'
import * as vu from './utils/vector-utils.js';

// Derived from https://lodev.org/cgtutor/raycasting.html.
// Casts a ray from the specified point at the specified angle and returns the first Wall the ray impacts.
Expand Down
4 changes: 2 additions & 2 deletions src/ts/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Vector } from "./interfaces/vector";
import { Vector } from './interfaces/vector';

export type Radian = number;
export type Scaler = Vector;
export type Scaler = Vector;
4 changes: 2 additions & 2 deletions src/ts/utils/math-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function degreesToRadians(degrees: number): number {

// Converts a value from Radians to Degrees.
export function radiansToDegrees(radians: number): number {
let theta = radians * 180 / Math.PI;
let theta = (radians * 180) / Math.PI;
if (theta < 0) theta += 360;
return theta;
}
}
19 changes: 9 additions & 10 deletions src/ts/utils/vector-utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Vector } from "../interfaces/vector";
import { Vector } from '../interfaces/vector';

export type Scaler = number;
export type Radian = number;
Expand All @@ -9,15 +9,15 @@ export function create(x: number = 0, y: number = 0): Vector {
return {
x,
y
}
};
}

export function normalise(v: Vector): Vector {
const magnitude = Math.sqrt((v.x * v.x) + (v.y * v.y));
const magnitude = Math.sqrt(v.x * v.x + v.y * v.y);
return {
x: v.x / magnitude,
y: v.y / magnitude
}
};
}

export function add(a: Vector, b: Vector): Vector {
Expand All @@ -38,31 +38,30 @@ export function multiply(a: Vector, b: Vector): Vector {
return {
x: a.x * b.x,
y: a.y * b.y
}
};
}

export function scale(a: Vector, factor: number): Vector {
return {
x: a.x * factor,
y: a.y * factor
}
};
}

export function rotate(v: Vector, radians: Radian): Vector {
return {
x: v.x * Math.cos(radians) - v.y * Math.sin(radians),
y: v.x * Math.sin(radians) + v.y * Math.cos(radians)
}
};
}

export function dot(a: Vector, b: Vector): Scaler {
return (a.x * b.x) + (a.y * b.y);
return a.x * b.x + a.y * b.y;
}

export function angle(a: Vector, b?: Vector): Radian {
if (b !== undefined) {
return Math.acos(dot(a,b));
return Math.acos(dot(a, b));
}
return Math.atan2(a.y, a.x);
}

0 comments on commit 724260b

Please sign in to comment.