Compare commits
No commits in common. "master" and "hecs" have entirely different histories.
35 changed files with 415 additions and 4844 deletions
28
.drone.yml
28
.drone.yml
|
@ -6,15 +6,12 @@ steps:
|
||||||
image: rust
|
image: rust
|
||||||
commands:
|
commands:
|
||||||
- apt-get update
|
- apt-get update
|
||||||
- apt-get install -y libasound2-dev g++-mingw-w64-x86-64 npm
|
- apt-get install -y libasound2-dev g++-mingw-w64-x86-64
|
||||||
- rustup target add x86_64-pc-windows-gnu
|
- rustup target add x86_64-pc-windows-gnu
|
||||||
- rustup toolchain install stable-x86_64-pc-windows-gnu
|
- rustup toolchain install stable-x86_64-pc-windows-gnu
|
||||||
- rustup target add wasm32-unknown-unknown
|
- cargo build --release --verbose --all
|
||||||
- cargo build --release --verbose --all --target x86_64-unknown-linux-gnu
|
|
||||||
- cargo build --release --verbose --all --target x86_64-pc-windows-gnu
|
- cargo build --release --verbose --all --target x86_64-pc-windows-gnu
|
||||||
- npm install
|
- mv target/release/kroz kroz_linux_x86_64
|
||||||
- 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
|
- mv target/x86_64-pc-windows-gnu/release/kroz.exe kroz_win_x86_64.exe
|
||||||
- name: release
|
- name: release
|
||||||
image: plugins/gitea-release
|
image: plugins/gitea-release
|
||||||
|
@ -32,22 +29,3 @@ steps:
|
||||||
when:
|
when:
|
||||||
event:
|
event:
|
||||||
- tag
|
- 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
4
.gitignore
vendored
|
@ -1,7 +1,3 @@
|
||||||
/extern
|
/extern
|
||||||
/target
|
/target
|
||||||
.vscode
|
.vscode
|
||||||
/pkg
|
|
||||||
node_modules
|
|
||||||
/dist
|
|
||||||
/wasm-pack.log
|
|
||||||
|
|
560
Cargo.lock
generated
560
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
27
Cargo.toml
27
Cargo.toml
|
@ -4,32 +4,15 @@ version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
build = "build.rs"
|
build = "build.rs"
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "libkroz"
|
|
||||||
crate-type = ["cdylib", "rlib"]
|
|
||||||
|
|
||||||
[[bin]]
|
|
||||||
name = "kroz"
|
|
||||||
path = "src/main.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# bracket-lib = { path = "extern/bracket-lib" }
|
# bracket-lib = { path = "extern/bracket-lib" }
|
||||||
bracket-lib = { git = "https://github.com/amethyst/bracket-lib" }
|
bracket-lib = { git = "https://github.com/amethyst/bracket-lib" }
|
||||||
hecs = "0.9.0"
|
hecs = "0.5.1"
|
||||||
specs-derive = "0.4.1"
|
specs-derive = "0.4.1"
|
||||||
cpal = { version = "0.14.1", features = ["wasm-bindgen"] }
|
cpal = "0.13"
|
||||||
oddio = "0.6.2"
|
oddio = "0.5"
|
||||||
|
fundsp = "0.1.0"
|
||||||
typenum = "1.15.0"
|
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]
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
winres = "0.1.12"
|
winres = "0.1"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
lto = true
|
|
||||||
opt-level = 's'
|
|
||||||
|
|
||||||
|
|
14
README.md
14
README.md
|
@ -17,19 +17,13 @@ The goal is to closely mimic the look and behavior of the original game, but not
|
||||||
- Game speed will be fixed, possibly configurable
|
- Game speed will be fixed, possibly configurable
|
||||||
- The original game's speed varied with CPU speed
|
- The original game's speed varied with CPU speed
|
||||||
- Improve control response
|
- Improve control response
|
||||||
- Support Windows, Linux, macOS, and the web
|
- Support Windows, Linux, macOS
|
||||||
|
- Possibly web and mobile platforms too
|
||||||
|
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
[Install Rust](https://rustup.rs/)
|
1. [Install Rust](https://rustup.rs/)
|
||||||
|
2. Run `cargo build` or `cargo run`
|
||||||
### Desktop
|
|
||||||
|
|
||||||
Run `cargo build` or `cargo run`
|
|
||||||
|
|
||||||
### Web
|
|
||||||
|
|
||||||
Run `npm run build` or `npm start`
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
8
build.rs
8
build.rs
|
@ -1,12 +1,12 @@
|
||||||
#[cfg(windows)]
|
#[cfg(target_os = "windows")]
|
||||||
extern crate winres;
|
extern crate winres;
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[cfg(target_os = "windows")]
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut res = winres::WindowsResource::new();
|
let mut res = winres::WindowsResource::new();
|
||||||
res.set_icon("icon.ico");
|
res.set_icon("icon.ico");
|
||||||
let _ = res.compile();
|
res.compile().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(windows))]
|
#[cfg(not(target_os = "windows"))]
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
import("../pkg/index.js").catch(console.error);
|
|
3701
package-lock.json
generated
3701
package-lock.json
generated
File diff suppressed because it is too large
Load diff
18
package.json
18
package.json
|
@ -1,18 +0,0 @@
|
||||||
{
|
|
||||||
"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"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
use instant::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
pub mod monster;
|
pub mod monster;
|
||||||
pub mod player;
|
pub mod player;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use instant::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
|
|
|
@ -13,5 +13,3 @@ pub const MAP_SIZE: usize = MAP_WIDTH * MAP_HEIGHT;
|
||||||
|
|
||||||
pub const MAP_X: usize = 1;
|
pub const MAP_X: usize = 1;
|
||||||
pub const MAP_Y: usize = 1;
|
pub const MAP_Y: usize = 1;
|
||||||
|
|
||||||
pub const BASE_WHIP_POWER: u32 = 2;
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::constants::*;
|
use crate::constants::{SIDEBAR_POS_X, SIDEBAR_POS_Y};
|
||||||
use crate::graphics::vga_color as vga;
|
use crate::graphics::vga_color as vga;
|
||||||
use crate::resources::Resources;
|
use crate::resources::Resources;
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
|
@ -48,15 +48,7 @@ pub fn draw(resources: &Resources, bterm: &mut BTerm) {
|
||||||
let stats = &resources.stats;
|
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 + 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 + 7, stats.gems);
|
||||||
bterm.print_centered_at(
|
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 10, stats.whips);
|
||||||
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 + 13, stats.teleports);
|
||||||
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 16, stats.keys);
|
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 16, stats.keys);
|
||||||
|
|
||||||
|
@ -96,9 +88,7 @@ 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 + 19, "Whip");
|
||||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 20, "Teleport");
|
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 + 21, "Pause");
|
||||||
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 + 22, "Quit");
|
|
||||||
}
|
|
||||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 23, "Save");
|
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 23, "Save");
|
||||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 24, "Restore");
|
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 24, "Restore");
|
||||||
|
|
||||||
|
@ -111,22 +101,12 @@ pub fn draw(resources: &Resources, bterm: &mut BTerm) {
|
||||||
&format!("{}", bterm.fps),
|
&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(
|
bterm.print_color(
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
RGB::named(vga::YELLOW_BRIGHT),
|
RGB::named(vga::YELLOW_BRIGHT),
|
||||||
RGB::named(vga::BLACK),
|
RGB::named(vga::BLACK),
|
||||||
&debug_string,
|
&format!("{}", resources.clock.ticks),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,13 +10,6 @@ pub fn handle_intent(bterm: &mut BTerm, _world: &mut World, resources: &mut Reso
|
||||||
if let Some(flashing_message) = &resources.flashing_message {
|
if let Some(flashing_message) = &resources.flashing_message {
|
||||||
if let Some(intent) = &flashing_message.intent {
|
if let Some(intent) = &flashing_message.intent {
|
||||||
match 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 => {
|
FlashingMessageIntent::Quit => {
|
||||||
if key == VirtualKeyCode::Y {
|
if key == VirtualKeyCode::Y {
|
||||||
bterm.quit()
|
bterm.quit()
|
||||||
|
@ -25,9 +18,6 @@ pub fn handle_intent(bterm: &mut BTerm, _world: &mut World, resources: &mut Reso
|
||||||
FlashingMessageIntent::Save => todo!(),
|
FlashingMessageIntent::Save => todo!(),
|
||||||
FlashingMessageIntent::Restore => todo!(),
|
FlashingMessageIntent::Restore => todo!(),
|
||||||
FlashingMessageIntent::Restart => todo!(),
|
FlashingMessageIntent::Restart => todo!(),
|
||||||
&FlashingMessageIntent::NextLevel => {
|
|
||||||
resources.should_advance_level = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -43,30 +33,24 @@ pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
|
||||||
match bterm.key {
|
match bterm.key {
|
||||||
None => {}
|
None => {}
|
||||||
Some(key) => match key {
|
Some(key) => match key {
|
||||||
VirtualKeyCode::Left | VirtualKeyCode::J | VirtualKeyCode::Numpad4 => {
|
VirtualKeyCode::Left | VirtualKeyCode::J => {
|
||||||
player::try_move(-1, 0, world, resources);
|
player::try_move(-1, 0, world, resources);
|
||||||
}
|
}
|
||||||
VirtualKeyCode::U | VirtualKeyCode::Home | VirtualKeyCode::Numpad7 => {
|
VirtualKeyCode::U | VirtualKeyCode::Home => player::try_move(-1, -1, world, resources),
|
||||||
player::try_move(-1, -1, world, resources)
|
VirtualKeyCode::Up | VirtualKeyCode::I => {
|
||||||
}
|
|
||||||
VirtualKeyCode::Up | VirtualKeyCode::I | VirtualKeyCode::Numpad8 => {
|
|
||||||
player::try_move(0, -1, world, resources);
|
player::try_move(0, -1, world, resources);
|
||||||
}
|
}
|
||||||
VirtualKeyCode::O | VirtualKeyCode::PageUp | VirtualKeyCode::Numpad9 => {
|
VirtualKeyCode::O | VirtualKeyCode::PageUp => player::try_move(1, -1, world, resources),
|
||||||
player::try_move(1, -1, world, resources)
|
VirtualKeyCode::Right | VirtualKeyCode::K => {
|
||||||
}
|
|
||||||
VirtualKeyCode::Right | VirtualKeyCode::K | VirtualKeyCode::Numpad6 => {
|
|
||||||
player::try_move(1, 0, world, resources);
|
player::try_move(1, 0, world, resources);
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Comma | VirtualKeyCode::PageDown | VirtualKeyCode::Numpad3 => {
|
VirtualKeyCode::Comma | VirtualKeyCode::PageDown => {
|
||||||
player::try_move(1, 1, world, resources)
|
player::try_move(1, 1, world, resources)
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Down | VirtualKeyCode::M | VirtualKeyCode::Numpad2 => {
|
VirtualKeyCode::Down | VirtualKeyCode::M => {
|
||||||
player::try_move(0, 1, world, resources);
|
player::try_move(0, 1, world, resources);
|
||||||
}
|
}
|
||||||
VirtualKeyCode::N | VirtualKeyCode::End | VirtualKeyCode::Numpad1 => {
|
VirtualKeyCode::N | VirtualKeyCode::End => player::try_move(-1, 1, world, resources),
|
||||||
player::try_move(-1, 1, world, resources)
|
|
||||||
}
|
|
||||||
VirtualKeyCode::W => {
|
VirtualKeyCode::W => {
|
||||||
player::whip(world, resources);
|
player::whip(world, resources);
|
||||||
}
|
}
|
||||||
|
@ -74,32 +58,22 @@ pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
|
||||||
resources.show_debug_info = !resources.show_debug_info;
|
resources.show_debug_info = !resources.show_debug_info;
|
||||||
}
|
}
|
||||||
VirtualKeyCode::Escape | VirtualKeyCode::Q => {
|
VirtualKeyCode::Escape | VirtualKeyCode::Q => {
|
||||||
if cfg!(not(target_family = "wasm")) {
|
resources.flashing_message = Some(FlashingMessage::new(
|
||||||
resources.flashing_message = Some(FlashingMessage::new(
|
" Are you sure you want to quit (Y/N)? ",
|
||||||
" Are you sure you want to quit (Y/N)? ",
|
Some(FlashingMessageIntent::Quit),
|
||||||
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 => {
|
VirtualKeyCode::P => {
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.sound_output
|
||||||
{
|
.play_sound(resources.sound_effects.pause.clone());
|
||||||
sound_output.play_sound(sound_effects.pause.clone());
|
|
||||||
}
|
|
||||||
resources.flashing_message =
|
resources.flashing_message =
|
||||||
Some(FlashingMessage::from(" Press any key to resume game. "));
|
Some(FlashingMessage::from(" Press any key to resume game. "));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.sound_output
|
||||||
{
|
.play_sound(resources.sound_effects.bad_key.clone());
|
||||||
sound_output.play_sound(sound_effects.bad_key.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,24 +1,21 @@
|
||||||
use instant::Instant;
|
use std::time::{Duration, Instant};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::{Entity, Without, World};
|
use hecs::{Entity, With, Without, World};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::monster::*,
|
components::monster::*, components::*, constants::*, resources::*, systems, tile_data::TileType,
|
||||||
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) {
|
pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut Resources) {
|
||||||
let mut to_kill: Vec<Entity> = Vec::new();
|
let mut to_kill: Vec<Entity> = Vec::new();
|
||||||
|
|
||||||
for (player_entity, (player, pos)) in
|
for (player_entity, (player, pos)) in &mut world.query::<(&mut Player, &mut Position)>() {
|
||||||
&mut world.query::<Without<(&mut Player, &mut Position), &WantsToWhip>>()
|
// The player shouldn't be able to move while whipping
|
||||||
{
|
if let Ok(_wants_to_whip) = world.get::<WantsToWhip>(player_entity) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
if now - player.last_moved > Duration::from_secs_f32(PLAYER_STEP_PERIOD) {
|
if now - player.last_moved > Duration::from_secs_f32(PLAYER_STEP_PERIOD) {
|
||||||
let destination = Point {
|
let destination = Point {
|
||||||
|
@ -29,15 +26,13 @@ pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut R
|
||||||
if resources.map.in_bounds(destination) {
|
if resources.map.in_bounds(destination) {
|
||||||
if try_step(destination, world, resources) {
|
if try_step(destination, world, resources) {
|
||||||
if let Some(monster_entity) = resources.map.get_tile_content_at(destination) {
|
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.add_score(damage_for_kind(monster.kind));
|
||||||
resources.stats.take_gems(damage_for_kind(monster.kind));
|
resources.stats.take_gems(damage_for_kind(monster.kind));
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources.sound_output.play_sound(sound_effect_for_kind(
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
monster.kind,
|
||||||
{
|
&resources.sound_effects,
|
||||||
sound_output
|
));
|
||||||
.play_sound(sound_effect_for_kind(monster.kind, sound_effects));
|
|
||||||
}
|
|
||||||
to_kill.push(monster_entity);
|
to_kill.push(monster_entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,23 +48,15 @@ pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut R
|
||||||
|
|
||||||
systems::time::force_tick(&mut resources.clock);
|
systems::time::force_tick(&mut resources.clock);
|
||||||
|
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.sound_output
|
||||||
{
|
.play_sound(resources.sound_effects.step.clone());
|
||||||
sound_output.play_sound(sound_effects.step.clone());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if let (Some(sound_effects), Some(sound_output)) =
|
} else {
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
let static_sound = resources
|
||||||
{
|
.sound_effects
|
||||||
if !resources.message_shown.touched_boundary {
|
.get_new_static_effect(&resources.sound_output);
|
||||||
resources.flashing_message = Some(FlashingMessage::from(
|
resources.sound_output.play_sound(static_sound);
|
||||||
"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;
|
player.last_moved = now;
|
||||||
|
@ -86,109 +73,35 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
crate::tile_data::TileType::Floor
|
crate::tile_data::TileType::Floor
|
||||||
| crate::tile_data::TileType::Slow
|
| crate::tile_data::TileType::Slow
|
||||||
| crate::tile_data::TileType::Medium
|
| crate::tile_data::TileType::Medium
|
||||||
| crate::tile_data::TileType::Fast
|
| crate::tile_data::TileType::Fast => true,
|
||||||
| crate::tile_data::TileType::Player => true,
|
crate::tile_data::TileType::Block | crate::tile_data::TileType::Wall => {
|
||||||
crate::tile_data::TileType::Block => {
|
resources
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
.sound_output
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.play_sound(resources.sound_effects.blocked.clone());
|
||||||
{
|
|
||||||
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 {
|
if resources.stats.score > 2 {
|
||||||
resources.stats.take_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
|
false
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Whip => {
|
crate::tile_data::TileType::Whip => {
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.sound_output
|
||||||
{
|
.play_sound(resources.sound_effects.grab.clone());
|
||||||
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.give_whips(1);
|
||||||
resources.stats.add_score(1);
|
resources.stats.add_score(1);
|
||||||
resources.map.set_tile_at(point, TileType::Floor);
|
resources.map.set_tile_at(point, TileType::Floor);
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Stairs => {
|
crate::tile_data::TileType::Stairs => {
|
||||||
if !resources.message_shown.stairs {
|
resources.should_advance_level = true;
|
||||||
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
|
true
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Chest => todo!(),
|
crate::tile_data::TileType::Chest => todo!(),
|
||||||
crate::tile_data::TileType::SlowTime => {
|
crate::tile_data::TileType::SlowTime => todo!(),
|
||||||
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 => {
|
crate::tile_data::TileType::Gem => {
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.sound_output
|
||||||
{
|
.play_sound(resources.sound_effects.grab.clone());
|
||||||
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.give_gems(1);
|
||||||
resources.stats.add_score(1);
|
resources.stats.add_score(1);
|
||||||
resources.map.set_tile_at(point, TileType::Floor);
|
resources.map.set_tile_at(point, TileType::Floor);
|
||||||
|
@ -196,18 +109,9 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Invisible => todo!(),
|
crate::tile_data::TileType::Invisible => todo!(),
|
||||||
crate::tile_data::TileType::Teleport => {
|
crate::tile_data::TileType::Teleport => {
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.sound_output
|
||||||
{
|
.play_sound(resources.sound_effects.grab.clone());
|
||||||
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.give_teleports(1);
|
||||||
resources.stats.add_score(1);
|
resources.stats.add_score(1);
|
||||||
resources.map.set_tile_at(point, TileType::Floor);
|
resources.map.set_tile_at(point, TileType::Floor);
|
||||||
|
@ -215,24 +119,7 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Key => todo!(),
|
crate::tile_data::TileType::Key => todo!(),
|
||||||
crate::tile_data::TileType::Door => todo!(),
|
crate::tile_data::TileType::Door => todo!(),
|
||||||
crate::tile_data::TileType::SpeedTime => {
|
crate::tile_data::TileType::SpeedTime => todo!(),
|
||||||
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::Trap => todo!(),
|
||||||
crate::tile_data::TileType::River => todo!(),
|
crate::tile_data::TileType::River => todo!(),
|
||||||
crate::tile_data::TileType::Power => todo!(),
|
crate::tile_data::TileType::Power => todo!(),
|
||||||
|
@ -265,6 +152,7 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
crate::tile_data::TileType::Trap11 => todo!(),
|
crate::tile_data::TileType::Trap11 => todo!(),
|
||||||
crate::tile_data::TileType::Trap12 => todo!(),
|
crate::tile_data::TileType::Trap12 => todo!(),
|
||||||
crate::tile_data::TileType::Trap13 => todo!(),
|
crate::tile_data::TileType::Trap13 => todo!(),
|
||||||
|
crate::tile_data::TileType::Player => true,
|
||||||
crate::tile_data::TileType::Punctuation => todo!(),
|
crate::tile_data::TileType::Punctuation => todo!(),
|
||||||
crate::tile_data::TileType::Letter(_) => todo!(),
|
crate::tile_data::TileType::Letter(_) => todo!(),
|
||||||
}
|
}
|
||||||
|
@ -273,7 +161,7 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
pub fn whip(world: &mut World, resources: &mut Resources) {
|
pub fn whip(world: &mut World, resources: &mut Resources) {
|
||||||
let mut to_add: Vec<Entity> = Vec::new();
|
let mut to_add: Vec<Entity> = Vec::new();
|
||||||
|
|
||||||
for (entity, _) in world.query_mut::<Without<(&Player, &Position), &WantsToWhip>>() {
|
for (entity, _) in world.query_mut::<With<Player, With<Position, Without<WantsToWhip, ()>>>>() {
|
||||||
if resources.stats.whips > 0 {
|
if resources.stats.whips > 0 {
|
||||||
to_add.push(entity);
|
to_add.push(entity);
|
||||||
}
|
}
|
||||||
|
@ -285,15 +173,11 @@ pub fn whip(world: &mut World, resources: &mut Resources) {
|
||||||
WantsToWhip {
|
WantsToWhip {
|
||||||
frame: 0,
|
frame: 0,
|
||||||
last_frame: Instant::now(),
|
last_frame: Instant::now(),
|
||||||
sound: {
|
sound: Some(
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
.sound_output
|
||||||
{
|
.play_sound(resources.sound_effects.whipping.clone()),
|
||||||
Some(sound_output.play_sound(sound_effects.whipping.clone()))
|
),
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
resources.stats.whips -= 1;
|
resources.stats.whips -= 1;
|
||||||
|
|
34
src/lib.rs
34
src/lib.rs
|
@ -1,34 +0,0 @@
|
||||||
#![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))
|
|
||||||
}
|
|
68
src/main.rs
68
src/main.rs
|
@ -10,8 +10,74 @@ mod state;
|
||||||
pub mod systems;
|
pub mod systems;
|
||||||
pub mod tile_data;
|
pub mod tile_data;
|
||||||
|
|
||||||
|
use std::time::Instant;
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
|
use hecs::World;
|
||||||
|
use resources::{difficulty::SECRET, *};
|
||||||
|
use state::State;
|
||||||
|
|
||||||
fn main() -> BError {
|
fn main() -> BError {
|
||||||
libkroz::main_common(true)
|
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))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use instant::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
pub struct Clock {
|
pub struct Clock {
|
||||||
pub last_ticked: Instant,
|
pub last_ticked: Instant,
|
||||||
|
|
|
@ -1,14 +1,5 @@
|
||||||
use crate::constants::*;
|
|
||||||
|
|
||||||
pub enum Difficulty {
|
|
||||||
Novice,
|
|
||||||
Experienced,
|
|
||||||
Advanced,
|
|
||||||
Secret,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
#[derive(Debug, Eq, PartialEq, Copy, Clone, Hash)]
|
||||||
pub struct DifficultySettings {
|
pub struct Difficulty {
|
||||||
pub value: u32,
|
pub value: u32,
|
||||||
pub starting_gems: u32,
|
pub starting_gems: u32,
|
||||||
pub starting_whips: u32,
|
pub starting_whips: u32,
|
||||||
|
@ -17,49 +8,38 @@ pub struct DifficultySettings {
|
||||||
pub starting_whip_power: u32,
|
pub starting_whip_power: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<&Difficulty> for DifficultySettings {
|
pub const SECRET: Difficulty = Difficulty {
|
||||||
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,
|
value: 9,
|
||||||
starting_gems: 250,
|
starting_gems: 250,
|
||||||
starting_whips: 100,
|
starting_whips: 100,
|
||||||
starting_teleports: 50,
|
starting_teleports: 50,
|
||||||
starting_keys: 1,
|
starting_keys: 1,
|
||||||
starting_whip_power: BASE_WHIP_POWER + 1,
|
starting_whip_power: 3,
|
||||||
};
|
};
|
||||||
|
|
||||||
const NOVICE: DifficultySettings = DifficultySettings {
|
pub const NOVICE: Difficulty = Difficulty {
|
||||||
value: 8,
|
value: 8,
|
||||||
starting_gems: 20,
|
starting_gems: 20,
|
||||||
starting_whips: 10,
|
starting_whips: 10,
|
||||||
starting_teleports: 0,
|
starting_teleports: 0,
|
||||||
starting_keys: 0,
|
starting_keys: 0,
|
||||||
starting_whip_power: BASE_WHIP_POWER,
|
starting_whip_power: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const EXPERIENCED: DifficultySettings = DifficultySettings {
|
pub const EXPERIENCED: Difficulty = Difficulty {
|
||||||
value: 5,
|
value: 5,
|
||||||
starting_gems: 15,
|
starting_gems: 15,
|
||||||
starting_whips: 0,
|
starting_whips: 0,
|
||||||
starting_teleports: 0,
|
starting_teleports: 0,
|
||||||
starting_keys: 0,
|
starting_keys: 0,
|
||||||
starting_whip_power: BASE_WHIP_POWER,
|
starting_whip_power: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
const ADVANCED: DifficultySettings = DifficultySettings {
|
pub const ADVANCED: Difficulty = Difficulty {
|
||||||
value: 2,
|
value: 2,
|
||||||
starting_gems: 10,
|
starting_gems: 10,
|
||||||
starting_whips: 0,
|
starting_whips: 0,
|
||||||
starting_teleports: 0,
|
starting_teleports: 0,
|
||||||
starting_keys: 0,
|
starting_keys: 0,
|
||||||
starting_whip_power: BASE_WHIP_POWER,
|
starting_whip_power: 0,
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
use instant::Instant;
|
use std::time::{Duration, Instant};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
|
|
||||||
pub enum FlashingMessageIntent {
|
pub enum FlashingMessageIntent {
|
||||||
Start,
|
|
||||||
Quit,
|
Quit,
|
||||||
Save,
|
Save,
|
||||||
Restore,
|
Restore,
|
||||||
Restart,
|
Restart,
|
||||||
NextLevel,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FlashingMessage {
|
pub struct FlashingMessage {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use instant::Instant;
|
use std::time::Instant;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{monster::*, Monster, Player, Position, Renderable},
|
components::{monster::*, Monster, Player, Position, Renderable},
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
#[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,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -2,17 +2,15 @@ pub mod clock;
|
||||||
pub mod difficulty;
|
pub mod difficulty;
|
||||||
pub mod flashing_message;
|
pub mod flashing_message;
|
||||||
pub mod map;
|
pub mod map;
|
||||||
pub mod message_shown;
|
|
||||||
pub mod sound_effects;
|
pub mod sound_effects;
|
||||||
pub mod sound_output;
|
pub mod sound_output;
|
||||||
pub mod stats;
|
pub mod stats;
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
pub use clock::{Clock, StopClock};
|
pub use clock::{Clock, StopClock};
|
||||||
pub use difficulty::DifficultySettings;
|
pub use difficulty::Difficulty;
|
||||||
pub use flashing_message::FlashingMessage;
|
pub use flashing_message::FlashingMessage;
|
||||||
pub use map::Map;
|
pub use map::Map;
|
||||||
pub use message_shown::MessageShown;
|
|
||||||
pub use sound_effects::SoundEffects;
|
pub use sound_effects::SoundEffects;
|
||||||
pub use sound_output::SoundOutput;
|
pub use sound_output::SoundOutput;
|
||||||
pub use stats::Stats;
|
pub use stats::Stats;
|
||||||
|
@ -25,12 +23,9 @@ pub struct Resources {
|
||||||
pub clock: Clock,
|
pub clock: Clock,
|
||||||
pub stop_clock: bool,
|
pub stop_clock: bool,
|
||||||
pub map: Map,
|
pub map: Map,
|
||||||
pub difficulty: Option<DifficultySettings>,
|
pub selected_difficulty: Option<Difficulty>,
|
||||||
pub sound_effects: Option<SoundEffects>,
|
pub sound_effects: SoundEffects,
|
||||||
pub sound_output: Option<SoundOutput>,
|
pub sound_output: SoundOutput,
|
||||||
pub flashing_message: Option<FlashingMessage>,
|
pub flashing_message: Option<FlashingMessage>,
|
||||||
pub message_shown: MessageShown,
|
|
||||||
pub should_advance_level: bool,
|
pub should_advance_level: bool,
|
||||||
pub speed_time_ticks: u32,
|
|
||||||
pub slow_time_ticks: u32,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,19 @@
|
||||||
use std::{cmp, iter, time::Duration};
|
use std::{array, iter, time::Duration};
|
||||||
|
|
||||||
use bracket_lib::random::RandomNumberGenerator;
|
use bracket_lib::random::RandomNumberGenerator;
|
||||||
|
|
||||||
use crate::resources::sound_output::{SoundOutput, SoundSamples};
|
use crate::resources::sound_output::{SoundOutput, SoundSamples};
|
||||||
|
|
||||||
type Frequency = u32;
|
type Frequency = u32;
|
||||||
|
type StartFrequency = u32;
|
||||||
|
type EndFrequency = u32;
|
||||||
type MinFrequency = u32;
|
type MinFrequency = u32;
|
||||||
type MaxFrequency = u32;
|
type MaxFrequency = u32;
|
||||||
|
|
||||||
pub enum SoundType {
|
pub enum SoundType {
|
||||||
Silence,
|
Silence,
|
||||||
Tone(Frequency),
|
Tone(Frequency),
|
||||||
|
Sweep(StartFrequency, EndFrequency),
|
||||||
Noise(MinFrequency, MaxFrequency),
|
Noise(MinFrequency, MaxFrequency),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,34 +34,28 @@ pub struct SoundEffects {
|
||||||
pub blocked: SoundSamples,
|
pub blocked: SoundSamples,
|
||||||
pub whipping: SoundSamples,
|
pub whipping: SoundSamples,
|
||||||
pub whipping_hit: SoundSamples,
|
pub whipping_hit: SoundSamples,
|
||||||
pub whipping_hit_enemy: SoundSamples,
|
pub whipping_hit_end: SoundSamples,
|
||||||
pub whipping_hit_block: SoundSamples,
|
|
||||||
pub slow_hit: SoundSamples,
|
pub slow_hit: SoundSamples,
|
||||||
pub medium_hit: SoundSamples,
|
pub medium_hit: SoundSamples,
|
||||||
pub fast_hit: SoundSamples,
|
pub fast_hit: SoundSamples,
|
||||||
pub pause: SoundSamples,
|
pub pause: SoundSamples,
|
||||||
pub speed_time: SoundSamples,
|
|
||||||
pub slow_time: SoundSamples,
|
|
||||||
rng: RandomNumberGenerator,
|
rng: RandomNumberGenerator,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SoundEffects {
|
impl SoundEffects {
|
||||||
pub fn new(sound_output: &SoundOutput) -> Self {
|
pub fn new(sound_output: &SoundOutput) -> Self {
|
||||||
let mut rng = RandomNumberGenerator::new();
|
|
||||||
Self {
|
Self {
|
||||||
startup: sound_output.render_sound_effect(&SoundEffect {
|
startup: sound_output.render_sound_effect(&SoundEffect {
|
||||||
sounds: (1..800)
|
sounds: vec![Sound {
|
||||||
.map(|x| Sound {
|
sound_type: SoundType::Sweep(1, 350),
|
||||||
sound_type: SoundType::Tone(x / 2),
|
duration: Duration::from_secs(1),
|
||||||
duration: Duration::from_millis(1),
|
}],
|
||||||
})
|
|
||||||
.collect(),
|
|
||||||
}),
|
}),
|
||||||
step: sound_output.render_sound_effect(&SoundEffect {
|
step: sound_output.render_sound_effect(&SoundEffect {
|
||||||
sounds: vec![
|
sounds: vec![
|
||||||
Sound {
|
Sound {
|
||||||
sound_type: SoundType::Noise(350, 900),
|
sound_type: SoundType::Noise(350, 900),
|
||||||
duration: Duration::from_millis(5),
|
duration: Duration::from_millis(6),
|
||||||
},
|
},
|
||||||
Sound {
|
Sound {
|
||||||
sound_type: SoundType::Silence,
|
sound_type: SoundType::Silence,
|
||||||
|
@ -92,7 +89,7 @@ impl SoundEffects {
|
||||||
duration: Duration::from_millis(40),
|
duration: Duration::from_millis(40),
|
||||||
})
|
})
|
||||||
.chain((0..4).flat_map(|_| {
|
.chain((0..4).flat_map(|_| {
|
||||||
[
|
array::IntoIter::new([
|
||||||
Sound {
|
Sound {
|
||||||
sound_type: SoundType::Tone(100),
|
sound_type: SoundType::Tone(100),
|
||||||
duration: Duration::from_millis(15),
|
duration: Duration::from_millis(15),
|
||||||
|
@ -101,7 +98,7 @@ impl SoundEffects {
|
||||||
sound_type: SoundType::Silence,
|
sound_type: SoundType::Silence,
|
||||||
duration: Duration::from_millis(15),
|
duration: Duration::from_millis(15),
|
||||||
},
|
},
|
||||||
]
|
])
|
||||||
}))
|
}))
|
||||||
.collect(),
|
.collect(),
|
||||||
}),
|
}),
|
||||||
|
@ -122,27 +119,23 @@ impl SoundEffects {
|
||||||
}],
|
}],
|
||||||
}),
|
}),
|
||||||
whipping_hit: sound_output.render_sound_effect(&SoundEffect {
|
whipping_hit: sound_output.render_sound_effect(&SoundEffect {
|
||||||
sounds: vec![Sound {
|
sounds: vec![
|
||||||
sound_type: SoundType::Tone(90),
|
Sound {
|
||||||
duration: Duration::from_secs(3),
|
sound_type: SoundType::Tone(400),
|
||||||
}],
|
duration: Duration::from_millis(20),
|
||||||
|
},
|
||||||
|
Sound {
|
||||||
|
sound_type: SoundType::Tone(90),
|
||||||
|
duration: Duration::from_secs(3),
|
||||||
|
},
|
||||||
|
],
|
||||||
}),
|
}),
|
||||||
whipping_hit_enemy: sound_output.render_sound_effect(&SoundEffect {
|
whipping_hit_end: sound_output.render_sound_effect(&SoundEffect {
|
||||||
sounds: vec![Sound {
|
sounds: vec![Sound {
|
||||||
sound_type: SoundType::Tone(400),
|
sound_type: SoundType::Tone(400),
|
||||||
duration: Duration::from_millis(20),
|
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 {
|
slow_hit: sound_output.render_sound_effect(&SoundEffect {
|
||||||
sounds: vec![Sound {
|
sounds: vec![Sound {
|
||||||
sound_type: SoundType::Tone(400),
|
sound_type: SoundType::Tone(400),
|
||||||
|
@ -174,24 +167,7 @@ impl SoundEffects {
|
||||||
sounds
|
sounds
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
speed_time: sound_output.render_sound_effect(&SoundEffect {
|
rng: RandomNumberGenerator::new(),
|
||||||
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,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,8 +4,8 @@ use cpal::{
|
||||||
traits::{DeviceTrait, HostTrait, StreamTrait},
|
traits::{DeviceTrait, HostTrait, StreamTrait},
|
||||||
SampleRate, Stream,
|
SampleRate, Stream,
|
||||||
};
|
};
|
||||||
|
use fundsp::prelude::*;
|
||||||
use oddio::{Frames, FramesSignal, Gain, Handle, Mixer, MonoToStereo, Stop};
|
use oddio::{Frames, FramesSignal, Gain, Handle, Mixer, MonoToStereo, Stop};
|
||||||
use rand::Rng;
|
|
||||||
|
|
||||||
use super::sound_effects::{SoundEffect, SoundType};
|
use super::sound_effects::{SoundEffect, SoundType};
|
||||||
|
|
||||||
|
@ -61,65 +61,39 @@ impl SoundOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn render_sound_effect(&self, effect: &SoundEffect) -> SoundSamples {
|
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
|
let effect_buffer: Vec<f32> = effect
|
||||||
.sounds
|
.sounds
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|sound| match sound.sound_type {
|
.flat_map(|sound| match sound.sound_type {
|
||||||
SoundType::Silence => {
|
SoundType::Silence => (0
|
||||||
// Reset phase on silence
|
..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
|
||||||
half_cycle_counter = 0;
|
.map(|_| 0f32)
|
||||||
speaker_out = false;
|
.collect::<Vec<f32>>(),
|
||||||
|
SoundType::Tone(freq) => {
|
||||||
|
let mut c = square_hz(freq as f32);
|
||||||
|
c.reset(Some(self.sample_rate.0 as f64));
|
||||||
(0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
|
(0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
|
||||||
.map(|_| 0f32)
|
.map(|_| c.get_mono())
|
||||||
.collect::<Vec<f32>>()
|
.collect::<Vec<f32>>()
|
||||||
}
|
}
|
||||||
SoundType::Tone(freq) => {
|
SoundType::Sweep(start_freq, end_freq) => {
|
||||||
// A frequency of 0 is silence
|
let mut c = lfo(|t| {
|
||||||
if freq == 0 {
|
lerp(
|
||||||
half_cycle_counter = 0;
|
start_freq as f32,
|
||||||
speaker_out = false;
|
end_freq as f32,
|
||||||
|
t * sound.duration.as_secs_f32(),
|
||||||
return (0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32())
|
)
|
||||||
as usize)
|
}) >> square();
|
||||||
.map(|_| 0f32)
|
c.reset(Some(self.sample_rate.0 as f64));
|
||||||
.collect::<Vec<f32>>();
|
(0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
|
||||||
}
|
.map(|_| c.get_mono())
|
||||||
|
.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) => {
|
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)
|
(0..(self.sample_rate.0 as f32 * sound.duration.as_secs_f32()) as usize)
|
||||||
.map(|i| {
|
.map(|_| c.get_mono())
|
||||||
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>>()
|
.collect::<Vec<f32>>()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -129,10 +103,11 @@ impl SoundOutput {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn play_sound(&mut self, samples: SoundSamples) -> SoundEffectHandle {
|
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
|
self.mixer_handle
|
||||||
.control::<oddio::Mixer<_>, _>()
|
.control::<oddio::Mixer<_>, _>()
|
||||||
.play(oddio::MonoToStereo::new(gain))
|
.play(oddio::MonoToStereo::new(oddio::Gain::new(
|
||||||
|
oddio::FramesSignal::from(samples),
|
||||||
|
0.50,
|
||||||
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
72
src/state.rs
72
src/state.rs
|
@ -1,11 +1,5 @@
|
||||||
use instant::Instant;
|
use crate::resources::flashing_message::FlashingMessage;
|
||||||
|
use crate::resources::{Map, Resources};
|
||||||
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 crate::{graphics, input, levels, systems};
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::World;
|
use hecs::World;
|
||||||
|
@ -28,64 +22,7 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
#[allow(dead_code)]
|
pub fn new(world: World, resources: Resources) -> Self {
|
||||||
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 }
|
State { world, resources }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,6 +33,9 @@ impl State {
|
||||||
self.resources.map = Map::from(levels::get_level(self.resources.level_number));
|
self.resources.map = Map::from(levels::get_level(self.resources.level_number));
|
||||||
self.resources.map.spawn_entities(&mut self.world);
|
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;
|
self.resources.should_advance_level = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
pub mod monster_ai;
|
pub mod monster_ai;
|
||||||
pub mod powerups;
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
pub mod whip;
|
pub mod whip;
|
||||||
|
|
||||||
|
@ -8,7 +7,6 @@ use hecs::World;
|
||||||
use crate::resources::Resources;
|
use crate::resources::Resources;
|
||||||
|
|
||||||
pub fn run(world: &mut World, resources: &mut Resources) {
|
pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
powerups::run(resources);
|
|
||||||
whip::run(world, resources);
|
whip::run(world, resources);
|
||||||
monster_ai::run(world, resources);
|
monster_ai::run(world, resources);
|
||||||
time::run(resources);
|
time::run(resources);
|
||||||
|
|
|
@ -52,16 +52,14 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(e) = resources.map.get_tile_content_at(destination) {
|
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
|
// TODO: Sound
|
||||||
resources.map.clear_tile_content_at(Point::from(*position));
|
resources.map.clear_tile_content_at(Point::from(*position));
|
||||||
resources.stats.take_gems(damage_for_kind(monster.kind));
|
resources.stats.take_gems(damage_for_kind(monster.kind));
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources.sound_output.play_sound(sound_effect_for_kind(
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
monster.kind,
|
||||||
{
|
&resources.sound_effects,
|
||||||
sound_output
|
));
|
||||||
.play_sound(sound_effect_for_kind(monster.kind, sound_effects));
|
|
||||||
}
|
|
||||||
to_kill.push(entity);
|
to_kill.push(entity);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -69,14 +67,10 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
match tile {
|
match tile {
|
||||||
TileType::Wall => {}
|
TileType::Wall => {}
|
||||||
TileType::Block => {
|
TileType::Block => {
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
resources.sound_output.play_sound(sound_effect_for_kind(
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
monster.kind,
|
||||||
{
|
&resources.sound_effects,
|
||||||
sound_output.play_sound(sound_effect_for_kind(
|
));
|
||||||
monster.kind,
|
|
||||||
sound_effects,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
resources.stats.add_score(1);
|
resources.stats.add_score(1);
|
||||||
*tile = TileType::Floor;
|
*tile = TileType::Floor;
|
||||||
to_kill.push(entity);
|
to_kill.push(entity);
|
||||||
|
@ -91,13 +85,7 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if resources.speed_time_ticks > 0 {
|
monster.ticks_until_move = ticks_for_kind(monster.kind);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,4 @@
|
||||||
use instant::Instant;
|
use std::time::{Duration, Instant};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use crate::constants::CLOCK_PERIOD;
|
use crate::constants::CLOCK_PERIOD;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use instant::Instant;
|
use std::time::{Duration, Instant};
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::{Entity, World};
|
use hecs::{Entity, World};
|
||||||
|
@ -7,7 +6,6 @@ use hecs::{Entity, World};
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{monster::damage_for_kind, Monster, Position, WantsToWhip},
|
components::{monster::damage_for_kind, Monster, Position, WantsToWhip},
|
||||||
resources::Resources,
|
resources::Resources,
|
||||||
tile_data::TileType,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn run(world: &mut World, resources: &mut Resources) {
|
pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
|
@ -70,19 +68,26 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
|
|
||||||
if let Some(dest) = destination {
|
if let Some(dest) = destination {
|
||||||
if let Some(e) = resources.map.get_tile_content_at(dest) {
|
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));
|
resources.stats.add_score(damage_for_kind(monster.kind));
|
||||||
to_kill.push(e);
|
to_kill.push(e);
|
||||||
resources.map.clear_tile_content_at(dest);
|
resources.map.clear_tile_content_at(dest);
|
||||||
if let (Some(sound_effects), Some(sound_output)) =
|
if let Some(sound) = &mut wants_to_whip.sound {
|
||||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
sound.control::<oddio::Stop<_>, _>().stop();
|
||||||
{
|
}
|
||||||
sound_output.play_sound(sound_effects.whipping_hit_enemy.clone());
|
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()),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
switch_to_hit_sound(resources, wants_to_whip);
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
hit_tile(resources, wants_to_whip, dest);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,36 +113,3 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
let _ = world.remove_one::<WantsToWhip>(e);
|
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()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ use bracket_lib::prelude::*;
|
||||||
|
|
||||||
use crate::graphics::vga_color as vga;
|
use crate::graphics::vga_color as vga;
|
||||||
|
|
||||||
#[derive(Eq, PartialEq, Copy, Clone)]
|
#[derive(PartialEq, Copy, Clone)]
|
||||||
pub struct TileData {
|
pub struct TileData {
|
||||||
pub glyph: FontCharType,
|
pub glyph: FontCharType,
|
||||||
pub color_fg: (u8, u8, u8),
|
pub color_fg: (u8, u8, u8),
|
||||||
|
|
BIN
static/icon.png
BIN
static/icon.png
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB |
|
@ -1,36 +0,0 @@
|
||||||
<!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>
|
|
|
@ -1,36 +0,0 @@
|
||||||
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,
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
};
|
|
Loading…
Add table
Reference in a new issue