Compare commits

...
Sign in to create a new pull request.

19 commits
hecs ... master

Author SHA1 Message Date
67822f9f31 Update npm dependencies
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2022-11-28 17:19:16 -05:00
a7d7d219a8 Optimize release builds for filesize 2022-11-28 17:18:52 -05:00
3674e4c26a Improve wall destruction sound
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2022-11-27 23:53:27 -05:00
a7759cfa06 Fix wasm target 2022-11-27 23:53:03 -05:00
3ca0eb1eea Use simpler algorithm for PC speaker tones
All checks were successful
continuous-integration/drone/push Build is passing
2022-11-27 22:36:39 -05:00
4b0b67c69a Fix whipping input 2022-11-27 22:29:00 -05:00
74d1c120fc Revert "Use FunDSP crate for beepboops"
This reverts commit 9219b6c475.
2022-11-24 00:05:11 -05:00
9dcd94932f Crate updates 2022-11-23 23:57:14 -05:00
38d3333635 Implement whipping blocks and trees
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2022-02-10 17:40:00 -05:00
36d109654c Add more one-time flashing messages 2022-02-09 21:28:15 -05:00
ce05dcb194 Implement speed and slow spells
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-08 21:02:42 -05:00
3129f1be1d Be specific with cargo dependencies 2022-02-08 19:59:33 -05:00
9e83e004dc Suppress clippy warning in wasm_bindgen macro 2022-02-08 19:58:18 -05:00
7c93fb2bae Add web build and deploy to CI
Some checks reported errors
continuous-integration/drone/push Build was killed
continuous-integration/drone Build is passing
2022-02-04 21:37:07 -05:00
c17013ac92 Don't allow quitting on the web
All checks were successful
continuous-integration/drone/push Build is passing
2022-02-04 19:55:21 -05:00
f08691a62e Add webpack 2022-02-04 19:44:58 -05:00
ecd7c87e29 Add lib target for wasm 2022-02-04 19:28:31 -05:00
cbcda28719 Initial web support 2022-02-04 19:09:59 -05:00
4cd9f5acc3 Include numpad numbers in input 2022-02-04 00:22:05 -05:00
35 changed files with 4844 additions and 415 deletions

View file

