Initial web support
This commit is contained in:
parent
4cd9f5acc3
commit
cbcda28719
17 changed files with 238 additions and 143 deletions
28
Cargo.lock
generated
28
Cargo.lock
generated
|
@ -127,7 +127,7 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-algorithm-traits"
|
name = "bracket-algorithm-traits"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bracket-geometry",
|
"bracket-geometry",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
|
@ -136,7 +136,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-color"
|
name = "bracket-color"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
@ -145,7 +145,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-embedding"
|
name = "bracket-embedding"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
|
@ -154,7 +154,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-geometry"
|
name = "bracket-geometry"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ultraviolet",
|
"ultraviolet",
|
||||||
]
|
]
|
||||||
|
@ -162,7 +162,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-lib"
|
name = "bracket-lib"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bracket-algorithm-traits",
|
"bracket-algorithm-traits",
|
||||||
"bracket-color",
|
"bracket-color",
|
||||||
|
@ -176,7 +176,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-noise"
|
name = "bracket-noise"
|
||||||
version = "0.8.2"
|
version = "0.8.2"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bracket-random",
|
"bracket-random",
|
||||||
]
|
]
|
||||||
|
@ -184,7 +184,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-pathfinding"
|
name = "bracket-pathfinding"
|
||||||
version = "0.8.4"
|
version = "0.8.4"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bracket-algorithm-traits",
|
"bracket-algorithm-traits",
|
||||||
"bracket-geometry",
|
"bracket-geometry",
|
||||||
|
@ -195,7 +195,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-random"
|
name = "bracket-random"
|
||||||
version = "0.8.3"
|
version = "0.8.3"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"js-sys",
|
"js-sys",
|
||||||
|
@ -209,7 +209,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-rex"
|
name = "bracket-rex"
|
||||||
version = "0.8.0"
|
version = "0.8.0"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bracket-color",
|
"bracket-color",
|
||||||
"bracket-embedding",
|
"bracket-embedding",
|
||||||
|
@ -220,7 +220,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bracket-terminal"
|
name = "bracket-terminal"
|
||||||
version = "0.8.5"
|
version = "0.8.5"
|
||||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"bracket-color",
|
"bracket-color",
|
||||||
|
@ -325,9 +325,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clang-sys"
|
name = "clang-sys"
|
||||||
version = "1.3.0"
|
version = "1.3.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90"
|
checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"glob",
|
"glob",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -513,6 +513,7 @@ dependencies = [
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"stdweb",
|
"stdweb",
|
||||||
"thiserror",
|
"thiserror",
|
||||||
|
"wasm-bindgen",
|
||||||
"web-sys",
|
"web-sys",
|
||||||
"winapi 0.3.9",
|
"winapi 0.3.9",
|
||||||
]
|
]
|
||||||
|
@ -1070,12 +1071,15 @@ name = "kroz"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bracket-lib",
|
"bracket-lib",
|
||||||
|
"console_error_panic_hook",
|
||||||
"cpal",
|
"cpal",
|
||||||
"fundsp",
|
"fundsp",
|
||||||
"hecs",
|
"hecs",
|
||||||
|
"instant",
|
||||||
"oddio",
|
"oddio",
|
||||||
"specs-derive",
|
"specs-derive",
|
||||||
"typenum",
|
"typenum",
|
||||||
|
"wasm-bindgen",
|
||||||
"winres",
|
"winres",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,13 @@ build = "build.rs"
|
||||||
bracket-lib = { git = "https://github.com/amethyst/bracket-lib" }
|
bracket-lib = { git = "https://github.com/amethyst/bracket-lib" }
|
||||||
hecs = "0.5.1"
|
hecs = "0.5.1"
|
||||||
specs-derive = "0.4.1"
|
specs-derive = "0.4.1"
|
||||||
cpal = "0.13"
|
cpal = { version = "0.13.0", features = ["wasm-bindgen"] }
|
||||||
oddio = "0.5"
|
oddio = "0.5"
|
||||||
fundsp = "0.1.0"
|
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"
|
||||||
|
|
||||||
[target.'cfg(windows)'.build-dependencies]
|
[target.'cfg(windows)'.build-dependencies]
|
||||||
winres = "0.1"
|
winres = "0.1"
|
||||||
|
|
8
build.rs
8
build.rs
|
@ -1,12 +1,12 @@
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(windows)]
|
||||||
extern crate winres;
|
extern crate winres;
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(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");
|
||||||
res.compile().unwrap();
|
let _ = res.compile();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_os = "windows"))]
|
#[cfg(not(windows))]
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
|
39
index.html
Normal file
39
index.html
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta content="text/html;charset=utf-8" http-equiv="Content-Type" />
|
||||||
|
<style>
|
||||||
|
* {
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
body,
|
||||||
|
html {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
#canvas {
|
||||||
|
width: 100vw;
|
||||||
|
height: 56.25vw; /* height:width ratio = 9/16 = .5625 */
|
||||||
|
background: pink;
|
||||||
|
max-height: 100vh;
|
||||||
|
max-width: 177.78vh; /* 16/9 = 1.778 */
|
||||||
|
margin: auto;
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0; /* vertical center */
|
||||||
|
left: 0;
|
||||||
|
right: 0; /* horizontal center */
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas"></canvas>
|
||||||
|
<script src="./kroz.js"></script>
|
||||||
|
<script>
|
||||||
|
window.addEventListener("load", async () => {
|
||||||
|
await wasm_bindgen("./kroz_bg.wasm");
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -1,4 +1,4 @@
|
||||||
use std::time::Instant;
|
use instant::Instant;
|
||||||
|
|
||||||
pub mod monster;
|
pub mod monster;
|
||||||
pub mod player;
|
pub mod player;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::time::Instant;
|
use instant::Instant;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Player {
|
pub struct Player {
|
||||||
|
|
|
@ -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(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()
|
||||||
|
@ -70,16 +77,20 @@ pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
VirtualKeyCode::P => {
|
VirtualKeyCode::P => {
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.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. "));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.play_sound(resources.sound_effects.bad_key.clone());
|
{
|
||||||
|
sound_output.play_sound(sound_effects.bad_key.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::time::{Duration, Instant};
|
use instant::Instant;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::{Entity, With, Without, World};
|
use hecs::{Entity, With, Without, World};
|
||||||
|
@ -29,10 +30,12 @@ pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut R
|
||||||
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));
|
||||||
resources.sound_output.play_sound(sound_effect_for_kind(
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
monster.kind,
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
&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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,15 +51,17 @@ 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);
|
||||||
|
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.play_sound(resources.sound_effects.step.clone());
|
{
|
||||||
|
sound_output.play_sound(sound_effects.step.clone());
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
let static_sound = resources
|
} else if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_effects
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.get_new_static_effect(&resources.sound_output);
|
{
|
||||||
resources.sound_output.play_sound(static_sound);
|
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;
|
||||||
|
@ -75,18 +80,22 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
| crate::tile_data::TileType::Medium
|
| crate::tile_data::TileType::Medium
|
||||||
| crate::tile_data::TileType::Fast => true,
|
| crate::tile_data::TileType::Fast => true,
|
||||||
crate::tile_data::TileType::Block | crate::tile_data::TileType::Wall => {
|
crate::tile_data::TileType::Block | crate::tile_data::TileType::Wall => {
|
||||||
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.stats.score > 2 {
|
if resources.stats.score > 2 {
|
||||||
resources.stats.take_score(2);
|
resources.stats.take_score(2);
|
||||||
}
|
}
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
crate::tile_data::TileType::Whip => {
|
crate::tile_data::TileType::Whip => {
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.play_sound(resources.sound_effects.grab.clone());
|
{
|
||||||
|
sound_output.play_sound(sound_effects.grab.clone());
|
||||||
|
}
|
||||||
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);
|
||||||
|
@ -99,9 +108,11 @@ fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||||
crate::tile_data::TileType::Chest => todo!(),
|
crate::tile_data::TileType::Chest => todo!(),
|
||||||
crate::tile_data::TileType::SlowTime => todo!(),
|
crate::tile_data::TileType::SlowTime => todo!(),
|
||||||
crate::tile_data::TileType::Gem => {
|
crate::tile_data::TileType::Gem => {
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.play_sound(resources.sound_effects.grab.clone());
|
{
|
||||||
|
sound_output.play_sound(sound_effects.grab.clone());
|
||||||
|
}
|
||||||
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);
|
||||||
|
@ -109,9 +120,11 @@ 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 => {
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.play_sound(resources.sound_effects.grab.clone());
|
{
|
||||||
|
sound_output.play_sound(sound_effects.grab.clone());
|
||||||
|
}
|
||||||
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);
|
||||||
|
@ -173,11 +186,15 @@ pub fn whip(world: &mut World, resources: &mut Resources) {
|
||||||
WantsToWhip {
|
WantsToWhip {
|
||||||
frame: 0,
|
frame: 0,
|
||||||
last_frame: Instant::now(),
|
last_frame: Instant::now(),
|
||||||
sound: Some(
|
sound: {
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.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;
|
||||||
|
|
77
src/main.rs
77
src/main.rs
|
@ -10,74 +10,29 @@ mod state;
|
||||||
pub mod systems;
|
pub mod systems;
|
||||||
pub mod tile_data;
|
pub mod tile_data;
|
||||||
|
|
||||||
use std::time::Instant;
|
use std::panic;
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::World;
|
|
||||||
use resources::{difficulty::SECRET, *};
|
|
||||||
use state::State;
|
use state::State;
|
||||||
|
use wasm_bindgen::{prelude::wasm_bindgen, JsValue};
|
||||||
|
|
||||||
|
#[wasm_bindgen(start)]
|
||||||
|
pub fn main_js() -> Result<(), JsValue> {
|
||||||
|
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||||
|
let _ = main_common(false);
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> BError {
|
fn main() -> BError {
|
||||||
|
main_common(true)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main_common(initialize_sound: bool) -> BError {
|
||||||
let context = BTermBuilder::vga(80, 25)
|
let context = BTermBuilder::vga(80, 25)
|
||||||
.with_fps_cap(60.0)
|
.with_fps_cap(60.0)
|
||||||
.with_title("Kroz")
|
.with_title("Kroz")
|
||||||
.build()?;
|
.build()
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
let mut sound_output = SoundOutput::new();
|
main_loop(context, State::new(initialize_sound))
|
||||||
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 std::time::Instant;
|
use instant::Instant;
|
||||||
|
|
||||||
pub struct Clock {
|
pub struct Clock {
|
||||||
pub last_ticked: Instant,
|
pub last_ticked: Instant,
|
||||||
|
|
|
@ -1,8 +1,10 @@
|
||||||
use std::time::{Duration, Instant};
|
use instant::Instant;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::constants::*;
|
use crate::constants::*;
|
||||||
|
|
||||||
pub enum FlashingMessageIntent {
|
pub enum FlashingMessageIntent {
|
||||||
|
Start,
|
||||||
Quit,
|
Quit,
|
||||||
Save,
|
Save,
|
||||||
Restore,
|
Restore,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use std::time::Instant;
|
use instant::Instant;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
components::{monster::*, Monster, Player, Position, Renderable},
|
components::{monster::*, Monster, Player, Position, Renderable},
|
||||||
|
|
|
@ -24,8 +24,8 @@ pub struct Resources {
|
||||||
pub stop_clock: bool,
|
pub stop_clock: bool,
|
||||||
pub map: Map,
|
pub map: Map,
|
||||||
pub selected_difficulty: Option<Difficulty>,
|
pub selected_difficulty: Option<Difficulty>,
|
||||||
pub sound_effects: SoundEffects,
|
pub sound_effects: Option<SoundEffects>,
|
||||||
pub sound_output: SoundOutput,
|
pub sound_output: Option<SoundOutput>,
|
||||||
pub flashing_message: Option<FlashingMessage>,
|
pub flashing_message: Option<FlashingMessage>,
|
||||||
pub should_advance_level: bool,
|
pub should_advance_level: bool,
|
||||||
}
|
}
|
||||||
|
|
61
src/state.rs
61
src/state.rs
|
@ -1,5 +1,11 @@
|
||||||
use crate::resources::flashing_message::FlashingMessage;
|
use instant::Instant;
|
||||||
use crate::resources::{Map, Resources};
|
|
||||||
|
use crate::resources::clock::Clock;
|
||||||
|
use crate::resources::difficulty::*;
|
||||||
|
use crate::resources::flashing_message::{FlashingMessage, FlashingMessageIntent};
|
||||||
|
use crate::resources::sound_effects::SoundEffects;
|
||||||
|
use crate::resources::stats::Stats;
|
||||||
|
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;
|
||||||
|
@ -22,7 +28,56 @@ impl GameState for State {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl State {
|
impl State {
|
||||||
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 = 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::new(
|
||||||
|
"Press any key to begin this level.",
|
||||||
|
Some(FlashingMessageIntent::Start),
|
||||||
|
)),
|
||||||
|
should_advance_level: false,
|
||||||
|
};
|
||||||
|
|
||||||
State { world, resources }
|
State { world, resources }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,10 +56,12 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
// 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));
|
||||||
resources.sound_output.play_sound(sound_effect_for_kind(
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
monster.kind,
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
&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 {
|
||||||
|
@ -67,10 +69,14 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
match tile {
|
match tile {
|
||||||
TileType::Wall => {}
|
TileType::Wall => {}
|
||||||
TileType::Block => {
|
TileType::Block => {
|
||||||
resources.sound_output.play_sound(sound_effect_for_kind(
|
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,
|
monster.kind,
|
||||||
&resources.sound_effects,
|
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);
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::time::{Duration, Instant};
|
use instant::Instant;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use crate::constants::CLOCK_PERIOD;
|
use crate::constants::CLOCK_PERIOD;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
use std::time::{Duration, Instant};
|
use instant::Instant;
|
||||||
|
use std::time::Duration;
|
||||||
|
|
||||||
use bracket_lib::prelude::*;
|
use bracket_lib::prelude::*;
|
||||||
use hecs::{Entity, World};
|
use hecs::{Entity, World};
|
||||||
|
@ -77,15 +78,16 @@ pub fn run(world: &mut World, resources: &mut Resources) {
|
||||||
}
|
}
|
||||||
if wants_to_whip.frame == 7 {
|
if wants_to_whip.frame == 7 {
|
||||||
wants_to_whip.sound = None;
|
wants_to_whip.sound = None;
|
||||||
resources
|
if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.play_sound(resources.sound_effects.whipping_hit_end.clone());
|
{
|
||||||
} else {
|
sound_output.play_sound(sound_effects.whipping_hit_end.clone());
|
||||||
wants_to_whip.sound = Some(
|
}
|
||||||
resources
|
} else if let (Some(sound_effects), Some(sound_output)) =
|
||||||
.sound_output
|
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||||
.play_sound(resources.sound_effects.whipping_hit.clone()),
|
{
|
||||||
);
|
wants_to_whip.sound =
|
||||||
|
Some(sound_output.play_sound(sound_effects.whipping_hit.clone()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue