Visuak break progress !
This commit is contained in:
@@ -111,9 +111,9 @@ export class PlayerControlsSystem extends System {
|
||||
InputManager.set_mouse_grabbed(player_component.screens.length === 0);
|
||||
|
||||
if (InputManager.is_mouse_down(0) && player_component.screens.length === 0) {
|
||||
player_component.breaking_block = true;
|
||||
player_component.breaking_block = { x: 0, y: 9999, z: 0 };
|
||||
} else {
|
||||
player_component.breaking_block = false;
|
||||
player_component.breaking_block = undefined;
|
||||
player_component.break_progress_max = 0;
|
||||
player_component.break_progress = 0;
|
||||
}
|
||||
@@ -123,6 +123,7 @@ export class PlayerControlsSystem extends System {
|
||||
if (block && player_component.screens.length === 0) {
|
||||
const block_info = EverythingRegistry.get_by_id<BlockRegistry>("blocks", block.block)!;
|
||||
if (player_component.breaking_block) {
|
||||
player_component.breaking_block = { x: block.x, y: block.y, z: block.z };
|
||||
player_component.break_progress_max = block_info.toughness ?? 9999;
|
||||
player_component.break_progress += delta;
|
||||
if (player_component.break_progress >= player_component.break_progress_max) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Camera } from "$/client/components/camera.ts";
|
||||
|
||||
import { render_animated_sprite, render_sprite } from "./rendering/sprites.ts";
|
||||
import { render_dimension } from "./rendering/dimension.ts";
|
||||
import { render_player_crosshair, render_player_hotbar } from "./rendering/player.ts";
|
||||
import { render_player_breaking, render_player_crosshair, render_player_hotbar } from "./rendering/player.ts";
|
||||
import { PlayerComponent } from "../player.ts";
|
||||
import { begin_mode_3d, end_mode_3d } from "../renderer/core.ts";
|
||||
|
||||
@@ -32,6 +32,11 @@ export class RenderSystem extends System {
|
||||
if (dimension) {
|
||||
render_dimension(dimension, camera);
|
||||
}
|
||||
|
||||
const player_component = entity.get(PlayerComponent);
|
||||
if (player_component) {
|
||||
render_player_breaking(player_component);
|
||||
}
|
||||
}
|
||||
|
||||
end_mode_3d();
|
||||
|
||||
@@ -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