File size: 1,505 Bytes
7ffaa9e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Transform } from './transform.js';
import { Matrix } from './matrix.js';
import { getConfig } from './config.js';

export class Entity {
    constructor() {
        this.transform = new Transform();
        this.boundingBox = { width: 0, height: 0 };
    }

    draw(ctx, camera) {
        const config = getConfig();
        const viewMatrix = camera.getViewMatrix();
        const worldMatrix = this.transform.getWorldMatrix();
        const finalMatrix = Matrix.multiply(worldMatrix, viewMatrix);
        const position = Matrix.transformPoint(finalMatrix, { x: 0, y: 0, z: 0 });
        const scale = this.transform.scale.x * camera.scale;

        // Draw entity as a simple red semi-transparent rectangle
        const width = this.boundingBox.width * scale;
        const height = this.boundingBox.height * scale;

        ctx.fillStyle = 'rgba(255, 0, 0, 0.2)';
        ctx.fillRect(
            position.x - width / 2,
            position.y - height / 2,
            width,
            height
        );

        // Draw debug bounding box if enabled
        if (config.debug.showBoundingBoxes) {
            ctx.save();
            ctx.strokeStyle = 'red';
            ctx.lineWidth = 1;
            ctx.strokeRect(
                position.x - width / 2,
                position.y - height / 2,
                width,
                height
            );
            ctx.restore();
        }
    }

    // Override this in derived classes
    drawEntity(ctx, position, scale) { }
}