Skip to content

Commit

Permalink
feat: add draw meter to isocanvas
Browse files Browse the repository at this point in the history
  • Loading branch information
hxtree committed Nov 20, 2024
1 parent f8ef73a commit 7c3419b
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { MeterProps } from './MeterProps';
import { GRID_WIDTH } from '../utils/GridDimensions';

export function drawMeter(ctx: CanvasRenderingContext2D, props: MeterProps) {
const x = props.x;
const y = props.y;
const width = props.width ?? GRID_WIDTH;
const height = props.height ?? 5;
const percent = props.percent ? props.percent * 0.01 : 1;
const lineWidth = props.lineWidth ?? 2;
const strokeColor = props.strokeColor ?? '#000';
const fillColor = props.fillColor ?? '#f00';

const startX = x - width / 2;
const startY = y;

ctx.lineWidth = lineWidth;
ctx.strokeStyle = strokeColor;

// Draw the background rectangle
ctx.beginPath();

ctx.globalAlpha = 0.618;
ctx.fillStyle = '#000';
ctx.rect(startX, startY, width, height);
ctx.fill();
ctx.stroke();
ctx.globalAlpha = 1.0;

// Draw the filled rectangle
const filledWidth = width * percent;
ctx.fillStyle = fillColor;
ctx.fillRect(startX, startY, filledWidth, height);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type MeterProps = {
x: number;
y: number;
percent: number;
width?: number;
height?: number;
lineWidth?: number;
strokeColor?: string;
fillColor?: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { kebabCase } from 'lodash';
import { GridAnimations } from '../types/Animation.type';
import { Duration } from 'luxon';
import { ActorModel } from '../models/Actor.model';
import { drawMeter } from '../draw/DrawMeter';

export class IsometricRender {
private tilesRendered: number = 0;
Expand Down Expand Up @@ -313,6 +314,13 @@ export class IsometricRender {
x: vectors.right.x - (vectors.right.x - vectors.left.x),
y: vectors.top.y - 17,
});

// TODO determine percent based on actor's health
drawMeter(ctx, {
x: vectors.left.x,
y: vectors.top.y - 17 - (actor.height ?? 60),
percent: 50,
});
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion clients/design-system/stories/game-assets/data/Sewer.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"currentAnimation": "look1",
"startingFrame": 0,
"totalFrames": 3,
"frameDuration": { "seconds": 0.83 },
"frameDuration": { "seconds": 10 },
"isAnimating": true
},
"wave1": {
Expand Down
4 changes: 0 additions & 4 deletions clients/design-system/stories/game-assets/data/TrainRoom.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
}
],
"dialogues": [
{
"actorId": "MEEKU_ONI",
"text": "Look at that! A new game engine!"
}
],
"spriteMapRegistry": {
"f": "/game-assets/fadewall-1x1.png",
Expand Down

0 comments on commit 7c3419b

Please sign in to comment.