Visuak break progress !
This commit is contained in:
@@ -1,9 +1,20 @@
|
||||
import { SLOT_SIZE } from "$/common/constants.ts";
|
||||
import { SLOT_SIZE, TEXTURE_SIZE } from "$/common/constants.ts";
|
||||
import { AssetManager } from "$/client/assets.ts";
|
||||
import { PlayerInventory } from "../../inventory.ts";
|
||||
import { draw_item, draw_nine_slice } from "./render_utils.ts";
|
||||
import { canvas, draw_rect_stroke, push_back_face, Texture } from "$/client/renderer/mod.ts";
|
||||
import {
|
||||
canvas,
|
||||
draw_rect_stroke,
|
||||
push_back_face,
|
||||
push_bottom_face,
|
||||
push_front_face,
|
||||
push_left_face,
|
||||
push_right_face,
|
||||
push_top_face,
|
||||
Texture,
|
||||
} from "$/client/renderer/mod.ts";
|
||||
import { PlayerComponent } from "../../player.ts";
|
||||
import { get_sprite_region } from "../../../common/utils.ts";
|
||||
|
||||
const PADDING = 10;
|
||||
|
||||
@@ -68,3 +79,42 @@ export function render_player_crosshair() {
|
||||
[0, 0, 0, 0.6],
|
||||
);
|
||||
}
|
||||
|
||||
const FACE_FUNCTIONS = [
|
||||
push_back_face,
|
||||
push_bottom_face,
|
||||
push_front_face,
|
||||
push_left_face,
|
||||
push_right_face,
|
||||
push_top_face,
|
||||
];
|
||||
export function render_player_breaking(player_component: PlayerComponent) {
|
||||
const block = player_component.breaking_block;
|
||||
if (block) {
|
||||
const tex = AssetManager.instance.get<Texture>("bworld:textures");
|
||||
|
||||
const progress = Math.max(
|
||||
0,
|
||||
Math.min(1, player_component.break_progress / player_component.break_progress_max),
|
||||
);
|
||||
const break_sprite = Math.round(progress * 8);
|
||||
|
||||
if (Number.isNaN(break_sprite)) {
|
||||
return;
|
||||
}
|
||||
const region = get_sprite_region(`bworld:break_${break_sprite}`);
|
||||
|
||||
for (const fn of FACE_FUNCTIONS) {
|
||||
fn(
|
||||
tex,
|
||||
block.x,
|
||||
block.y,
|
||||
block.z,
|
||||
region.x * TEXTURE_SIZE,
|
||||
region.y * TEXTURE_SIZE,
|
||||
TEXTURE_SIZE,
|
||||
TEXTURE_SIZE,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user