implement sounds

This commit is contained in:
LabyStudio
2022-02-13 07:55:40 +01:00
parent 82ea74085b
commit c955fdc7f9
42 changed files with 209 additions and 2 deletions
@@ -2,7 +2,18 @@ window.Block = class {
static blocks = new Map();
static sounds = {};
static create() {
// Sounds
Block.sounds.stone = new Sound("stone", 1.0);
Block.sounds.wood = new Sound("wood", 1.0);
Block.sounds.gravel = new Sound("gravel", 1.0);
Block.sounds.grass = new Sound("grass", 1.0);
Block.sounds.cloth = new Sound("cloth", 1.0);
Block.sounds.sand = new Sound("sand", 1.0);
// Blocks
Block.STONE = new BlockStone(1, 0);
Block.GRASS = new BlockGrass(2, 1);
Block.DIRT = new BlockDirt(3, 2);
@@ -17,8 +28,12 @@ window.Block = class {
this.id = id;
this.textureSlotId = textureSlotId;
// Bounding box
this.boundingBox = new BoundingBox(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
// Default sound
this.sound = Block.sounds.stone;
// Register block
Block.blocks.set(id, this);
}
@@ -60,6 +75,14 @@ window.Block = class {
return true;
}
isLiquid() {
return false;
}
getSound() {
return this.sound;
}
getBoundingBox(world, x, y, z) {
return this.boundingBox;
}
@@ -2,6 +2,9 @@ window.BlockDirt = class extends Block {
constructor(id, textureSlotId) {
super(id, textureSlotId);
// Sound
this.sound = Block.sounds.gravel;
}
}
@@ -2,6 +2,9 @@ window.BlockGrass = class extends Block {
constructor(id, textureSlotId) {
super(id, textureSlotId);
// Sound
this.sound = Block.sounds.grass;
}
getTextureForFace(face) {
@@ -2,6 +2,9 @@ window.BlockLeave = class extends Block {
constructor(id, textureSlotId) {
super(id, textureSlotId);
// Sound
this.sound = Block.sounds.grass;
}
getOpacity() {
@@ -2,6 +2,9 @@ window.BlockLog = class extends Block {
constructor(id, textureSlotId) {
super(id, textureSlotId);
// Sound
this.sound = Block.sounds.wood;
}
getTextureForFace(face) {
@@ -2,6 +2,9 @@ window.BlockSand = class extends Block {
constructor(id, textureSlotId) {
super(id, textureSlotId);
// Sound
this.sound = Block.sounds.sand;
}
}
@@ -5,6 +5,9 @@ window.BlockTorch = class extends Block {
this.boundingBox = new BoundingBox(0.4, 0.0, 0.4, 0.6, 0.6, 0.6);
// Sound
this.sound = Block.sounds.wood;
// Create data faces
this.dataFaces = [
EnumBlockFace.WEST,
@@ -12,6 +12,10 @@ window.BlockWater = class extends Block {
return false;
}
isLiquid() {
return true;
}
canInteract() {
return false;
}
@@ -0,0 +1,20 @@
window.Sound = class {
constructor(name, pitch) {
this.name = name;
this.pitch = pitch;
}
getBreakSound() {
return "step." + this.name;
}
getStepSound() {
return "step." + this.name;
}
getPitch() {
return this.pitch;
}
}