@ -6,12 +6,15 @@ steps:
image: rust
commands:
- apt-get update
- apt-get install -y libasound2-dev g++-mingw-w64-x86-64
- apt-get install -y libasound2-dev g++-mingw-w64-x86-64 npm
- rustup target add x86_64-pc-windows-gnu
- rustup toolchain install stable-x86_64-pc-windows-gnu
- cargo build --release --verbose --all
- rustup target add wasm32-unknown-unknown
- cargo build --release --verbose --all --target x86_64-unknown-linux-gnu
- cargo build --release --verbose --all --target x86_64-pc-windows-gnu
- mv target/release/kroz kroz_linux_x86_64
- npm install
- npm run build
- mv target/x86_64-unknown-linux-gnu/release/kroz kroz_linux_x86_64
- mv target/x86_64-pc-windows-gnu/release/kroz.exe kroz_win_x86_64.exe
- name: release
image: plugins/gitea-release
@ -29,3 +32,22 @@ steps:
when:
event:
- tag
- name: deploy
image: alpine
volumes:
- name: krozhtml
path: /html
commands:
- rm -r /html/*.wasm || true
- cp -r dist/* /html/
- chown -R 1000:1000 /html/*
when:
event:
- promote
target:
- production
volumes:
- name: krozhtml
host:
path: /home/alex/docker/kroz/files

4
.gitignore vendored
View file

@ -1,3 +1,7 @@
/extern
/target
.vscode
/pkg
node_modules
/dist
/wasm-pack.log

560
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -4,15 +4,32 @@ version = "0.1.0"
edition = "2021"
build = "build.rs"
[lib]
name = "libkroz"
crate-type = ["cdylib", "rlib"]
[[bin]]
name = "kroz"
path = "src/main.rs"
[dependencies]
# bracket-lib = { path = "extern/bracket-lib" }
bracket-lib = { git = "https://github.com/amethyst/bracket-lib" }
hecs = "0.5.1"
hecs = "0.9.0"
specs-derive = "0.4.1"
cpal = "0.13"
oddio = "0.5"
fundsp = "0.1.0"
cpal = { version = "0.14.1", features = ["wasm-bindgen"] }
oddio = "0.6.2"
typenum = "1.15.0"
console_error_panic_hook = "0.1.7"
wasm-bindgen = "0.2.79"
instant = "0.1.12"
rand = "0.8.5"
getrandom = { version = "0.2.4", features = ["js"] }
[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
winres = "0.1.12"
[profile.release]
lto = true
opt-level = 's'

View file

@ -17,13 +17,19 @@ The goal is to closely mimic the look and behavior of the original game, but not
- Game speed will be fixed, possibly configurable
- The original game's speed varied with CPU speed
- Improve control response
- Support Windows, Linux, macOS
- Possibly web and mobile platforms too
- Support Windows, Linux, macOS, and the web
## Building
1. [Install Rust](https://rustup.rs/)
2. Run `cargo build` or `cargo run`
[Install Rust](https://rustup.rs/)
### Desktop
Run `cargo build` or `cargo run`
### Web
Run `npm run build` or `npm start`
## License

View file

@ -1,12 +1,12 @@
#[cfg(target_os = "windows")]
#[cfg(windows)]
extern crate winres;
#[cfg(target_os = "windows")]
#[cfg(windows)]
fn main() {
let mut res = winres::WindowsResource::new();
res.set_icon("icon.ico");
res.compile().unwrap();
let _ = res.compile();
}
#[cfg(not(target_os = "windows"))]
#[cfg(not(windows))]
fn main() {}

1
js/index.js Normal file
View file

@ -0,0 +1 @@
import("../pkg/index.js").catch(console.error);

3701
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

18
package.json Normal file
View file

@ -0,0 +1,18 @@
{
"author": "anpage <alex@anpage.me>",
"name": "kroz",
"version": "0.1.0",
"scripts": {
"build": "rimraf dist pkg && webpack",
"start": "rimraf dist pkg && webpack-dev-server --open",
"test": "cargo test && wasm-pack test --headless"
},
"devDependencies": {
"@wasm-tool/wasm-pack-plugin": "^1.1.0",
"copy-webpack-plugin": "^11.0.0",
"rimraf": "^3.0.0",
"webpack": "^5.75.0",
"webpack-cli": "^5.0.0",
"webpack-dev-server": "^4.11.1"
}
}

View file

@ -1,4 +1,4 @@
use std::time::Instant;
use instant::Instant;
pub mod monster;
pub mod player;

View file

@ -1,4 +1,4 @@
use std::time::Instant;
use instant::Instant;
#[derive(Debug)]
pub struct Player {

View file

@ -13,3 +13,5 @@ pub const MAP_SIZE: usize = MAP_WIDTH * MAP_HEIGHT;
pub const MAP_X: usize = 1;
pub const MAP_Y: usize = 1;
pub const BASE_WHIP_POWER: u32 = 2;

View file

@ -1,4 +1,4 @@
use crate::constants::{SIDEBAR_POS_X, SIDEBAR_POS_Y};
use crate::constants::*;
use crate::graphics::vga_color as vga;
use crate::resources::Resources;
use bracket_lib::prelude::*;
@ -48,7 +48,15 @@ pub fn draw(resources: &Resources, bterm: &mut BTerm) {
let stats = &resources.stats;
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 1, stats.score * 10);
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 7, stats.gems);
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 10, stats.whips);
bterm.print_centered_at(
SIDEBAR_POS_X + 6,
SIDEBAR_POS_Y + 10,
if stats.whip_power <= BASE_WHIP_POWER {
stats.whips.to_string()
} else {
format!("{}+{}", stats.whips, stats.whip_power - BASE_WHIP_POWER)
},
);
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 13, stats.teleports);
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 16, stats.keys);
@ -88,7 +96,9 @@ pub fn draw(resources: &Resources, bterm: &mut BTerm) {
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 19, "Whip");
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 20, "Teleport");
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 21, "Pause");
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 22, "Quit");
if !cfg!(target_family = "wasm") {
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 22, "Quit");
}
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 23, "Save");
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 24, "Restore");
@ -101,12 +111,22 @@ pub fn draw(resources: &Resources, bterm: &mut BTerm) {
&format!("{}", bterm.fps),
);
let mut debug_string = format!("{}", resources.clock.ticks);
if resources.speed_time_ticks > 0 {
debug_string += " SPEED"
}
if resources.slow_time_ticks > 0 {
debug_string += " SLOW"
}
bterm.print_color(
0,
0,
RGB::named(vga::YELLOW_BRIGHT),
RGB::named(vga::BLACK),
&format!("{}", resources.clock.ticks),
&debug_string,
);
}
}

View file

@ -10,6 +10,13 @@ pub fn handle_intent(bterm: &mut BTerm, _world: &mut World, resources: &mut Reso
if let Some(flashing_message) = &resources.flashing_message {
if let Some(intent) = &flashing_message.intent {
match intent {
FlashingMessageIntent::Start => {
if resources.sound_output.is_none() || resources.sound_effects.is_none() {
let sound_output = SoundOutput::new();
resources.sound_effects = Some(SoundEffects::new(&sound_output));
resources.sound_output = Some(sound_output);
}
}
FlashingMessageIntent::Quit => {
if key == VirtualKeyCode::Y {
bterm.quit()
@ -18,6 +25,9 @@ pub fn handle_intent(bterm: &mut BTerm, _world: &mut World, resources: &mut Reso
FlashingMessageIntent::Save => todo!(),
FlashingMessageIntent::Restore => todo!(),
FlashingMessageIntent::Restart => todo!(),
&FlashingMessageIntent::NextLevel => {
resources.should_advance_level = true;
}
}
}
}
@ -33,24 +43,30 @@ pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
match bterm.key {
None => {}
Some(key) => match key {
VirtualKeyCode::Left | VirtualKeyCode::J => {
VirtualKeyCode::Left | VirtualKeyCode::J | VirtualKeyCode::Numpad4 => {
player::try_move(-1, 0, world, resources);
}
VirtualKeyCode::U | VirtualKeyCode::Home => player::try_move(-1, -1, world, resources),
VirtualKeyCode::Up | VirtualKeyCode::I => {
VirtualKeyCode::U | VirtualKeyCode::Home | VirtualKeyCode::Numpad7 => {
player::try_move(-1, -1, world, resources)
}
VirtualKeyCode::Up | VirtualKeyCode::I | VirtualKeyCode::Numpad8 => {
player::try_move(0, -1, world, resources);
}
VirtualKeyCode::O | VirtualKeyCode::PageUp => player::try_move(1, -1, world, resources),
VirtualKeyCode::Right | VirtualKeyCode::K => {
VirtualKeyCode::O | VirtualKeyCode::PageUp | VirtualKeyCode::Numpad9 => {
player::try_move(1, -1, world, resources)
}
VirtualKeyCode::Right | VirtualKeyCode::K | VirtualKeyCode::Numpad6 => {
player::try_move(1, 0, world, resources);
}
VirtualKeyCode::Comma | VirtualKeyCode::PageDown => {
VirtualKeyCode::Comma | VirtualKeyCode::PageDown | VirtualKeyCode::Numpad3 => {
player::try_move(1, 1, world, resources)
}
VirtualKeyCode::Down | VirtualKeyCode::M => {
VirtualKeyCode::Down | VirtualKeyCode::M | VirtualKeyCode::Numpad2 => {
player::try_move(0, 1, world, resources);
}
VirtualKeyCode::N | VirtualKeyCode::End => player::try_move(-1, 1, world, resources),
VirtualKeyCode::N | VirtualKeyCode::End | VirtualKeyCode::Numpad1 => {
player::try_move(-1, 1, world, resources)
}
VirtualKeyCode::W => {
player::whip(world, resources);
}
@ -58,22 +74,32 @@ pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
resources.show_debug_info = !resources.show_debug_info;
}
VirtualKeyCode::Escape | VirtualKeyCode::Q => {
resources.flashing_message = Some(FlashingMessage::new(
" Are you sure you want to quit (Y/N)? ",
Some(FlashingMessageIntent::Quit),
));
if cfg!(not(target_family = "wasm")) {
resources.flashing_message = Some(FlashingMessage::new(
" Are you sure you want to quit (Y/N)? ",
Some(FlashingMessageIntent::Quit),
));
} else if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.bad_key.clone());
}
}
VirtualKeyCode::P => {
resources
.sound_output
.play_sound(resources.sound_effects.pause.clone());
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.pause.clone());
}
resources.flashing_message =
Some(FlashingMessage::from(" Press any key to resume game. "));
}
_ => {
resources
.sound_output
.play_sound(resources.sound_effects.bad_key.clone());
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.bad_key.clone());
}
}
},
}

View file

@ -1,21 +1,24 @@
use std::time::{Duration, Instant};
use instant::Instant;
use std::time::Duration;
use bracket_lib::prelude::*;
use hecs::{Entity, With, Without, World};
use hecs::{Entity, Without, World};
use crate::{
components::monster::*, components::*, constants::*, resources::*, systems, tile_data::TileType,
components::monster::*,
components::*,
constants::*,
resources::{flashing_message::FlashingMessageIntent, *},
systems,
tile_data::TileType,
};
pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut Resources) {
let mut to_kill: Vec<Entity> = Vec::new();
for (player_entity, (player, pos)) in &mut world.query::<(&mut Player, &mut Position)>() {
// The player shouldn't be able to move while whipping
if let Ok(_wants_to_whip) = world.get::<WantsToWhip>(player_entity) {
continue;
}
for (player_entity, (player, pos)) in
&mut world.query::<Without<(&mut Player, &mut Position), &WantsToWhip>>()
{
let now = Instant::now();
if now - player.last_moved > Duration::from_secs_f32(PLAYER_STEP_PERIOD) {
let destination = Point {
@ -26,13 +29,15 @@ pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut R
if resources.map.in_bounds(destination) {
if try_step(destination, world, resources) {
if let Some(monster_entity) = resources.map.get_tile_content_at(destination) {
if let Ok(monster) = world.get::<Monster>(monster_entity) {
if let Ok(monster) = world.get::<&Monster>(monster_entity) {
resources.stats.add_score(damage_for_kind(monster.kind));
resources.stats.take_gems(damage_for_kind(monster.kind));
resources.sound_output.play_sound(sound_effect_for_kind(
monster.kind,
&resources.sound_effects,
));
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output
.play_sound(sound_effect_for_kind(monster.kind, sound_effects));
}
to_kill.push(monster_entity);
}
}
@ -48,15 +53,23 @@ pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut R
systems::time::force_tick(&mut resources.clock);
resources
.sound_output
.play_sound(resources.sound_effects.step.clone());
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.step.clone());
}
}
} else {
let static_sound = resources
.sound_effects
.get_new_static_effect(&resources.sound_output);
resources.sound_output.play_sound(static_sound);
} else if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
if !resources.message_shown.touched_boundary {
resources.flashing_message = Some(FlashingMessage::from(
"An Electrified Wall blocks your way.",
));
resources.message_shown.touched_boundary = true;
}
let static_sound = sound_effects.get_new_static_effect(sound_output);
sound_output.play_sound(static_sound);
}
player.last_moved = now;
@ -73,35 +86,109 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
crate::tile_data::TileType::Floor
| crate::tile_data::TileType::Slow
| crate::tile_data::TileType::Medium
| crate::tile_data::TileType::Fast => true,
crate::tile_data::TileType::Block | crate::tile_data::TileType::Wall => {
resources
.sound_output
.play_sound(resources.sound_effects.blocked.clone());
| crate::tile_data::TileType::Fast
| crate::tile_data::TileType::Player => true,
crate::tile_data::TileType::Block => {
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.blocked.clone());
}
if !resources.message_shown.touched_boundary {
resources.flashing_message = Some(FlashingMessage::from(
"An Electrified Wall blocks your way.",
));
resources.message_shown.touched_boundary = true;
}
if resources.stats.score > 2 {
resources.stats.take_score(2);
}
false
}
crate::tile_data::TileType::Wall => {
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.blocked.clone());
}
if !resources.message_shown.touched_boundary {
resources.flashing_message =
Some(FlashingMessage::from("A Solid Wall blocks your way."));
resources.message_shown.touched_boundary = true;
}
if resources.stats.score > 2 {
resources.stats.take_score(2);
}
false
}
crate::tile_data::TileType::Whip => {
resources
.sound_output
.play_sound(resources.sound_effects.grab.clone());
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.grab.clone());
}
if !resources.message_shown.whip {
resources.flashing_message = Some(FlashingMessage::from("You found a Whip."));
resources.message_shown.whip = true;
}
resources.stats.give_whips(1);
resources.stats.add_score(1);
resources.map.set_tile_at(point, TileType::Floor);
true
}
crate::tile_data::TileType::Stairs => {
resources.should_advance_level = true;
if !resources.message_shown.stairs {
resources.flashing_message = Some(FlashingMessage::new(
"Stairs take you to the next lower level.",
Some(FlashingMessageIntent::NextLevel),
));
resources.message_shown.stairs = true;
} else {
resources.should_advance_level = true;
}
true
}
crate::tile_data::TileType::Chest => todo!(),
crate::tile_data::TileType::SlowTime => todo!(),
crate::tile_data::TileType::SlowTime => {
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.slow_time.clone());
}
if !resources.message_shown.slow_time {
resources.flashing_message = Some(FlashingMessage::from(
"You activated a Slow Creature spell.",
));
resources.message_shown.slow_time = true;
}
resources.slow_time_ticks = 100;
resources.map.set_tile_at(point, TileType::Floor);
true
}
crate::tile_data::TileType::Gem => {
resources
.sound_output
.play_sound(resources.sound_effects.grab.clone());
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.grab.clone());
}
if !resources.message_shown.gem {
resources.flashing_message = Some(FlashingMessage::from(
"Gems give you both points and strength.",
));
resources.message_shown.gem = true;
}
resources.stats.give_gems(1);
resources.stats.add_score(1);
resources.map.set_tile_at(point, TileType::Floor);
@ -109,9 +196,18 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
}
crate::tile_data::TileType::Invisible => todo!(),
crate::tile_data::TileType::Teleport => {
resources
.sound_output
.play_sound(resources.sound_effects.grab.clone());
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.grab.clone());
}
if !resources.message_shown.teleport_scroll {
resources.flashing_message =
Some(FlashingMessage::from("You found a Teleport scroll."));
resources.message_shown.teleport_scroll = true;
}
resources.stats.give_teleports(1);
resources.stats.add_score(1);
resources.map.set_tile_at(point, TileType::Floor);
@ -119,7 +215,24 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
}
crate::tile_data::TileType::Key => todo!(),
crate::tile_data::TileType::Door => todo!(),
crate::tile_data::TileType::SpeedTime => todo!(),
crate::tile_data::TileType::SpeedTime => {
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.speed_time.clone());
}
if !resources.message_shown.speed_time {
resources.flashing_message = Some(FlashingMessage::from(
"You activated a Speed Creature spell.",
));
resources.message_shown.speed_time = true;
}
resources.speed_time_ticks = 80;
resources.map.set_tile_at(point, TileType::Floor);
true
}
crate::tile_data::TileType::Trap => todo!(),
crate::tile_data::TileType::River => todo!(),
crate::tile_data::TileType::Power => todo!(),
@ -152,7 +265,6 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
crate::tile_data::TileType::Trap11 => todo!(),
crate::tile_data::TileType::Trap12 => todo!(),
crate::tile_data::TileType::Trap13 => todo!(),
crate::tile_data::TileType::Player => true,
crate::tile_data::TileType::Punctuation => todo!(),
crate::tile_data::TileType::Letter(_) => todo!(),
}
@ -161,7 +273,7 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
pub fn whip(world: &mut World, resources: &mut Resources) {
let mut to_add: Vec<Entity> = Vec::new();
for (entity, _) in world.query_mut::<With<Player, With<Position, Without<WantsToWhip, ()>>>>() {
for (entity, _) in world.query_mut::<Without<(&Player, &Position), &WantsToWhip>>() {
if resources.stats.whips > 0 {
to_add.push(entity);
}
@ -173,11 +285,15 @@ pub fn whip(world: &mut World, resources: &mut Resources) {
WantsToWhip {
frame: 0,
last_frame: Instant::now(),
sound: Some(
resources
.sound_output
.play_sound(resources.sound_effects.whipping.clone()),
),
sound: {
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
Some(sound_output.play_sound(sound_effects.whipping.clone()))
} else {
None
}
},
},
);
resources.stats.whips -= 1;

34
src/lib.rs Normal file
View file

@ -0,0 +1,34 @@
#![allow(clippy::unused_unit)]
use std::panic;
use bracket_lib::prelude::*;
use state::State;
use wasm_bindgen::prelude::*;
pub mod components;
pub mod constants;
mod graphics;
pub mod input;
pub mod levels;
pub mod resources;
mod state;
pub mod systems;
pub mod tile_data;
#[wasm_bindgen(start)]
pub fn main_js() -> Result<(), JsValue> {
panic::set_hook(Box::new(console_error_panic_hook::hook));
let _ = main_common(false);
Ok(())
}
pub fn main_common(initialize_sound: bool) -> BError {
let context = BTermBuilder::vga(80, 25)
.with_fps_cap(60.0)
.with_title("Kroz")
.build()
.unwrap();
main_loop(context, State::new(initialize_sound))
}

View file

@ -10,74 +10,8 @@ mod state;
pub mod systems;
pub mod tile_data;
use std::time::Instant;
use bracket_lib::prelude::*;
use hecs::World;
use resources::{difficulty::SECRET, *};
use state::State;
fn main() -> BError {
let context = BTermBuilder::vga(80, 25)
.with_fps_cap(60.0)
.with_title("Kroz")
.build()?;
let mut sound_output = SoundOutput::new();
let sound_effects = SoundEffects::new(&sound_output);
sound_output.play_sound(sound_effects.startup.clone());
let starting_level = 0;
let selected_difficulty = SECRET;
let mut world = World::new();
let mut map = Map::from(levels::get_level(starting_level));
map.spawn_entities(&mut world);
let resources = Resources {
level_number: starting_level,
show_debug_info: false,
player_input: None,
stats: Stats {
score: 0,
gems: selected_difficulty.starting_gems,
whips: selected_difficulty.starting_whips,
whip_power: selected_difficulty.starting_whip_power,
teleports: selected_difficulty.starting_teleports,
keys: selected_difficulty.starting_keys,
},
clock: Clock {
last_ticked: Instant::now(),
has_ticked: false,
ticks: 0,
},
stop_clock: false,
map,
sound_effects,
sound_output,
selected_difficulty: Some(selected_difficulty),
flashing_message: Some(FlashingMessage::from("Press any key to begin this level.")),
should_advance_level: false,
};
// let descent_sounds: Vec<Sound> = (20..100)
// .rev()
// .flat_map(|x| {
// (1..10).rev().flat_map(move |y| {
// vec![Sound {
// sound_type: SoundType::Tone(x * y * y),
// duration: Duration::from_millis((y as f64 / 1.5) as u64),
// }]
// })
// })
// .collect();
// let descent_effect = gs.sound_system.render_sound_effect(SoundEffect {
// sounds: descent_sounds,
// });
// let _ = gs.sound_system.play_sound(descent_effect);
main_loop(context, State::new(world, resources))
libkroz::main_common(true)
}

View file

@ -1,4 +1,4 @@
use std::time::Instant;
use instant::Instant;
pub struct Clock {
pub last_ticked: Instant,

View file

@ -1,5 +1,14 @@
use crate::constants::*;
pub enum Difficulty {
Novice,
Experienced,
Advanced,
Secret,
}
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
pub struct Difficulty {
pub struct DifficultySettings {
pub value: u32,
pub starting_gems: u32,
pub starting_whips: u32,
@ -8,38 +17,49 @@ pub struct Difficulty {
pub starting_whip_power: u32,
}
pub const SECRET: Difficulty = Difficulty {
impl From<&Difficulty> for DifficultySettings {
fn from(difficulty: &Difficulty) -> Self {
match difficulty {
Difficulty::Novice => NOVICE,
Difficulty::Experienced => EXPERIENCED,
Difficulty::Advanced => ADVANCED,
Difficulty::Secret => SECRET,
}
}
}
const SECRET: DifficultySettings = DifficultySettings {
value: 9,
starting_gems: 250,
starting_whips: 100,
starting_teleports: 50,
starting_keys: 1,
starting_whip_power: 3,
starting_whip_power: BASE_WHIP_POWER + 1,
};
pub const NOVICE: Difficulty = Difficulty {
const NOVICE: DifficultySettings = DifficultySettings {
value: 8,
starting_gems: 20,
starting_whips: 10,
starting_teleports: 0,
starting_keys: 0,
starting_whip_power: 0,
starting_whip_power: BASE_WHIP_POWER,
};
pub const EXPERIENCED: Difficulty = Difficulty {
const EXPERIENCED: DifficultySettings = DifficultySettings {
value: 5,
starting_gems: 15,
starting_whips: 0,
starting_teleports: 0,
starting_keys: 0,
starting_whip_power: 0,
starting_whip_power: BASE_WHIP_POWER,
};
pub const ADVANCED: Difficulty = Difficulty {
const ADVANCED: DifficultySettings = DifficultySettings {
value: 2,
starting_gems: 10,
starting_whips: 0,
starting_teleports: 0,
starting_keys: 0,
starting_whip_power: 0,
starting_whip_power: BASE_WHIP_POWER,
};

View file

@ -1,12 +1,15 @@
use std::time::{Duration, Instant};
use instant::Instant;
use std::time::Duration;
use crate::constants::*;
pub enum FlashingMessageIntent {
Start,
Quit,
Save,
Restore,
Restart,
NextLevel,
}
pub struct FlashingMessage {

View file

@ -1,4 +1,4 @@
use std::time::Instant;
use instant::Instant;
use crate::{
components::{monster::*, Monster, Player, Position, Renderable},

View file

@ -0,0 +1,24 @@
#[derive(Debug, Default)]
pub struct MessageShown {
pub touched_boundary: bool,
pub slow_time: bool,
pub speed_time: bool,
pub whip: bool,
pub gem: bool,
pub teleport_scroll: bool,
pub stairs: bool,
}
impl MessageShown {
pub fn all_shown() -> Self {
MessageShown {
touched_boundary: true,
slow_time: true,
speed_time: true,
whip: true,
gem: true,
teleport_scroll: true,
stairs: true,
}
}
}

View file

@ -2,15 +2,17 @@ pub mod clock;
pub mod difficulty;
pub mod flashing_message;
pub mod map;
pub mod message_shown;
pub mod sound_effects;
pub mod sound_output;
pub mod stats;
use bracket_lib::prelude::*;
pub use clock::{Clock, StopClock};
pub use difficulty::Difficulty;
pub use difficulty::DifficultySettings;
pub use flashing_message::FlashingMessage;
pub use map::Map;
pub use message_shown::MessageShown;
pub use sound_effects::SoundEffects;
pub use sound_output::SoundOutput;
pub use stats::Stats;
@ -23,9 +25,12 @@ pub struct Resources {
pub clock: Clock,
pub stop_clock: bool,
pub map: Map,
pub selected_difficulty: Option<Difficulty>,
pub sound_effects: SoundEffects,
pub sound_output: SoundOutput,
pub difficulty: Option<DifficultySettings>,
pub sound_effects: Option<SoundEffects>,
pub sound_output: Option<SoundOutput>,
pub flashing_message: Option<FlashingMessage>,
pub message_shown: MessageShown,
pub should_advance_level: bool,
pub speed_time_ticks: u32,
pub slow_time_ticks: u32,
}

View file

@ -1,19 +1,16 @@
use std::{array, iter, time::Duration};
use std::{cmp, iter, time::Duration};
use bracket_lib::random::RandomNumberGenerator;
use crate::resources::sound_output::{SoundOutput, SoundSamples};
type Frequency = u32;
type StartFrequency = u32;
type EndFrequency = u32;
type MinFrequency = u32;
type MaxFrequency = u32;
pub enum SoundType {
Silence,
Tone(Frequency),
Sweep(StartFrequency, EndFrequency),
Noise(MinFrequency, MaxFrequency),
}
@ -34,28 +31,34 @@ pub struct SoundEffects {
pub blocked: SoundSamples,
pub whipping: SoundSamples,
pub whipping_hit: SoundSamples,
pub whipping_hit_end: SoundSamples,
pub whipping_hit_enemy: SoundSamples,
pub whipping_hit_block: SoundSamples,
pub slow_hit: SoundSamples,
pub medium_hit: SoundSamples,
pub fast_hit: SoundSamples,
pub pause: SoundSamples,
pub speed_time: SoundSamples,
pub slow_time: SoundSamples,
rng: RandomNumberGenerator,
}
impl SoundEffects {
pub fn new(sound_output: &SoundOutput) -> Self {
let mut rng = RandomNumberGenerator::new();
Self {
startup: sound_output.render_sound_effect(&SoundEffect {
sounds: vec![Sound {
sound_type: SoundType::Sweep(1, 350),
duration: Duration::from_secs(1),
}],
sounds: (1..800)
.map(|x| Sound {
sound_type: SoundType::Tone(x / 2),
duration: Duration::from_millis(1),
})
.collect(),
}),
step: sound_output.render_sound_effect(&SoundEffect {
sounds: vec![
Sound {
sound_type: SoundType::Noise(350, 900),
duration: Duration::from_millis(6),
duration: Duration::from_millis(5),
},
Sound {
sound_type: SoundType::Silence,
@ -89,7 +92,7 @@ impl SoundEffects {
duration: Duration::from_millis(40),
})
.chain((0..4).flat_map(|_| {
array::IntoIter::new([
[
Sound {
sound_type: SoundType::Tone(100),
duration: Duration::from_millis(15),
@ -98,7 +101,7 @@ impl SoundEffects {
sound_type: SoundType::Silence,
duration: Duration::from_millis(15),
},
])
]
}))
.collect(),
}),
@ -119,23 +122,27 @@ impl SoundEffects {
}],
}),
whipping_hit: sound_output.render_sound_effect(&SoundEffect {
sounds: vec![
Sound {
sound_type: SoundType::Tone(400),
duration: Duration::from_millis(20),
},
Sound {
sound_type: SoundType::Tone(90),
duration: Duration::from_secs(3),
},
],
sounds: vec![Sound {
sound_type: SoundType::Tone(90),
duration: Duration::from_secs(3),
}],
}),
whipping_hit_end: sound_output.render_sound_effect(&SoundEffect {
whipping_hit_enemy: sound_output.render_sound_effect(&SoundEffect {
sounds: vec![Sound {
sound_type: SoundType::Tone(400),
duration: Duration::from_millis(20),
}],
}),
whipping_hit_block: sound_output.render_sound_effect(&SoundEffect {
sounds: (20_i32..=5700_i32)
.rev()
.step_by(5)
.map(|x| Sound {
sound_type: SoundType::Tone(cmp::max(0, rng.range(0, x * 2) - x) as u32),
duration: Duration::from_micros(665),
})
.collect(),
}),
slow_hit: sound_output.render_sound_effect(&SoundEffect {
sounds: vec![Sound {
sound_type: SoundType::Tone(400),
@ -167,7 +174,24 @@ impl SoundEffects {
sounds
},
}),
rng: RandomNumberGenerator::new(),
speed_time: sound_output.render_sound_effect(&SoundEffect {
sounds: (1..=7)
.map(|x| Sound {
sound_type: SoundType::Tone(x * 50 + 300),
duration: Duration::from_millis(x as u64 * 10 + 40),
})
.collect(),
}),
slow_time: sound_output.render_sound_effect(&SoundEffect {
sounds: (1..=7)
.rev()
.map(|x| Sound {
sound_type: SoundType::Tone(x * 50 + 300),
duration: Duration::from_millis(x as u64 * 10 + 40),
})
.collect(),
}),
rng,
}
}

View file

@ -4,8 +4,8 @@ use cpal::{
traits::{DeviceTrait, HostTrait, StreamTrait},
SampleRate, Stream,
};
use fundsp::prelude::*;
use oddio::{Frames, FramesSignal, Gain, Handle, Mixer, MonoToStereo, Stop};
use rand::Rng;
use super::sound_effects::{SoundEffect, SoundType};
@ -61,39 +61,65 @@ impl SoundOutput {
}
pub fn render_sound_effect(&self, effect: &SoundEffect) -> SoundSamples {
// Keep these outside the loop to remember phase
let mut half_cycle_counter: u32 = 0;
let mut speaker_out: bool = false;
let effect_buffer: Vec<f32> = effect
.sounds
.iter()
.flat_map(|sound| match sound.sound_type {
SoundType::Silence => (0
..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
.map(|_| 0f32)
.collect::<Vec<f32>>(),
SoundType::Tone(freq) => {
let mut c = square_hz(freq as f32);
c.reset(Some(self.sample_rate.0 as f64));
SoundType::Silence => {
// Reset phase on silence
half_cycle_counter = 0;
speaker_out = false;
(0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
.map(|_| c.get_mono())
.map(|_| 0f32)
.collect::<Vec<f32>>()
}
SoundType::Sweep(start_freq, end_freq) => {
let mut c = lfo(|t| {
lerp(
start_freq as f32,
end_freq as f32,
t * sound.duration.as_secs_f32(),
)
}) >> square();
c.reset(Some(self.sample_rate.0 as f64));
(0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
.map(|_| c.get_mono())
.collect::<Vec<f32>>()
SoundType::Tone(freq) => {
// A frequency of 0 is silence
if freq == 0 {
half_cycle_counter = 0;
speaker_out = false;
return (0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32())
as usize)
.map(|_| 0f32)
.collect::<Vec<f32>>();
}
let mut buffer: Vec<f32> = vec![
0.;
(self.sample_rate.0 as f32 * sound.duration.as_secs_f32())
as usize
];
let half_cycle_counter_upper_bound: u32 = self.sample_rate.0 / freq;
for sample in &mut buffer {
if speaker_out {
*sample = 0.75;
}
half_cycle_counter += 2;
if half_cycle_counter >= half_cycle_counter_upper_bound {
half_cycle_counter %= half_cycle_counter_upper_bound;
speaker_out = !speaker_out;
}
}
buffer
}
SoundType::Noise(min, max) => {
let mut c =
(((white() + dc(1.0)) * dc(max as f32 / 2.0)) + dc(min as f32)) >> square();
(0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
.map(|_| c.get_mono())
.map(|i| {
let t = i as f32 / self.sample_rate.0 as f32;
(t * (rand::thread_rng().gen_range(min as f32..max as f32))
* 2.0
* std::f32::consts::PI)
.sin()
.signum()
})
.collect::<Vec<f32>>()
}
})
@ -103,11 +129,10 @@ impl SoundOutput {
}
pub fn play_sound(&mut self, samples: SoundSamples) -> SoundEffectHandle {
let mut gain = oddio::Gain::new(oddio::FramesSignal::from(samples));
gain.set_gain(-10.0);
self.mixer_handle
.control::<oddio::Mixer<_>, _>()
.play(oddio::MonoToStereo::new(oddio::Gain::new(
oddio::FramesSignal::from(samples),
0.50,
)))
.play(oddio::MonoToStereo::new(gain))
}
}

View file

@ -1,5 +1,11 @@
use crate::resources::flashing_message::FlashingMessage;
use crate::resources::{Map, Resources};
use instant::Instant;
use crate::resources::clock::Clock;
use crate::resources::flashing_message::{FlashingMessage, FlashingMessageIntent};
use crate::resources::sound_effects::SoundEffects;
use crate::resources::stats::Stats;
use crate::resources::{difficulty::*, MessageShown};
use crate::resources::{Map, Resources, SoundOutput};
use crate::{graphics, input, levels, systems};
use bracket_lib::prelude::*;
use hecs::World;
@ -22,7 +28,64 @@ impl GameState for State {
}
impl State {
pub fn new(world: World, resources: Resources) -> Self {
#[allow(dead_code)]
pub fn new(initialize_sound: bool) -> Self {
let mut sound_output = if initialize_sound {
Some(SoundOutput::new())
} else {
None
};
let sound_effects = sound_output.as_ref().map(SoundEffects::new);
if let (Some(so), Some(se)) = (&mut sound_output, &sound_effects) {
so.play_sound(se.startup.clone());
}
let starting_level = 0;
let selected_difficulty = Difficulty::Secret;
let difficulty_settings = DifficultySettings::from(&selected_difficulty);
let mut world = World::new();
let mut map = Map::from(levels::get_level(starting_level));
map.spawn_entities(&mut world);
let resources = Resources {
level_number: starting_level,
show_debug_info: false,
player_input: None,
stats: Stats {
score: 0,
gems: difficulty_settings.starting_gems,
whips: difficulty_settings.starting_whips,
whip_power: difficulty_settings.starting_whip_power,
teleports: difficulty_settings.starting_teleports,
keys: difficulty_settings.starting_keys,
},
clock: Clock {
last_ticked: Instant::now(),
has_ticked: false,
ticks: 0,
},
stop_clock: false,
map,
sound_effects,
sound_output,
difficulty: Some(difficulty_settings),
flashing_message: Some(FlashingMessage::new(
"Press any key to begin this level.",
Some(FlashingMessageIntent::Start),
)),
message_shown: match selected_difficulty {
Difficulty::Novice | Difficulty::Experienced => Default::default(),
_ => MessageShown::all_shown(),
},
should_advance_level: false,
speed_time_ticks: 0,
slow_time_ticks: 0,
};
State { world, resources }
}
@ -33,9 +96,6 @@ impl State {
self.resources.map = Map::from(levels::get_level(self.resources.level_number));
self.resources.map.spawn_entities(&mut self.world);
self.resources.flashing_message =
Some(FlashingMessage::from("Press any key to begin this level."));
self.resources.should_advance_level = false;
}
}

View file

@ -1,4 +1,5 @@
pub mod monster_ai;
pub mod powerups;
pub mod time;
pub mod whip;
@ -7,6 +8,7 @@ use hecs::World;
use crate::resources::Resources;
pub fn run(world: &mut World, resources: &mut Resources) {
powerups::run(resources);
whip::run(world, resources);
monster_ai::run(world, resources);
time::run(resources);

View file

@ -52,14 +52,16 @@ pub fn run(world: &mut World, resources: &mut Resources) {
};
if let Some(e) = resources.map.get_tile_content_at(destination) {
if let Ok(_player) = world.get::<Player>(e) {
if let Ok(_player) = world.get::<&Player>(e) {
// TODO: Sound
resources.map.clear_tile_content_at(Point::from(*position));
resources.stats.take_gems(damage_for_kind(monster.kind));
resources.sound_output.play_sound(sound_effect_for_kind(
monster.kind,
&resources.sound_effects,
));
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output
.play_sound(sound_effect_for_kind(monster.kind, sound_effects));
}
to_kill.push(entity);
}
} else {
@ -67,10 +69,14 @@ pub fn run(world: &mut World, resources: &mut Resources) {
match tile {
TileType::Wall => {}
TileType::Block => {
resources.sound_output.play_sound(sound_effect_for_kind(
monster.kind,
&resources.sound_effects,
));
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effect_for_kind(
monster.kind,
sound_effects,
));
}
resources.stats.add_score(1);
*tile = TileType::Floor;
to_kill.push(entity);
@ -85,7 +91,13 @@ pub fn run(world: &mut World, resources: &mut Resources) {
}
}
monster.ticks_until_move = ticks_for_kind(monster.kind);
if resources.speed_time_ticks > 0 {
monster.ticks_until_move = 3;
} else if resources.slow_time_ticks > 0 {
monster.ticks_until_move = ticks_for_kind(monster.kind) * 5;
} else {
monster.ticks_until_move = ticks_for_kind(monster.kind);
}
}
}
}

12
src/systems/powerups.rs Normal file
View file

@ -0,0 +1,12 @@
use crate::resources::Resources;
pub fn run(resources: &mut Resources) {
if resources.clock.has_ticked {
if let Some(t) = resources.speed_time_ticks.checked_sub(1) {
resources.speed_time_ticks = t;
}
if let Some(t) = resources.slow_time_ticks.checked_sub(1) {
resources.slow_time_ticks = t;
}
}
}

View file

@ -1,4 +1,5 @@
use std::time::{Duration, Instant};
use instant::Instant;
use std::time::Duration;
use crate::constants::CLOCK_PERIOD;

View file

@ -1,4 +1,5 @@
use std::time::{Duration, Instant};
use instant::Instant;
use std::time::Duration;
use bracket_lib::prelude::*;
use hecs::{Entity, World};
@ -6,6 +7,7 @@ use hecs::{Entity, World};
use crate::{
components::{monster::damage_for_kind, Monster, Position, WantsToWhip},
resources::Resources,
tile_data::TileType,
};
pub fn run(world: &mut World, resources: &mut Resources) {
@ -68,26 +70,19 @@ pub fn run(world: &mut World, resources: &mut Resources) {
if let Some(dest) = destination {
if let Some(e) = resources.map.get_tile_content_at(dest) {
if let Ok(monster) = world.get::<Monster>(e) {
if let Ok(monster) = world.get::<&Monster>(e) {
resources.stats.add_score(damage_for_kind(monster.kind));
to_kill.push(e);
resources.map.clear_tile_content_at(dest);
if let Some(sound) = &mut wants_to_whip.sound {
sound.control::<oddio::Stop<_>, _>().stop();
}
if wants_to_whip.frame == 7 {
wants_to_whip.sound = None;
resources
.sound_output
.play_sound(resources.sound_effects.whipping_hit_end.clone());
} else {
wants_to_whip.sound = Some(
resources
.sound_output
.play_sound(resources.sound_effects.whipping_hit.clone()),
);
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.whipping_hit_enemy.clone());
}
switch_to_hit_sound(resources, wants_to_whip);
}
} else {
hit_tile(resources, wants_to_whip, dest);
}
}
@ -113,3 +108,36 @@ pub fn run(world: &mut World, resources: &mut Resources) {
let _ = world.remove_one::<WantsToWhip>(e);
}
}
fn hit_tile(resources: &mut Resources, wants_to_whip: &mut WantsToWhip, location: Point) {
let tile = resources.map.get_tile_at(location);
match tile {
TileType::Block | TileType::Tree => {
let mut rng = RandomNumberGenerator::new();
if (rng.range(0, 7) as u32) < resources.stats.whip_power {
resources.map.set_tile_at(location, TileType::Floor);
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
sound_output.play_sound(sound_effects.whipping_hit_block.clone());
}
switch_to_hit_sound(resources, wants_to_whip);
}
}
TileType::Forest => todo!(),
_ => (),
}
}
fn switch_to_hit_sound(resources: &mut Resources, wants_to_whip: &mut WantsToWhip) {
if let Some(sound) = &mut wants_to_whip.sound {
sound.control::<oddio::Stop<_>, _>().stop();
}
if let (Some(sound_effects), Some(sound_output)) =
(&mut resources.sound_effects, &mut resources.sound_output)
{
wants_to_whip.sound = Some(sound_output.play_sound(sound_effects.whipping_hit.clone()));
}
}

View file

@ -2,7 +2,7 @@ use bracket_lib::prelude::*;
use crate::graphics::vga_color as vga;
#[derive(PartialEq, Copy, Clone)]
#[derive(Eq, PartialEq, Copy, Clone)]
pub struct TileData {
pub glyph: FontCharType,
pub color_fg: (u8, u8, u8),

BIN
static/icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

36
static/index.html Normal file
View file

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Kroz</title>
<link rel="icon" type="image/png" href="icon.png" />
<style>
* {
margin: 0;
padding: 0;
}
body,
html {
height: 100%;
}
#canvas {
width: 100vw;
height: 56.25vw;
max-height: 100vh;
max-width: 177.78vh;
margin: auto;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<canvas id="canvas"></canvas>
<script src="index.js"></script>
</body>
</html>

36
webpack.config.js Normal file
View file

@ -0,0 +1,36 @@
const path = require("path");
const CopyPlugin = require("copy-webpack-plugin");
const WasmPackPlugin = require("@wasm-tool/wasm-pack-plugin");
const dist = path.resolve(__dirname, "dist");
module.exports = {
mode: "production",
entry: {
index: "./js/index.js"
},
output: {
path: dist,
filename: "[name].js"
},
experiments: {
asyncWebAssembly: true,
syncWebAssembly: true
},
devServer: {
static: {
directory: dist,
}
},
plugins: [
new CopyPlugin({
patterns: [
"static"
]
}),
new WasmPackPlugin({
crateDirectory: __dirname,
}),
]
};