Compare commits
23 commits
c0ce37aa38
...
ce05dcb194
Author | SHA1 | Date | |
---|---|---|---|
ce05dcb194 | |||
3129f1be1d | |||
9e83e004dc | |||
7c93fb2bae | |||
c17013ac92 | |||
f08691a62e | |||
ecd7c87e29 | |||
cbcda28719 | |||
4cd9f5acc3 | |||
fe7eef7770 | |||
f38a80b0c7 | |||
2b484a4ad7 | |||
e948ad1d93 | |||
094d8e8617 | |||
550713aaf8 | |||
0e5e823b0b | |||
def124cd71 | |||
ecaf448e90 | |||
cf4e818094 | |||
616a4d580a | |||
c138aeb228 | |||
a3adb27acf | |||
d9606e8b87 |
46 changed files with 6618 additions and 806 deletions
28
.drone.yml
28
.drone.yml
|
@ -6,12 +6,15 @@ steps:
|
|||
image: rust
|
||||
commands:
|
||||
- apt-get update
|
||||
- apt-get install -y libasound2-dev g++-mingw-w64-x86-64
|
||||
- apt-get install -y libasound2-dev g++-mingw-w64-x86-64 npm
|
||||
- rustup target add x86_64-pc-windows-gnu
|
||||
- rustup toolchain install stable-x86_64-pc-windows-gnu
|
||||
- cargo build --release --verbose --all
|
||||
- rustup target add wasm32-unknown-unknown
|
||||
- cargo build --release --verbose --all --target x86_64-unknown-linux-gnu
|
||||
- cargo build --release --verbose --all --target x86_64-pc-windows-gnu
|
||||
- mv target/release/kroz kroz_linux_x86_64
|
||||
- npm install
|
||||
- npm run build
|
||||
- mv target/x86_64-unknown-linux-gnu/release/kroz kroz_linux_x86_64
|
||||
- mv target/x86_64-pc-windows-gnu/release/kroz.exe kroz_win_x86_64.exe
|
||||
- name: release
|
||||
image: plugins/gitea-release
|
||||
|
@ -29,3 +32,22 @@ steps:
|
|||
when:
|
||||
event:
|
||||
- tag
|
||||
- name: deploy
|
||||
image: alpine
|
||||
volumes:
|
||||
- name: krozhtml
|
||||
path: /html
|
||||
commands:
|
||||
- rm -r /html/*.wasm || true
|
||||
- cp -r dist/* /html/
|
||||
- chown -R 1000:1000 /html/*
|
||||
when:
|
||||
event:
|
||||
- promote
|
||||
target:
|
||||
- production
|
||||
|
||||
volumes:
|
||||
- name: krozhtml
|
||||
host:
|
||||
path: /home/alex/docker/kroz/files
|
||||
|
|
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -1,3 +1,7 @@
|
|||
/extern
|
||||
/target
|
||||
.vscode
|
||||
/pkg
|
||||
node_modules
|
||||
/dist
|
||||
/wasm-pack.log
|
||||
|
|
200
Cargo.lock
generated
200
Cargo.lock
generated
|
@ -22,9 +22,14 @@ checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
|
|||
|
||||
[[package]]
|
||||
name = "ahash"
|
||||
version = "0.3.8"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
|
||||
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"once_cell",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
|
@ -82,23 +87,11 @@ version = "1.0.53"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "94a45b455c14666b85fc40a019e8ab9eb75e3a124e05494f5397122bc9eb06e0"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "atom"
|
||||
version = "0.3.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c9ff149ed9780025acfdb36862d35b28856bb693ceb451259a7164442f22fdc3"
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.0.1"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a"
|
||||
checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
|
||||
|
||||
[[package]]
|
||||
name = "bindgen"
|
||||
|
@ -134,7 +127,7 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a"
|
|||
[[package]]
|
||||
name = "bracket-algorithm-traits"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"bracket-geometry",
|
||||
"smallvec",
|
||||
|
@ -143,7 +136,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-color"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"parking_lot",
|
||||
|
@ -152,7 +145,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-embedding"
|
||||
version = "0.8.0"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"parking_lot",
|
||||
|
@ -161,7 +154,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-geometry"
|
||||
version = "0.8.3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"ultraviolet",
|
||||
]
|
||||
|
@ -169,7 +162,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-lib"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"bracket-algorithm-traits",
|
||||
"bracket-color",
|
||||
|
@ -183,7 +176,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-noise"
|
||||
version = "0.8.2"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"bracket-random",
|
||||
]
|
||||
|
@ -191,7 +184,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-pathfinding"
|
||||
version = "0.8.4"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"bracket-algorithm-traits",
|
||||
"bracket-geometry",
|
||||
|
@ -202,7 +195,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-random"
|
||||
version = "0.8.3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
"js-sys",
|
||||
|
@ -216,7 +209,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-rex"
|
||||
version = "0.8.0"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"bracket-color",
|
||||
"bracket-embedding",
|
||||
|
@ -227,7 +220,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "bracket-terminal"
|
||||
version = "0.8.5"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#5e35a050f5181892155a2eb4641af7445273a6f3"
|
||||
source = "git+https://github.com/amethyst/bracket-lib#cf8eec60ae17f2534a14f3ae643c871202aed192"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"bracket-color",
|
||||
|
@ -332,9 +325,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "clang-sys"
|
||||
version = "1.3.0"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fa66045b9cb23c2e9c1520732030608b02ee07e5cfaa5a521ec15ded7fa24c90"
|
||||
checksum = "4cc00842eed744b858222c4c9faf7243aafc6d33f92f96935263ef4d8a41ce21"
|
||||
dependencies = [
|
||||
"glob",
|
||||
"libc",
|
||||
|
@ -350,7 +343,7 @@ dependencies = [
|
|||
"bitflags",
|
||||
"block",
|
||||
"cocoa-foundation",
|
||||
"core-foundation 0.9.2",
|
||||
"core-foundation 0.9.3",
|
||||
"core-graphics 0.22.3",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
|
@ -365,7 +358,7 @@ checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318"
|
|||
dependencies = [
|
||||
"bitflags",
|
||||
"block",
|
||||
"core-foundation 0.9.2",
|
||||
"core-foundation 0.9.3",
|
||||
"core-graphics-types",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
|
@ -410,9 +403,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "core-foundation"
|
||||
version = "0.9.2"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6888e10551bb93e424d8df1d07f1a8b4fceb0001a3a4b048bfc47554946f47b3"
|
||||
checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146"
|
||||
dependencies = [
|
||||
"core-foundation-sys 0.8.3",
|
||||
"libc",
|
||||
|
@ -449,7 +442,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "2581bbab3b8ffc6fcbd550bf46c355135d16e9ff2a6ea032ad6b9bf1d7efe4fb"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation 0.9.2",
|
||||
"core-foundation 0.9.3",
|
||||
"core-graphics-types",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
|
@ -462,7 +455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"core-foundation 0.9.2",
|
||||
"core-foundation 0.9.3",
|
||||
"foreign-types",
|
||||
"libc",
|
||||
]
|
||||
|
@ -520,15 +513,16 @@ dependencies = [
|
|||
"parking_lot",
|
||||
"stdweb",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crc32fast"
|
||||
version = "1.3.1"
|
||||
version = "1.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2209c310e29876f7f0b2721e7e26b84aff178aa3da5d091f9bfbf47669e60e3"
|
||||
checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
@ -543,8 +537,8 @@ dependencies = [
|
|||
"crossbeam-channel",
|
||||
"crossbeam-deque",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-queue 0.3.3",
|
||||
"crossbeam-utils 0.8.6",
|
||||
"crossbeam-queue",
|
||||
"crossbeam-utils 0.8.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -554,7 +548,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "e54ea8bc3fb1ee042f5aace6e3c6e025d3874866da222930f70ce62aceba0bfa"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils 0.8.6",
|
||||
"crossbeam-utils 0.8.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -565,17 +559,17 @@ checksum = "6455c0ca19f0d2fbf751b908d5c55c1f5cbc65e03c4225427254b46890bdde1e"
|
|||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-epoch",
|
||||
"crossbeam-utils 0.8.6",
|
||||
"crossbeam-utils 0.8.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-epoch"
|
||||
version = "0.9.6"
|
||||
version = "0.9.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "97242a70df9b89a65d0b6df3c4bf5b9ce03c5b7309019777fbde37e7537f8762"
|
||||
checksum = "c00d6d2ea26e8b151d99093005cb442fb9a37aeaca582a03ec70946f49ab5ed9"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils 0.8.6",
|
||||
"crossbeam-utils 0.8.7",
|
||||
"lazy_static",
|
||||
"memoffset",
|
||||
"scopeguard",
|
||||
|
@ -583,23 +577,12 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.2.3"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570"
|
||||
dependencies = [
|
||||
"cfg-if 0.1.10",
|
||||
"crossbeam-utils 0.7.2",
|
||||
"maybe-uninit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "crossbeam-queue"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b979d76c9fcb84dffc80a73f7290da0f83e4c95773494674cb44b76d13a7a110"
|
||||
checksum = "4dd435b205a4842da59efd07628f921c096bc1cc0a156835b4fa0bcb9a19bcce"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"crossbeam-utils 0.8.6",
|
||||
"crossbeam-utils 0.8.7",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -615,9 +598,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "crossbeam-utils"
|
||||
version = "0.8.6"
|
||||
version = "0.8.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfcae03edb34f947e64acdb1c33ec169824e20657e9ecb61cef6c8c74dcb8120"
|
||||
checksum = "b5e5bed1f1c269533fa816a0a5492b3545209a205ca1a54842be180eb63a16a6"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"lazy_static",
|
||||
|
@ -821,9 +804,9 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
|
|||
|
||||
[[package]]
|
||||
name = "fundsp"
|
||||
version = "0.1.0"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e44dcde4aedad5675c131b5114d431b4d7c739dc32dd599bf0460f36413d247e"
|
||||
checksum = "914385c9ea3226815d12f436c2c60b2e6f88a89af684ed9e24d62e55f1b0dba1"
|
||||
dependencies = [
|
||||
"generic-array",
|
||||
"lazy_static",
|
||||
|
@ -899,7 +882,7 @@ dependencies = [
|
|||
"android_glue",
|
||||
"cgl",
|
||||
"cocoa",
|
||||
"core-foundation 0.9.2",
|
||||
"core-foundation 0.9.3",
|
||||
"glutin_egl_sys",
|
||||
"glutin_emscripten_sys",
|
||||
"glutin_gles2_sys",
|
||||
|
@ -964,21 +947,20 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "hashbrown"
|
||||
version = "0.7.2"
|
||||
version = "0.11.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "96282e96bfcd3da0d3aa9938bedf1e50df3269b6db08b4876d2da0bb1a0841cf"
|
||||
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hibitset"
|
||||
version = "0.6.3"
|
||||
name = "hecs"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "93a1bb8316a44459a7d14253c4d28dd7395cbd23cc04a68c46e851b8e46d64b1"
|
||||
checksum = "ddd0e227c3f78ad06fcc590966b327a2f8fef03ef51812dad4fbff5b0a6424bd"
|
||||
dependencies = [
|
||||
"atom",
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1089,12 +1071,15 @@ name = "kroz"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bracket-lib",
|
||||
"console_error_panic_hook",
|
||||
"cpal",
|
||||
"fundsp",
|
||||
"hecs",
|
||||
"instant",
|
||||
"oddio",
|
||||
"specs",
|
||||
"specs-derive",
|
||||
"typenum",
|
||||
"wasm-bindgen",
|
||||
"winres",
|
||||
]
|
||||
|
||||
|
@ -1112,9 +1097,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.116"
|
||||
version = "0.2.117"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "565dbd88872dbe4cc8a46e527f26483c1d1f7afa6b884a3bd6cd893d4f98da74"
|
||||
checksum = "e74d72e0f9b65b5b4ca49a346af3976df0f9c61d550727f349ecd559f251a26c"
|
||||
|
||||
[[package]]
|
||||
name = "libloading"
|
||||
|
@ -1172,12 +1157,6 @@ dependencies = [
|
|||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "maybe-uninit"
|
||||
version = "2.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.4.1"
|
||||
|
@ -1229,9 +1208,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "mint"
|
||||
version = "0.5.8"
|
||||
version = "0.5.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "162e591484b4b8fe9e1ca16ebf07ab584fdc3334508d76a788cd54d89cfc20dc"
|
||||
checksum = "e53debba6bda7a793e5f99b8dacf19e626084f525f7829104ba9898f367d85ff"
|
||||
|
||||
[[package]]
|
||||
name = "mio"
|
||||
|
@ -1284,7 +1263,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "b47412f3a52115b936ff2a229b803498c7b4d332adeb87c2f1498c9da54c398c"
|
||||
dependencies = [
|
||||
"crossbeam",
|
||||
"crossbeam-queue 0.3.3",
|
||||
"crossbeam-queue",
|
||||
"log",
|
||||
"mio 0.7.14",
|
||||
]
|
||||
|
@ -1310,12 +1289,6 @@ dependencies = [
|
|||
"winapi 0.3.9",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mopa"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a785740271256c230f57462d3b83e52f998433a7062fc18f96d5999474a9f915"
|
||||
|
||||
[[package]]
|
||||
name = "ndk"
|
||||
version = "0.2.1"
|
||||
|
@ -1987,25 +1960,6 @@ version = "0.1.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
|
||||
|
||||
[[package]]
|
||||
name = "shred"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c5f08237e667ac94ad20f8878b5943d91a93ccb231428446c57c21c57779016d"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"hashbrown",
|
||||
"mopa",
|
||||
"smallvec",
|
||||
"tynm",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shrev"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5752e017e03af9d735b4b069f53b7a7fd90fefafa04d8bd0c25581b0bff437f"
|
||||
|
||||
[[package]]
|
||||
name = "slab"
|
||||
version = "0.4.5"
|
||||
|
@ -2046,21 +2000,6 @@ dependencies = [
|
|||
"wayland-protocols",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "specs"
|
||||
version = "0.16.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fff28a29366aff703d5da8a7e2c8875dc8453ac1118f842cbc0fa70c7db51240"
|
||||
dependencies = [
|
||||
"crossbeam-queue 0.2.3",
|
||||
"hashbrown",
|
||||
"hibitset",
|
||||
"log",
|
||||
"shred",
|
||||
"shrev",
|
||||
"tuple_utils",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "specs-derive"
|
||||
version = "0.4.1"
|
||||
|
@ -2199,21 +2138,6 @@ version = "0.6.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e5d7cd7ab3e47dda6e56542f4bbf3824c15234958c6e1bd6aaa347e93499fdc"
|
||||
|
||||
[[package]]
|
||||
name = "tuple_utils"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "44834418e2c5b16f47bedf35c28e148db099187dd5feee6367fb2525863af4f1"
|
||||
|
||||
[[package]]
|
||||
name = "tynm"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a4df2caa2dc9c3d1f7641ba981f4cd40ab229775aa7aeb834c9ab2850d50623d"
|
||||
dependencies = [
|
||||
"nom 5.1.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.15.0"
|
||||
|
@ -2480,7 +2404,7 @@ checksum = "da4eda6fce0eb84bd0a33e3c8794eb902e1033d0a1d5a31bc4f19b1b4bbff597"
|
|||
dependencies = [
|
||||
"bitflags",
|
||||
"cocoa",
|
||||
"core-foundation 0.9.2",
|
||||
"core-foundation 0.9.3",
|
||||
"core-graphics 0.22.3",
|
||||
"core-video-sys",
|
||||
"dispatch",
|
||||
|
@ -2513,7 +2437,7 @@ checksum = "79610794594d5e86be473ef7763f604f2159cbac8c94debd00df8fb41e86c2f8"
|
|||
dependencies = [
|
||||
"bitflags",
|
||||
"cocoa",
|
||||
"core-foundation 0.9.2",
|
||||
"core-foundation 0.9.3",
|
||||
"core-graphics 0.22.3",
|
||||
"core-video-sys",
|
||||
"dispatch",
|
||||
|
|
19
Cargo.toml
19
Cargo.toml
|
@ -4,15 +4,26 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
build = "build.rs"
|
||||
|
||||
[lib]
|
||||
name = "libkroz"
|
||||
crate-type = ["cdylib", "rlib"]
|
||||
|
||||
[[bin]]
|
||||
name = "kroz"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
# bracket-lib = { path = "extern/bracket-lib" }
|
||||
bracket-lib = { git = "https://github.com/amethyst/bracket-lib" }
|
||||
specs = { version = "0.16.1", default-features = false }
|
||||
hecs = "0.5.1"
|
||||
specs-derive = "0.4.1"
|
||||
cpal = "0.13"
|
||||
oddio = "0.5"
|
||||
cpal = { version = "0.13.0", features = ["wasm-bindgen"] }
|
||||
oddio = "0.5.0"
|
||||
fundsp = "0.1.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]
|
||||
winres = "0.1"
|
||||
winres = "0.1.12"
|
||||
|
|
14
README.md
14
README.md
|
@ -17,13 +17,19 @@ The goal is to closely mimic the look and behavior of the original game, but not
|
|||
- Game speed will be fixed, possibly configurable
|
||||
- The original game's speed varied with CPU speed
|
||||
- Improve control response
|
||||
- Support Windows, Linux, macOS
|
||||
- Possibly web and mobile platforms too
|
||||
- Support Windows, Linux, macOS, and the web
|
||||
|
||||
## Building
|
||||
|
||||
1. [Install Rust](https://rustup.rs/)
|
||||
2. Run `cargo build` or `cargo run`
|
||||
[Install Rust](https://rustup.rs/)
|
||||
|
||||
### Desktop
|
||||
|
||||
Run `cargo build` or `cargo run`
|
||||
|
||||
### Web
|
||||
|
||||
Run `npm run build` or `npm start`
|
||||
|
||||
## License
|
||||
|
||||
|
|
8
build.rs
8
build.rs
|
@ -1,12 +1,12 @@
|
|||
#[cfg(target_os = "windows")]
|
||||
#[cfg(windows)]
|
||||
extern crate winres;
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
#[cfg(windows)]
|
||||
fn main() {
|
||||
let mut res = winres::WindowsResource::new();
|
||||
res.set_icon("icon.ico");
|
||||
res.compile().unwrap();
|
||||
let _ = res.compile();
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "windows"))]
|
||||
#[cfg(not(windows))]
|
||||
fn main() {}
|
||||
|
|
1
js/index.js
Normal file
1
js/index.js
Normal file
|
@ -0,0 +1 @@
|
|||
import("../pkg/index.js").catch(console.error);
|
5324
package-lock.json
generated
Normal file
5324
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
18
package.json
Normal file
18
package.json
Normal file
|
@ -0,0 +1,18 @@
|
|||
{
|
||||
"author": "anpage <alex@anpage.me>",
|
||||
"name": "kroz",
|
||||
"version": "0.1.0",
|
||||
"scripts": {
|
||||
"build": "rimraf dist pkg && webpack",
|
||||
"start": "rimraf dist pkg && webpack-dev-server --open -d",
|
||||
"test": "cargo test && wasm-pack test --headless"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@wasm-tool/wasm-pack-plugin": "^1.1.0",
|
||||
"copy-webpack-plugin": "^5.0.3",
|
||||
"webpack": "^4.42.0",
|
||||
"webpack-cli": "^3.3.3",
|
||||
"webpack-dev-server": "^3.7.1",
|
||||
"rimraf": "^3.0.0"
|
||||
}
|
||||
}
|
|
@ -1,7 +1,4 @@
|
|||
use std::time::Instant;
|
||||
|
||||
use specs::prelude::*;
|
||||
use specs_derive::Component;
|
||||
use instant::Instant;
|
||||
|
||||
pub mod monster;
|
||||
pub mod player;
|
||||
|
@ -15,7 +12,6 @@ pub use renderable::Renderable;
|
|||
|
||||
use crate::resources::sound_output::SoundEffectHandle;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct WantsToWhip {
|
||||
pub frame: u8,
|
||||
pub last_frame: Instant,
|
||||
|
|
|
@ -3,10 +3,8 @@ use crate::{
|
|||
resources::{sound_output::SoundSamples, SoundEffects},
|
||||
};
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use specs_derive::Component;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct Monster {
|
||||
pub kind: MonsterKind,
|
||||
pub ticks_until_move: i32,
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
use std::time::Instant;
|
||||
use instant::Instant;
|
||||
|
||||
use specs::prelude::*;
|
||||
use specs_derive::Component;
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
#[derive(Debug)]
|
||||
pub struct Player {
|
||||
pub last_moved: Instant,
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use specs_derive::Component;
|
||||
|
||||
#[derive(Component, Clone, Copy)]
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct Position {
|
||||
pub x: i32,
|
||||
pub y: i32,
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use specs_derive::Component;
|
||||
|
||||
#[derive(Component)]
|
||||
#[derive(Debug)]
|
||||
pub struct Renderable {
|
||||
pub glyph: FontCharType,
|
||||
pub fg: RGB,
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
/// Fast PC mode at 400 cycles/ms.
|
||||
pub const CLOCK_PERIOD: f32 = 0.184;
|
||||
pub const PLAYER_STEP_PERIOD: f32 = 1.0 / 7.5;
|
||||
pub const FLASHING_PERIOD: f32 = 0.02;
|
||||
|
||||
pub const SIDEBAR_POS_X: i32 = 66;
|
||||
pub const SIDEBAR_POS_Y: i32 = 0;
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use hecs::World;
|
||||
|
||||
use crate::{components::*, constants::*};
|
||||
|
||||
pub fn draw(world: &World, bterm: &mut BTerm) {
|
||||
let positions = world.read_storage::<Position>();
|
||||
let renderables = world.read_storage::<Renderable>();
|
||||
|
||||
for (pos, render) in (&positions, &renderables).join() {
|
||||
for (_, (pos, render)) in &mut world.query::<(&Position, &Renderable)>() {
|
||||
bterm.set(
|
||||
pos.x + MAP_X as i32,
|
||||
pos.y + MAP_Y as i32,
|
||||
|
|
18
src/graphics/flashing_message.rs
Normal file
18
src/graphics/flashing_message.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
use crate::constants::*;
|
||||
use crate::graphics::vga_color as vga;
|
||||
use crate::resources::Resources;
|
||||
use bracket_lib::prelude::*;
|
||||
|
||||
pub fn draw(resources: &mut Resources, bterm: &mut BTerm) {
|
||||
if let Some(flashing_message) = &mut resources.flashing_message {
|
||||
flashing_message.next_color();
|
||||
|
||||
bterm.print_color_centered_at(
|
||||
MAP_X + (MAP_WIDTH / 2),
|
||||
MAP_Y + MAP_HEIGHT,
|
||||
RGB::named(vga::get_by_index(flashing_message.color)),
|
||||
RGB::named(vga::BLACK),
|
||||
flashing_message.message.to_string(),
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::resources::*;
|
||||
|
||||
pub fn draw(world: &World, bterm: &mut BTerm) {
|
||||
let map = world.fetch::<Map>();
|
||||
map.draw(bterm);
|
||||
pub fn draw(resources: &Resources, bterm: &mut BTerm) {
|
||||
resources.map.draw(bterm);
|
||||
}
|
||||
|
|
|
@ -1,16 +1,20 @@
|
|||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use hecs::World;
|
||||
|
||||
use crate::resources::Resources;
|
||||
|
||||
mod entities;
|
||||
mod flashing_message;
|
||||
mod map;
|
||||
mod sidebar;
|
||||
pub mod vga_color;
|
||||
mod whip;
|
||||
|
||||
pub fn draw(world: &World, bterm: &mut BTerm) {
|
||||
pub fn draw(world: &World, resources: &mut Resources, bterm: &mut BTerm) {
|
||||
bterm.cls();
|
||||
map::draw(world, bterm);
|
||||
map::draw(resources, bterm);
|
||||
entities::draw(world, bterm);
|
||||
whip::draw(world, bterm);
|
||||
sidebar::draw(world, bterm);
|
||||
whip::draw(world, resources, bterm);
|
||||
flashing_message::draw(resources, bterm);
|
||||
sidebar::draw(resources, bterm);
|
||||
}
|
||||
|
|
|
@ -1,10 +1,9 @@
|
|||
use crate::constants::{SIDEBAR_POS_X, SIDEBAR_POS_Y};
|
||||
use crate::graphics::vga_color as vga;
|
||||
use crate::resources::{Clock, LevelNumber, ShowDebugInfo, Stats};
|
||||
use crate::resources::Resources;
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
pub fn draw(world: &World, bterm: &mut BTerm) {
|
||||
pub fn draw(resources: &Resources, bterm: &mut BTerm) {
|
||||
// Blue background
|
||||
bterm.fill_region(
|
||||
Rect {
|
||||
|
@ -39,15 +38,15 @@ pub fn draw(world: &World, bterm: &mut BTerm) {
|
|||
bterm.print_centered_at(
|
||||
SIDEBAR_POS_X + 6,
|
||||
SIDEBAR_POS_Y + 4,
|
||||
world.read_resource::<LevelNumber>().0 + 1,
|
||||
resources.level_number + 1,
|
||||
);
|
||||
bterm.print(SIDEBAR_POS_X + 4, SIDEBAR_POS_Y + 6, "Gems");
|
||||
bterm.print(SIDEBAR_POS_X + 4, SIDEBAR_POS_Y + 9, "Whips");
|
||||
bterm.print(SIDEBAR_POS_X + 2, SIDEBAR_POS_Y + 12, "Teleports");
|
||||
bterm.print(SIDEBAR_POS_X + 4, SIDEBAR_POS_Y + 15, "Keys");
|
||||
|
||||
let stats = world.read_resource::<Stats>();
|
||||
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 1, stats.score);
|
||||
let stats = &resources.stats;
|
||||
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 1, stats.score * 10);
|
||||
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 7, stats.gems);
|
||||
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 10, stats.whips);
|
||||
bterm.print_centered_at(SIDEBAR_POS_X + 6, SIDEBAR_POS_Y + 13, stats.teleports);
|
||||
|
@ -89,11 +88,13 @@ pub fn draw(world: &World, bterm: &mut BTerm) {
|
|||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 19, "Whip");
|
||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 20, "Teleport");
|
||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 21, "Pause");
|
||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 22, "Quit");
|
||||
if !cfg!(target_family = "wasm") {
|
||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 22, "Quit");
|
||||
}
|
||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 23, "Save");
|
||||
bterm.print(SIDEBAR_POS_X + 3, SIDEBAR_POS_Y + 24, "Restore");
|
||||
|
||||
if world.read_resource::<ShowDebugInfo>().0 {
|
||||
if resources.show_debug_info {
|
||||
bterm.print_color_right(
|
||||
SIDEBAR_POS_X + 14,
|
||||
SIDEBAR_POS_Y,
|
||||
|
@ -102,12 +103,22 @@ pub fn draw(world: &World, bterm: &mut BTerm) {
|
|||
&format!("{}", bterm.fps),
|
||||
);
|
||||
|
||||
let mut debug_string = format!("{}", resources.clock.ticks);
|
||||
|
||||
if resources.speed_time_ticks > 0 {
|
||||
debug_string += " SPEED"
|
||||
}
|
||||
|
||||
if resources.slow_time_ticks > 0 {
|
||||
debug_string += " SLOW"
|
||||
}
|
||||
|
||||
bterm.print_color(
|
||||
0,
|
||||
0,
|
||||
RGB::named(vga::YELLOW_BRIGHT),
|
||||
RGB::named(vga::BLACK),
|
||||
&format!("{}", world.read_resource::<Clock>().ticks),
|
||||
&debug_string,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use hecs::World;
|
||||
|
||||
use crate::{components::*, constants::*, resources::*};
|
||||
|
||||
use super::{vga_color as vga, vga_color::get_by_index};
|
||||
|
||||
pub fn draw(world: &World, bterm: &mut BTerm) {
|
||||
let positions = world.read_storage::<Position>();
|
||||
let wants_to_whips = world.read_storage::<WantsToWhip>();
|
||||
let map = world.read_resource::<Map>();
|
||||
pub fn draw(world: &World, resources: &Resources, bterm: &mut BTerm) {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
for (position, wants_to_whip) in (&positions, &wants_to_whips).join() {
|
||||
|
||||
for (_, (position, wants_to_whip)) in &mut world.query::<(&Position, &WantsToWhip)>() {
|
||||
let color = RGB::named(get_by_index(rng.range(1, 16)));
|
||||
let mut rendered_frame = wants_to_whip.frame;
|
||||
let frame_data = loop {
|
||||
|
@ -31,7 +29,7 @@ pub fn draw(world: &World, bterm: &mut BTerm) {
|
|||
x: position.x + data.0,
|
||||
y: position.y + data.1,
|
||||
};
|
||||
if map.in_bounds(dest) {
|
||||
if resources.map.in_bounds(dest) {
|
||||
break frame_data;
|
||||
}
|
||||
rendered_frame += 1;
|
||||
|
|
107
src/input/mod.rs
107
src/input/mod.rs
|
@ -1,49 +1,102 @@
|
|||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use hecs::World;
|
||||
|
||||
use crate::resources::*;
|
||||
use crate::resources::{flashing_message::FlashingMessageIntent, *};
|
||||
|
||||
mod player;
|
||||
|
||||
pub fn handle(world: &World, bterm: &mut BTerm) {
|
||||
pub fn handle_intent(bterm: &mut BTerm, _world: &mut World, resources: &mut Resources) {
|
||||
if let Some(key) = bterm.key {
|
||||
if let Some(flashing_message) = &resources.flashing_message {
|
||||
if let Some(intent) = &flashing_message.intent {
|
||||
match intent {
|
||||
FlashingMessageIntent::Start => {
|
||||
if resources.sound_output.is_none() || resources.sound_effects.is_none() {
|
||||
let sound_output = SoundOutput::new();
|
||||
resources.sound_effects = Some(SoundEffects::new(&sound_output));
|
||||
resources.sound_output = Some(sound_output);
|
||||
}
|
||||
}
|
||||
FlashingMessageIntent::Quit => {
|
||||
if key == VirtualKeyCode::Y {
|
||||
bterm.quit()
|
||||
}
|
||||
}
|
||||
FlashingMessageIntent::Save => todo!(),
|
||||
FlashingMessageIntent::Restore => todo!(),
|
||||
FlashingMessageIntent::Restart => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn handle(world: &mut World, resources: &mut Resources, bterm: &mut BTerm) {
|
||||
if resources.flashing_message.is_some() && bterm.key.is_some() {
|
||||
handle_intent(bterm, world, resources);
|
||||
resources.flashing_message = None;
|
||||
}
|
||||
|
||||
match bterm.key {
|
||||
None => {}
|
||||
Some(key) => match key {
|
||||
VirtualKeyCode::Left | VirtualKeyCode::J => {
|
||||
player::try_move(-1, 0, world);
|
||||
VirtualKeyCode::Left | VirtualKeyCode::J | VirtualKeyCode::Numpad4 => {
|
||||
player::try_move(-1, 0, world, resources);
|
||||
}
|
||||
VirtualKeyCode::U | VirtualKeyCode::Home => player::try_move(-1, -1, world),
|
||||
VirtualKeyCode::Up | VirtualKeyCode::I => {
|
||||
player::try_move(0, -1, world);
|
||||
VirtualKeyCode::U | VirtualKeyCode::Home | VirtualKeyCode::Numpad7 => {
|
||||
player::try_move(-1, -1, world, resources)
|
||||
}
|
||||
VirtualKeyCode::O | VirtualKeyCode::PageUp => player::try_move(1, -1, world),
|
||||
VirtualKeyCode::Right | VirtualKeyCode::K => {
|
||||
player::try_move(1, 0, world);
|
||||
VirtualKeyCode::Up | VirtualKeyCode::I | VirtualKeyCode::Numpad8 => {
|
||||
player::try_move(0, -1, world, resources);
|
||||
}
|
||||
VirtualKeyCode::Comma | VirtualKeyCode::PageDown => player::try_move(1, 1, world),
|
||||
VirtualKeyCode::Down | VirtualKeyCode::M => {
|
||||
player::try_move(0, 1, world);
|
||||
VirtualKeyCode::O | VirtualKeyCode::PageUp | VirtualKeyCode::Numpad9 => {
|
||||
player::try_move(1, -1, world, resources)
|
||||
}
|
||||
VirtualKeyCode::Right | VirtualKeyCode::K | VirtualKeyCode::Numpad6 => {
|
||||
player::try_move(1, 0, world, resources);
|
||||
}
|
||||
VirtualKeyCode::Comma | VirtualKeyCode::PageDown | VirtualKeyCode::Numpad3 => {
|
||||
player::try_move(1, 1, world, resources)
|
||||
}
|
||||
VirtualKeyCode::Down | VirtualKeyCode::M | VirtualKeyCode::Numpad2 => {
|
||||
player::try_move(0, 1, world, resources);
|
||||
}
|
||||
VirtualKeyCode::N | VirtualKeyCode::End | VirtualKeyCode::Numpad1 => {
|
||||
player::try_move(-1, 1, world, resources)
|
||||
}
|
||||
VirtualKeyCode::N | VirtualKeyCode::End => player::try_move(-1, 1, world),
|
||||
VirtualKeyCode::W => {
|
||||
player::whip(world);
|
||||
}
|
||||
VirtualKeyCode::S => {
|
||||
let mut sound_system = world.write_resource::<SoundOutput>();
|
||||
let sound_effects = world.fetch::<SoundEffects>();
|
||||
sound_system.play_sound(sound_effects.pickup.clone());
|
||||
player::whip(world, resources);
|
||||
}
|
||||
VirtualKeyCode::D => {
|
||||
let mut show_debug_info = world.write_resource::<ShowDebugInfo>();
|
||||
show_debug_info.0 = !show_debug_info.0;
|
||||
resources.show_debug_info = !resources.show_debug_info;
|
||||
}
|
||||
VirtualKeyCode::Escape | VirtualKeyCode::Q => {
|
||||
bterm.quit();
|
||||
if cfg!(not(target_family = "wasm")) {
|
||||
resources.flashing_message = Some(FlashingMessage::new(
|
||||
" Are you sure you want to quit (Y/N)? ",
|
||||
Some(FlashingMessageIntent::Quit),
|
||||
));
|
||||
} else if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.bad_key.clone());
|
||||
}
|
||||
}
|
||||
VirtualKeyCode::P => {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.pause.clone());
|
||||
}
|
||||
resources.flashing_message =
|
||||
Some(FlashingMessage::from(" Press any key to resume game. "));
|
||||
}
|
||||
_ => {
|
||||
let mut sound_system = world.write_resource::<SoundOutput>();
|
||||
let sound_effects = world.fetch::<SoundEffects>();
|
||||
sound_system.play_sound(sound_effects.bad_key.clone());
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.bad_key.clone());
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
|
@ -1,26 +1,19 @@
|
|||
use std::time::{Duration, Instant};
|
||||
use instant::Instant;
|
||||
use std::time::Duration;
|
||||
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use hecs::{Entity, With, Without, World};
|
||||
|
||||
use crate::{
|
||||
components::monster::*, components::*, constants::*, resources::*, systems::TimeSystem,
|
||||
components::monster::*, components::*, constants::*, resources::*, systems, tile_data::TileType,
|
||||
};
|
||||
|
||||
pub fn try_move(delta_x: i32, delta_y: i32, world: &World) {
|
||||
let entities = world.entities();
|
||||
let mut positions = world.write_storage::<Position>();
|
||||
let mut players = world.write_storage::<Player>();
|
||||
let monsters = world.write_storage::<Monster>();
|
||||
let mut map = world.write_resource::<Map>();
|
||||
let mut stats = world.write_resource::<Stats>();
|
||||
let mut sound_output = world.write_resource::<SoundOutput>();
|
||||
let wants_to_whips = world.read_storage::<WantsToWhip>();
|
||||
let mut clock = world.write_resource::<Clock>();
|
||||
pub fn try_move(delta_x: i32, delta_y: i32, world: &mut World, resources: &mut Resources) {
|
||||
let mut to_kill: Vec<Entity> = Vec::new();
|
||||
|
||||
for (player_entity, player, pos) in (&entities, &mut players, &mut positions).join() {
|
||||
for (player_entity, (player, pos)) in &mut world.query::<(&mut Player, &mut Position)>() {
|
||||
// The player shouldn't be able to move while whipping
|
||||
if let Some(_wants_to_whip) = wants_to_whips.get(player_entity) {
|
||||
if let Ok(_wants_to_whip) = world.get::<WantsToWhip>(player_entity) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -31,65 +24,213 @@ pub fn try_move(delta_x: i32, delta_y: i32, world: &World) {
|
|||
y: pos.y + delta_y,
|
||||
};
|
||||
|
||||
let mut sound_effects = world.fetch_mut::<SoundEffects>();
|
||||
|
||||
if map.in_bounds(destination) {
|
||||
if map.is_solid(destination) {
|
||||
sound_output.play_sound(sound_effects.blocked.clone());
|
||||
} else {
|
||||
if let Some(e) = map.get_tile_content_at(destination) {
|
||||
if let Some(monster) = monsters.get(e) {
|
||||
stats.add_score(damage_for_kind(monster.kind));
|
||||
stats.take_gems(damage_for_kind(monster.kind));
|
||||
sound_output
|
||||
.play_sound(sound_effect_for_kind(monster.kind, &sound_effects));
|
||||
let _ = entities.delete(e);
|
||||
if resources.map.in_bounds(destination) {
|
||||
if try_step(destination, world, resources) {
|
||||
if let Some(monster_entity) = resources.map.get_tile_content_at(destination) {
|
||||
if let Ok(monster) = world.get::<Monster>(monster_entity) {
|
||||
resources.stats.add_score(damage_for_kind(monster.kind));
|
||||
resources.stats.take_gems(damage_for_kind(monster.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, sound_effects));
|
||||
}
|
||||
to_kill.push(monster_entity);
|
||||
}
|
||||
}
|
||||
|
||||
map.clear_tile_content_at(Point::from(*pos));
|
||||
resources.map.clear_tile_content_at(Point::from(*pos));
|
||||
|
||||
pos.x = destination.x;
|
||||
pos.y = destination.y;
|
||||
|
||||
map.set_tile_content_at(destination, player_entity);
|
||||
resources
|
||||
.map
|
||||
.set_tile_content_at(destination, player_entity);
|
||||
|
||||
TimeSystem::force_tick(&mut clock);
|
||||
systems::time::force_tick(&mut resources.clock);
|
||||
|
||||
sound_output.play_sound(sound_effects.step.clone());
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.step.clone());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let static_sound = sound_effects.get_new_static_effect(&sound_output);
|
||||
} else if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
let static_sound = sound_effects.get_new_static_effect(sound_output);
|
||||
sound_output.play_sound(static_sound);
|
||||
}
|
||||
|
||||
player.last_moved = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn whip(world: &World) {
|
||||
let entities = world.entities();
|
||||
|
||||
let players = world.read_storage::<Player>();
|
||||
let positions = world.read_storage::<Position>();
|
||||
let mut wants_to_whips = world.write_storage::<WantsToWhip>();
|
||||
|
||||
let mut stats = world.write_resource::<Stats>();
|
||||
let mut sound_output = world.write_resource::<SoundOutput>();
|
||||
let sound_effects = world.fetch::<SoundEffects>();
|
||||
|
||||
for (entity, _player, _position) in (&entities, &players, &positions).join() {
|
||||
if wants_to_whips.get(entity).is_none() && stats.whips > 0 {
|
||||
let _ = wants_to_whips.insert(
|
||||
entity,
|
||||
WantsToWhip {
|
||||
frame: 0,
|
||||
last_frame: Instant::now(),
|
||||
sound: Some(sound_output.play_sound(sound_effects.whipping.clone())),
|
||||
},
|
||||
);
|
||||
stats.whips -= 1;
|
||||
}
|
||||
for e in to_kill {
|
||||
let _ = world.despawn(e);
|
||||
}
|
||||
}
|
||||
|
||||
fn try_step(point: Point, _world: &World, resources: &mut Resources) -> bool {
|
||||
match resources.map.get_tile_at(point) {
|
||||
crate::tile_data::TileType::Floor
|
||||
| crate::tile_data::TileType::Slow
|
||||
| crate::tile_data::TileType::Medium
|
||||
| crate::tile_data::TileType::Fast => true,
|
||||
crate::tile_data::TileType::Block | crate::tile_data::TileType::Wall => {
|
||||
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.stats.score > 2 {
|
||||
resources.stats.take_score(2);
|
||||
}
|
||||
false
|
||||
}
|
||||
crate::tile_data::TileType::Whip => {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.grab.clone());
|
||||
}
|
||||
resources.stats.give_whips(1);
|
||||
resources.stats.add_score(1);
|
||||
resources.map.set_tile_at(point, TileType::Floor);
|
||||
true
|
||||
}
|
||||
crate::tile_data::TileType::Stairs => {
|
||||
resources.should_advance_level = true;
|
||||
true
|
||||
}
|
||||
crate::tile_data::TileType::Chest => todo!(),
|
||||
crate::tile_data::TileType::SlowTime => {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.slow_time.clone());
|
||||
}
|
||||
|
||||
if !resources.message_shown.slow_time {
|
||||
resources.flashing_message = Some(FlashingMessage::from(
|
||||
"You activated a Slow Creature spell.",
|
||||
));
|
||||
resources.message_shown.slow_time = true;
|
||||
}
|
||||
|
||||
resources.slow_time_ticks = 100;
|
||||
resources.map.set_tile_at(point, TileType::Floor);
|
||||
true
|
||||
}
|
||||
crate::tile_data::TileType::Gem => {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.grab.clone());
|
||||
}
|
||||
resources.stats.give_gems(1);
|
||||
resources.stats.add_score(1);
|
||||
resources.map.set_tile_at(point, TileType::Floor);
|
||||
true
|
||||
}
|
||||
crate::tile_data::TileType::Invisible => todo!(),
|
||||
crate::tile_data::TileType::Teleport => {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.grab.clone());
|
||||
}
|
||||
resources.stats.give_teleports(1);
|
||||
resources.stats.add_score(1);
|
||||
resources.map.set_tile_at(point, TileType::Floor);
|
||||
true
|
||||
}
|
||||
crate::tile_data::TileType::Key => todo!(),
|
||||
crate::tile_data::TileType::Door => todo!(),
|
||||
crate::tile_data::TileType::SpeedTime => {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.speed_time.clone());
|
||||
}
|
||||
|
||||
if !resources.message_shown.speed_time {
|
||||
resources.flashing_message = Some(FlashingMessage::from(
|
||||
"You activated a Speed Creature spell.",
|
||||
));
|
||||
resources.message_shown.speed_time = true;
|
||||
}
|
||||
|
||||
resources.speed_time_ticks = 80;
|
||||
resources.map.set_tile_at(point, TileType::Floor);
|
||||
true
|
||||
}
|
||||
crate::tile_data::TileType::Trap => todo!(),
|
||||
crate::tile_data::TileType::River => todo!(),
|
||||
crate::tile_data::TileType::Power => todo!(),
|
||||
crate::tile_data::TileType::Forest => todo!(),
|
||||
crate::tile_data::TileType::Tree => todo!(),
|
||||
crate::tile_data::TileType::Bomb => todo!(),
|
||||
crate::tile_data::TileType::Lava => todo!(),
|
||||
crate::tile_data::TileType::Pit => todo!(),
|
||||
crate::tile_data::TileType::Tome => todo!(),
|
||||
crate::tile_data::TileType::Tunnel => todo!(),
|
||||
crate::tile_data::TileType::Freeze => todo!(),
|
||||
crate::tile_data::TileType::Nugget => todo!(),
|
||||
crate::tile_data::TileType::Quake => todo!(),
|
||||
crate::tile_data::TileType::InvisibleBlock => todo!(),
|
||||
crate::tile_data::TileType::InvisibleWall => todo!(),
|
||||
crate::tile_data::TileType::InvisibleDoor => todo!(),
|
||||
crate::tile_data::TileType::Stop => todo!(),
|
||||
crate::tile_data::TileType::Zap => todo!(),
|
||||
crate::tile_data::TileType::Create => todo!(),
|
||||
crate::tile_data::TileType::Generator => todo!(),
|
||||
crate::tile_data::TileType::Trap2 => todo!(),
|
||||
crate::tile_data::TileType::Trap3 => todo!(),
|
||||
crate::tile_data::TileType::Trap4 => todo!(),
|
||||
crate::tile_data::TileType::Trap5 => todo!(),
|
||||
crate::tile_data::TileType::Trap6 => todo!(),
|
||||
crate::tile_data::TileType::Trap7 => todo!(),
|
||||
crate::tile_data::TileType::Trap8 => todo!(),
|
||||
crate::tile_data::TileType::Trap9 => todo!(),
|
||||
crate::tile_data::TileType::Trap10 => todo!(),
|
||||
crate::tile_data::TileType::Trap11 => todo!(),
|
||||
crate::tile_data::TileType::Trap12 => todo!(),
|
||||
crate::tile_data::TileType::Trap13 => todo!(),
|
||||
crate::tile_data::TileType::Player => true,
|
||||
crate::tile_data::TileType::Punctuation => todo!(),
|
||||
crate::tile_data::TileType::Letter(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn whip(world: &mut World, resources: &mut Resources) {
|
||||
let mut to_add: Vec<Entity> = Vec::new();
|
||||
|
||||
for (entity, _) in world.query_mut::<With<Player, With<Position, Without<WantsToWhip, ()>>>>() {
|
||||
if resources.stats.whips > 0 {
|
||||
to_add.push(entity);
|
||||
}
|
||||
}
|
||||
|
||||
for e in to_add {
|
||||
let _ = world.insert_one(
|
||||
e,
|
||||
WantsToWhip {
|
||||
frame: 0,
|
||||
last_frame: Instant::now(),
|
||||
sound: {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
Some(sound_output.play_sound(sound_effects.whipping.clone()))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
},
|
||||
);
|
||||
resources.stats.whips -= 1;
|
||||
}
|
||||
}
|
||||
|
|
34
src/lib.rs
Normal file
34
src/lib.rs
Normal file
|
@ -0,0 +1,34 @@
|
|||
#![allow(clippy::unused_unit)]
|
||||
|
||||
use std::panic;
|
||||
|
||||
use bracket_lib::prelude::*;
|
||||
use state::State;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
pub mod components;
|
||||
pub mod constants;
|
||||
mod graphics;
|
||||
pub mod input;
|
||||
pub mod levels;
|
||||
pub mod resources;
|
||||
mod state;
|
||||
pub mod systems;
|
||||
pub mod tile_data;
|
||||
|
||||
#[wasm_bindgen(start)]
|
||||
pub fn main_js() -> Result<(), JsValue> {
|
||||
panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||
let _ = main_common(false);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn main_common(initialize_sound: bool) -> BError {
|
||||
let context = BTermBuilder::vga(80, 25)
|
||||
.with_fps_cap(60.0)
|
||||
.with_title("Kroz")
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
main_loop(context, State::new(initialize_sound))
|
||||
}
|
72
src/main.rs
72
src/main.rs
|
@ -2,7 +2,6 @@
|
|||
|
||||
pub mod components;
|
||||
pub mod constants;
|
||||
pub mod difficulty;
|
||||
mod graphics;
|
||||
pub mod input;
|
||||
pub mod levels;
|
||||
|
@ -12,76 +11,7 @@ pub mod systems;
|
|||
pub mod tile_data;
|
||||
|
||||
use bracket_lib::prelude::*;
|
||||
use components::{Monster, Player, Position, Renderable, WantsToWhip};
|
||||
use resources::{
|
||||
Clock, LevelNumber, Map, ShowDebugInfo, SoundEffects, SoundOutput, Stats, StopClock,
|
||||
};
|
||||
use specs::prelude::*;
|
||||
use state::State;
|
||||
use std::time::Instant;
|
||||
|
||||
fn main() -> BError {
|
||||
let context = BTermBuilder::vga(80, 25)
|
||||
.with_fps_cap(60.0)
|
||||
.with_title("Kroz")
|
||||
.build()?;
|
||||
|
||||
let mut sound_system = SoundOutput::new();
|
||||
let sound_effects = SoundEffects::new(&sound_system);
|
||||
sound_system.play_sound(sound_effects.startup.clone());
|
||||
|
||||
let mut world = World::new();
|
||||
|
||||
let starting_level = 0;
|
||||
world.insert(sound_system);
|
||||
world.insert(LevelNumber(starting_level));
|
||||
world.insert(ShowDebugInfo(false));
|
||||
world.insert(StopClock(false));
|
||||
world.insert(Clock {
|
||||
last_ticked: Instant::now(),
|
||||
has_ticked: false,
|
||||
ticks: 0,
|
||||
});
|
||||
world.insert(sound_effects);
|
||||
|
||||
let selected_difficulty = difficulty::SECRET;
|
||||
world.insert(selected_difficulty);
|
||||
world.insert(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,
|
||||
});
|
||||
|
||||
world.register::<Position>();
|
||||
world.register::<Renderable>();
|
||||
world.register::<Monster>();
|
||||
world.register::<Player>();
|
||||
world.register::<WantsToWhip>();
|
||||
|
||||
let mut map = Map::from_level(levels::get_level(starting_level));
|
||||
map.spawn_entities(&mut world);
|
||||
world.insert(map);
|
||||
|
||||
// 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))
|
||||
libkroz::main_common(true)
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use std::time::Instant;
|
||||
use instant::Instant;
|
||||
|
||||
pub struct Clock {
|
||||
pub last_ticked: Instant,
|
||||
|
|
47
src/resources/flashing_message.rs
Normal file
47
src/resources/flashing_message.rs
Normal file
|
@ -0,0 +1,47 @@
|
|||
use instant::Instant;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::constants::*;
|
||||
|
||||
pub enum FlashingMessageIntent {
|
||||
Start,
|
||||
Quit,
|
||||
Save,
|
||||
Restore,
|
||||
Restart,
|
||||
}
|
||||
|
||||
pub struct FlashingMessage {
|
||||
pub message: String,
|
||||
pub color: usize,
|
||||
pub last_changed_color: Instant,
|
||||
pub intent: Option<FlashingMessageIntent>,
|
||||
}
|
||||
|
||||
impl FlashingMessage {
|
||||
pub fn new(message: &str, intent: Option<FlashingMessageIntent>) -> Self {
|
||||
Self {
|
||||
message: message.to_string(),
|
||||
color: 14,
|
||||
last_changed_color: Instant::now(),
|
||||
intent,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn next_color(&mut self) {
|
||||
let now = Instant::now();
|
||||
if now - self.last_changed_color > Duration::from_secs_f32(FLASHING_PERIOD) {
|
||||
self.color += 1;
|
||||
if self.color > 15 {
|
||||
self.color = 13
|
||||
}
|
||||
self.last_changed_color = now;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&str> for FlashingMessage {
|
||||
fn from(message: &str) -> Self {
|
||||
Self::new(message, None)
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
use std::time::Instant;
|
||||
use instant::Instant;
|
||||
|
||||
use crate::{
|
||||
components::{monster::*, Monster, Player, Position, Renderable},
|
||||
|
@ -8,7 +8,7 @@ use crate::{
|
|||
tile_data::{self, TileType},
|
||||
};
|
||||
use bracket_lib::{prelude::*, random::RandomNumberGenerator};
|
||||
use specs::{Builder, Entity, World, WorldExt};
|
||||
use hecs::{Entity, World};
|
||||
|
||||
pub struct Map {
|
||||
tiles: Vec<TileType>,
|
||||
|
@ -44,42 +44,6 @@ impl Map {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn from_level(level: Level) -> Self {
|
||||
match level {
|
||||
Level::Normal(_data) => todo!(),
|
||||
Level::Randomized(data) => {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
let mut map = Self::new();
|
||||
for (tile, count) in data {
|
||||
for _ in 0..count {
|
||||
loop {
|
||||
let point = Point {
|
||||
x: rng.range(0, MAP_WIDTH as i32),
|
||||
y: rng.range(0, MAP_HEIGHT as i32),
|
||||
};
|
||||
if map.get_tile_at(point) == TileType::Floor {
|
||||
map.set_tile_at(point, tile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
loop {
|
||||
let point = Point {
|
||||
x: rng.range(0, MAP_WIDTH as i32),
|
||||
y: rng.range(0, MAP_HEIGHT as i32),
|
||||
};
|
||||
if map.get_tile_at(point) == TileType::Floor {
|
||||
map.set_tile_at(point, TileType::Player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
||||
Level::End => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn spawn_entities(&mut self, world: &mut World) {
|
||||
for (index, tile) in self
|
||||
.tiles
|
||||
|
@ -90,85 +54,84 @@ impl Map {
|
|||
let point = Point::new(index % MAP_WIDTH, index / MAP_WIDTH);
|
||||
match tile {
|
||||
TileType::Player => {
|
||||
let player_entity = world
|
||||
.create_entity()
|
||||
.with(Position {
|
||||
let entity = world.spawn((
|
||||
Player {
|
||||
last_moved: Instant::now(),
|
||||
},
|
||||
Position {
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
})
|
||||
.with(Renderable {
|
||||
},
|
||||
Renderable {
|
||||
glyph: to_cp437('☻'),
|
||||
fg: RGB::named(vga::YELLOW_BRIGHT),
|
||||
bg: RGB::named(vga::BLACK),
|
||||
})
|
||||
.with(Player {
|
||||
last_moved: Instant::now(),
|
||||
})
|
||||
.build();
|
||||
self.tile_content[index] = Some(player_entity);
|
||||
},
|
||||
));
|
||||
self.tile_content[index] = Some(entity);
|
||||
}
|
||||
TileType::Slow => {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
world
|
||||
.create_entity()
|
||||
.with(Position {
|
||||
let entity = world.spawn((
|
||||
Monster {
|
||||
kind: MonsterKind::Slow,
|
||||
ticks_until_move: ticks_for_kind(MonsterKind::Slow),
|
||||
},
|
||||
Position {
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
})
|
||||
.with(Renderable {
|
||||
},
|
||||
Renderable {
|
||||
glyph: *rng
|
||||
.random_slice_entry(&glyphs_for_kind(MonsterKind::Slow))
|
||||
.unwrap(),
|
||||
fg: color_for_kind(MonsterKind::Slow),
|
||||
bg: RGB::named(vga::BLACK),
|
||||
})
|
||||
.with(Monster {
|
||||
kind: MonsterKind::Slow,
|
||||
ticks_until_move: ticks_for_kind(MonsterKind::Slow),
|
||||
})
|
||||
.build();
|
||||
},
|
||||
));
|
||||
self.tile_content[index] = Some(entity);
|
||||
}
|
||||
TileType::Medium => {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
world
|
||||
.create_entity()
|
||||
.with(Position {
|
||||
let entity = world.spawn((
|
||||
Monster {
|
||||
kind: MonsterKind::Medium,
|
||||
ticks_until_move: ticks_for_kind(MonsterKind::Medium),
|
||||
},
|
||||
Position {
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
})
|
||||
.with(Renderable {
|
||||
},
|
||||
Renderable {
|
||||
glyph: *rng
|
||||
.random_slice_entry(&glyphs_for_kind(MonsterKind::Medium))
|
||||
.unwrap(),
|
||||
fg: color_for_kind(MonsterKind::Medium),
|
||||
bg: RGB::named(vga::BLACK),
|
||||
})
|
||||
.with(Monster {
|
||||
kind: MonsterKind::Medium,
|
||||
ticks_until_move: ticks_for_kind(MonsterKind::Medium),
|
||||
})
|
||||
.build();
|
||||
},
|
||||
));
|
||||
self.tile_content[index] = Some(entity);
|
||||
}
|
||||
TileType::Fast => {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
world
|
||||
.create_entity()
|
||||
.with(Position {
|
||||
let entity = world.spawn((
|
||||
Monster {
|
||||
kind: MonsterKind::Fast,
|
||||
ticks_until_move: ticks_for_kind(MonsterKind::Fast),
|
||||
},
|
||||
Position {
|
||||
x: point.x,
|
||||
y: point.y,
|
||||
})
|
||||
.with(Renderable {
|
||||
},
|
||||
Renderable {
|
||||
glyph: *rng
|
||||
.random_slice_entry(&glyphs_for_kind(MonsterKind::Fast))
|
||||
.unwrap(),
|
||||
fg: color_for_kind(MonsterKind::Fast),
|
||||
bg: RGB::named(vga::BLACK),
|
||||
})
|
||||
.with(Monster {
|
||||
kind: MonsterKind::Fast,
|
||||
ticks_until_move: ticks_for_kind(MonsterKind::Fast),
|
||||
})
|
||||
.build();
|
||||
},
|
||||
));
|
||||
self.tile_content[index] = Some(entity);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
@ -246,8 +209,59 @@ impl Map {
|
|||
let index = self.point2d_to_index(point);
|
||||
self.tiles[index] = tile;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_solid(&self, point: Point) -> bool {
|
||||
matches!(self.get_tile_at(point), TileType::Wall | TileType::Block)
|
||||
impl From<Level> for Map {
|
||||
fn from(level: Level) -> Self {
|
||||
match level {
|
||||
Level::Normal(data) => {
|
||||
assert_eq!(data.len(), MAP_HEIGHT, "Level data is incorrect height!");
|
||||
|
||||
let mut map = Self::new();
|
||||
for (y, line) in data.iter().enumerate() {
|
||||
assert_eq!(line.len(), MAP_WIDTH, "Level data is incorrect width!");
|
||||
for (x, c) in line.chars().enumerate() {
|
||||
map.set_tile_at(
|
||||
Point {
|
||||
x: x as i32,
|
||||
y: y as i32,
|
||||
},
|
||||
TileType::from(c),
|
||||
);
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
||||
Level::Randomized(data) => {
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
let mut map = Self::new();
|
||||
for (tile, count) in data {
|
||||
for _ in 0..count {
|
||||
loop {
|
||||
let point = Point {
|
||||
x: rng.range(0, MAP_WIDTH as i32),
|
||||
y: rng.range(0, MAP_HEIGHT as i32),
|
||||
};
|
||||
if map.get_tile_at(point) == TileType::Floor {
|
||||
map.set_tile_at(point, tile);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
loop {
|
||||
let point = Point {
|
||||
x: rng.range(0, MAP_WIDTH as i32),
|
||||
y: rng.range(0, MAP_HEIGHT as i32),
|
||||
};
|
||||
if map.get_tile_at(point) == TileType::Floor {
|
||||
map.set_tile_at(point, TileType::Player);
|
||||
break;
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
||||
Level::End => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
5
src/resources/message_shown.rs
Normal file
5
src/resources/message_shown.rs
Normal file
|
@ -0,0 +1,5 @@
|
|||
#[derive(Debug, Default)]
|
||||
pub struct MessageShown {
|
||||
pub slow_time: bool,
|
||||
pub speed_time: bool,
|
||||
}
|
|
@ -1,47 +1,36 @@
|
|||
pub mod clock;
|
||||
pub mod difficulty;
|
||||
pub mod flashing_message;
|
||||
pub mod map;
|
||||
pub mod message_shown;
|
||||
pub mod sound_effects;
|
||||
pub mod sound_output;
|
||||
pub mod stats;
|
||||
|
||||
use bracket_lib::prelude::*;
|
||||
pub use clock::{Clock, StopClock};
|
||||
pub use difficulty::Difficulty;
|
||||
pub use flashing_message::FlashingMessage;
|
||||
pub use map::Map;
|
||||
use message_shown::MessageShown;
|
||||
pub use sound_effects::SoundEffects;
|
||||
pub use sound_output::SoundOutput;
|
||||
pub use stats::Stats;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct LevelNumber(pub u32);
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ShowDebugInfo(pub bool);
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct PlayerInput(pub Option<VirtualKeyCode>);
|
||||
|
||||
pub struct Stats {
|
||||
pub score: u32,
|
||||
pub gems: u32,
|
||||
pub whips: u32,
|
||||
pub whip_power: u32,
|
||||
pub teleports: u32,
|
||||
pub keys: u32,
|
||||
}
|
||||
|
||||
type PlayerSurvived = bool;
|
||||
|
||||
impl Stats {
|
||||
pub fn take_gems(&mut self, num_gems: u32) -> PlayerSurvived {
|
||||
let new_num_gems = self.gems as i64 - num_gems as i64;
|
||||
if new_num_gems <= 0 {
|
||||
self.gems = 0;
|
||||
false
|
||||
} else {
|
||||
self.gems = new_num_gems as u32;
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_score(&mut self, score: u32) {
|
||||
self.score += score;
|
||||
}
|
||||
pub struct Resources {
|
||||
pub level_number: u32,
|
||||
pub show_debug_info: bool,
|
||||
pub player_input: Option<VirtualKeyCode>,
|
||||
pub stats: Stats,
|
||||
pub clock: Clock,
|
||||
pub stop_clock: bool,
|
||||
pub map: Map,
|
||||
pub selected_difficulty: Option<Difficulty>,
|
||||
pub sound_effects: Option<SoundEffects>,
|
||||
pub sound_output: Option<SoundOutput>,
|
||||
pub flashing_message: Option<FlashingMessage>,
|
||||
pub message_shown: MessageShown,
|
||||
pub should_advance_level: bool,
|
||||
pub speed_time_ticks: u32,
|
||||
pub slow_time_ticks: u32,
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ pub struct SoundEffect {
|
|||
pub struct SoundEffects {
|
||||
pub startup: SoundSamples,
|
||||
pub step: SoundSamples,
|
||||
pub pickup: SoundSamples,
|
||||
pub grab: SoundSamples,
|
||||
pub bad_key: SoundSamples,
|
||||
pub blocked: SoundSamples,
|
||||
pub whipping: SoundSamples,
|
||||
|
@ -38,6 +38,9 @@ pub struct SoundEffects {
|
|||
pub slow_hit: SoundSamples,
|
||||
pub medium_hit: SoundSamples,
|
||||
pub fast_hit: SoundSamples,
|
||||
pub pause: SoundSamples,
|
||||
pub speed_time: SoundSamples,
|
||||
pub slow_time: SoundSamples,
|
||||
rng: RandomNumberGenerator,
|
||||
}
|
||||
|
||||
|
@ -66,7 +69,7 @@ impl SoundEffects {
|
|||
},
|
||||
],
|
||||
}),
|
||||
pickup: sound_output.render_sound_effect(&SoundEffect {
|
||||
grab: sound_output.render_sound_effect(&SoundEffect {
|
||||
sounds: vec![
|
||||
Sound {
|
||||
sound_type: SoundType::Noise(350, 900),
|
||||
|
@ -153,6 +156,36 @@ impl SoundEffects {
|
|||
duration: Duration::from_millis(25),
|
||||
}],
|
||||
}),
|
||||
pause: sound_output.render_sound_effect(&SoundEffect {
|
||||
sounds: {
|
||||
let mut sounds = vec![Sound {
|
||||
sound_type: SoundType::Tone(500),
|
||||
duration: Duration::from_millis(100),
|
||||
}];
|
||||
sounds.extend((100..=200).rev().step_by(10).map(|x| Sound {
|
||||
sound_type: SoundType::Tone(x),
|
||||
duration: Duration::from_millis(20),
|
||||
}));
|
||||
sounds
|
||||
},
|
||||
}),
|
||||
speed_time: sound_output.render_sound_effect(&SoundEffect {
|
||||
sounds: (1..=7)
|
||||
.map(|x| Sound {
|
||||
sound_type: SoundType::Tone(x * 50 + 300),
|
||||
duration: Duration::from_millis(x as u64 * 10 + 40),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
slow_time: sound_output.render_sound_effect(&SoundEffect {
|
||||
sounds: (1..=7)
|
||||
.rev()
|
||||
.map(|x| Sound {
|
||||
sound_type: SoundType::Tone(x * 50 + 300),
|
||||
duration: Duration::from_millis(x as u64 * 10 + 40),
|
||||
})
|
||||
.collect(),
|
||||
}),
|
||||
rng: RandomNumberGenerator::new(),
|
||||
}
|
||||
}
|
||||
|
|
74
src/resources/stats.rs
Normal file
74
src/resources/stats.rs
Normal file
|
@ -0,0 +1,74 @@
|
|||
pub struct Stats {
|
||||
pub score: u32,
|
||||
pub gems: u32,
|
||||
pub whips: u32,
|
||||
pub whip_power: u32,
|
||||
pub teleports: u32,
|
||||
pub keys: u32,
|
||||
}
|
||||
|
||||
type PlayerSurvived = bool;
|
||||
|
||||
impl Stats {
|
||||
pub fn add_score(&mut self, score: u32) {
|
||||
self.score += score;
|
||||
}
|
||||
|
||||
pub fn take_score(&mut self, score: u32) {
|
||||
if let Some(result) = self.score.checked_sub(score) {
|
||||
self.score = result;
|
||||
} else {
|
||||
self.score = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn give_gems(&mut self, num_gems: u32) {
|
||||
self.gems += num_gems;
|
||||
}
|
||||
|
||||
pub fn take_gems(&mut self, num_gems: u32) -> PlayerSurvived {
|
||||
if let Some(result) = self.gems.checked_sub(num_gems) {
|
||||
self.gems = result;
|
||||
true
|
||||
} else {
|
||||
self.gems = 0;
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn give_whips(&mut self, num_whips: u32) {
|
||||
self.whips += num_whips;
|
||||
}
|
||||
|
||||
pub fn take_whips(&mut self, num_whips: u32) {
|
||||
if let Some(result) = self.whips.checked_sub(num_whips) {
|
||||
self.whips = result;
|
||||
} else {
|
||||
self.whips = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn give_teleports(&mut self, num_teleports: u32) {
|
||||
self.teleports += num_teleports;
|
||||
}
|
||||
|
||||
pub fn take_teleports(&mut self, num_teleports: u32) {
|
||||
if let Some(result) = self.teleports.checked_sub(num_teleports) {
|
||||
self.teleports = result;
|
||||
} else {
|
||||
self.teleports = 0;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn give_keys(&mut self, num_keys: u32) {
|
||||
self.keys += num_keys;
|
||||
}
|
||||
|
||||
pub fn take_keys(&mut self, num_keys: u32) {
|
||||
if let Some(result) = self.keys.checked_sub(num_keys) {
|
||||
self.keys = result;
|
||||
} else {
|
||||
self.keys = 0;
|
||||
}
|
||||
}
|
||||
}
|
95
src/state.rs
95
src/state.rs
|
@ -1,23 +1,100 @@
|
|||
use crate::graphics::draw;
|
||||
use crate::input::handle;
|
||||
use crate::systems::*;
|
||||
use instant::Instant;
|
||||
|
||||
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 bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
use hecs::World;
|
||||
|
||||
pub struct State {
|
||||
world: World,
|
||||
resources: Resources,
|
||||
}
|
||||
|
||||
impl GameState for State {
|
||||
fn tick(&mut self, bterm: &mut BTerm) {
|
||||
handle(&self.world, bterm);
|
||||
run_systems(&mut self.world);
|
||||
draw(&self.world, bterm);
|
||||
input::handle(&mut self.world, &mut self.resources, bterm);
|
||||
systems::run(&mut self.world, &mut self.resources);
|
||||
graphics::draw(&self.world, &mut self.resources, bterm);
|
||||
|
||||
if self.resources.should_advance_level {
|
||||
self.next_level();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
pub fn new(world: World) -> Self {
|
||||
State { world }
|
||||
#[allow(dead_code)]
|
||||
pub fn new(initialize_sound: bool) -> Self {
|
||||
let mut sound_output = if initialize_sound {
|
||||
Some(SoundOutput::new())
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
let sound_effects = sound_output.as_ref().map(SoundEffects::new);
|
||||
|
||||
if let (Some(so), Some(se)) = (&mut sound_output, &sound_effects) {
|
||||
so.play_sound(se.startup.clone());
|
||||
}
|
||||
|
||||
let starting_level = 0;
|
||||
let selected_difficulty = 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),
|
||||
)),
|
||||
message_shown: Default::default(),
|
||||
should_advance_level: false,
|
||||
speed_time_ticks: 0,
|
||||
slow_time_ticks: 0,
|
||||
};
|
||||
|
||||
State { world, resources }
|
||||
}
|
||||
|
||||
fn next_level(&mut self) {
|
||||
self.resources.level_number += 1;
|
||||
|
||||
self.world.clear();
|
||||
self.resources.map = Map::from(levels::get_level(self.resources.level_number));
|
||||
self.resources.map.spawn_entities(&mut self.world);
|
||||
|
||||
self.resources.flashing_message =
|
||||
Some(FlashingMessage::from("Press any key to begin this level."));
|
||||
|
||||
self.resources.should_advance_level = false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +1,15 @@
|
|||
pub mod monster_ai_system;
|
||||
pub mod time_system;
|
||||
pub mod whip_system;
|
||||
pub mod monster_ai;
|
||||
pub mod powerups;
|
||||
pub mod time;
|
||||
pub mod whip;
|
||||
|
||||
pub use monster_ai_system::MonsterAiSystem;
|
||||
use specs::prelude::*;
|
||||
pub use time_system::TimeSystem;
|
||||
pub use whip_system::WhipSystem;
|
||||
use hecs::World;
|
||||
|
||||
pub fn run_systems(world: &mut World) {
|
||||
let mut whip_system = WhipSystem {};
|
||||
whip_system.run_now(world);
|
||||
use crate::resources::Resources;
|
||||
|
||||
let mut monster_ai_system = MonsterAiSystem {};
|
||||
monster_ai_system.run_now(world);
|
||||
|
||||
let mut time_system = TimeSystem {};
|
||||
time_system.run_now(world);
|
||||
|
||||
world.maintain();
|
||||
pub fn run(world: &mut World, resources: &mut Resources) {
|
||||
powerups::run(resources);
|
||||
whip::run(world, resources);
|
||||
monster_ai::run(world, resources);
|
||||
time::run(resources);
|
||||
}
|
||||
|
|
109
src/systems/monster_ai.rs
Normal file
109
src/systems/monster_ai.rs
Normal file
|
@ -0,0 +1,109 @@
|
|||
use crate::{
|
||||
components::{monster::*, *},
|
||||
resources::Resources,
|
||||
tile_data::TileType,
|
||||
};
|
||||
|
||||
use bracket_lib::{prelude::*, random::RandomNumberGenerator};
|
||||
use hecs::*;
|
||||
|
||||
pub fn run(world: &mut World, resources: &mut Resources) {
|
||||
let player_position = world
|
||||
.query::<(&Player, &Position)>()
|
||||
.iter()
|
||||
.map(|(_, (_, &pos))| pos)
|
||||
.collect::<Vec<_>>()
|
||||
.first()
|
||||
.cloned();
|
||||
|
||||
if let Some(player_pos) = player_position {
|
||||
let mut to_kill: Vec<Entity> = Vec::new();
|
||||
for (entity, (monster, position, renderable)) in
|
||||
&mut world.query::<(&mut Monster, &mut Position, &mut Renderable)>()
|
||||
{
|
||||
if resources.clock.has_ticked {
|
||||
monster.ticks_until_move -= 1;
|
||||
if monster.ticks_until_move <= 0 {
|
||||
// Change glyph
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
if let Some(glyph) =
|
||||
rng.random_slice_entry(&monster::glyphs_for_kind(monster.kind))
|
||||
{
|
||||
renderable.glyph = *glyph;
|
||||
}
|
||||
|
||||
// Move monster
|
||||
let (mut delta_x, mut delta_y) = (0, 0);
|
||||
if player_pos.x < position.x {
|
||||
delta_x = -1;
|
||||
}
|
||||
if player_pos.x > position.x {
|
||||
delta_x = 1;
|
||||
}
|
||||
if player_pos.y < position.y {
|
||||
delta_y = -1;
|
||||
}
|
||||
if player_pos.y > position.y {
|
||||
delta_y = 1;
|
||||
}
|
||||
let destination = Point {
|
||||
x: position.x + delta_x,
|
||||
y: position.y + delta_y,
|
||||
};
|
||||
|
||||
if let Some(e) = resources.map.get_tile_content_at(destination) {
|
||||
if let Ok(_player) = world.get::<Player>(e) {
|
||||
// TODO: Sound
|
||||
resources.map.clear_tile_content_at(Point::from(*position));
|
||||
resources.stats.take_gems(damage_for_kind(monster.kind));
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output
|
||||
.play_sound(sound_effect_for_kind(monster.kind, sound_effects));
|
||||
}
|
||||
to_kill.push(entity);
|
||||
}
|
||||
} else {
|
||||
let tile = resources.map.get_tile_at_mut(destination);
|
||||
match tile {
|
||||
TileType::Wall => {}
|
||||
TileType::Block => {
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effect_for_kind(
|
||||
monster.kind,
|
||||
sound_effects,
|
||||
));
|
||||
}
|
||||
resources.stats.add_score(1);
|
||||
*tile = TileType::Floor;
|
||||
to_kill.push(entity);
|
||||
resources.map.clear_tile_content_at(Point::from(*position));
|
||||
}
|
||||
_ => {
|
||||
resources.map.clear_tile_content_at(Point::from(*position));
|
||||
position.x = destination.x;
|
||||
position.y = destination.y;
|
||||
resources.map.set_tile_content_at(destination, entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if resources.speed_time_ticks > 0 {
|
||||
monster.ticks_until_move = 3;
|
||||
} else if resources.slow_time_ticks > 0 {
|
||||
monster.ticks_until_move = ticks_for_kind(monster.kind) * 5;
|
||||
} else {
|
||||
monster.ticks_until_move = ticks_for_kind(monster.kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for e in to_kill {
|
||||
let _ = world.despawn(e);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,120 +0,0 @@
|
|||
use crate::{
|
||||
components::{
|
||||
monster::{self, damage_for_kind, sound_effect_for_kind, ticks_for_kind},
|
||||
Monster, Player, Position, Renderable,
|
||||
},
|
||||
resources::{Clock, Map, SoundEffects, SoundOutput, Stats},
|
||||
tile_data::TileType,
|
||||
};
|
||||
use bracket_lib::{prelude::*, random::RandomNumberGenerator};
|
||||
use specs::prelude::*;
|
||||
|
||||
pub struct MonsterAiSystem {}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
impl<'a> System<'a> for MonsterAiSystem {
|
||||
type SystemData = (
|
||||
Entities<'a>,
|
||||
ReadExpect<'a, Clock>,
|
||||
WriteExpect<'a, Map>,
|
||||
WriteExpect<'a, Stats>,
|
||||
ReadExpect<'a, SoundEffects>,
|
||||
WriteExpect<'a, SoundOutput>,
|
||||
WriteStorage<'a, Monster>,
|
||||
WriteStorage<'a, Position>,
|
||||
WriteStorage<'a, Renderable>,
|
||||
ReadStorage<'a, Player>,
|
||||
);
|
||||
|
||||
fn run(
|
||||
&mut self,
|
||||
(
|
||||
entities,
|
||||
clock,
|
||||
mut map,
|
||||
mut stats,
|
||||
sound_effects,
|
||||
mut sound_output,
|
||||
mut monsters,
|
||||
mut positions,
|
||||
mut renderables,
|
||||
players,
|
||||
): Self::SystemData,
|
||||
) {
|
||||
let mut player_position = None;
|
||||
for (_entity, _player, position) in (&entities, &players, &positions).join() {
|
||||
player_position = Some(Point::from(*position));
|
||||
}
|
||||
|
||||
if let Some(player_pos) = player_position {
|
||||
let mut data = (&entities, &mut monsters, &mut positions, &mut renderables)
|
||||
.join()
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for (entity, monster, position, renderable) in &mut data {
|
||||
if clock.has_ticked {
|
||||
monster.ticks_until_move -= 1;
|
||||
if monster.ticks_until_move <= 0 {
|
||||
// Change glyph
|
||||
let mut rng = RandomNumberGenerator::new();
|
||||
if let Some(glyph) =
|
||||
rng.random_slice_entry(&monster::glyphs_for_kind(monster.kind))
|
||||
{
|
||||
renderable.glyph = *glyph;
|
||||
}
|
||||
|
||||
// Move monster
|
||||
let (mut delta_x, mut delta_y) = (0, 0);
|
||||
if player_pos.x < position.x {
|
||||
delta_x = -1;
|
||||
}
|
||||
if player_pos.x > position.x {
|
||||
delta_x = 1;
|
||||
}
|
||||
if player_pos.y < position.y {
|
||||
delta_y = -1;
|
||||
}
|
||||
if player_pos.y > position.y {
|
||||
delta_y = 1;
|
||||
}
|
||||
let destination = Point {
|
||||
x: position.x + delta_x,
|
||||
y: position.y + delta_y,
|
||||
};
|
||||
|
||||
if let Some(e) = map.get_tile_content_at(destination) {
|
||||
if let Some(_player) = players.get(e) {
|
||||
// TODO: Sound
|
||||
map.clear_tile_content_at(Point::from(**position));
|
||||
stats.take_gems(damage_for_kind(monster.kind));
|
||||
sound_output.play_sound(sound_effect_for_kind(
|
||||
monster.kind,
|
||||
&sound_effects,
|
||||
));
|
||||
let _ = entities.delete(*entity);
|
||||
}
|
||||
} else {
|
||||
let tile = map.get_tile_at_mut(destination);
|
||||
match tile {
|
||||
TileType::Wall => {}
|
||||
TileType::Block => {
|
||||
// TODO: Sound
|
||||
*tile = TileType::Floor;
|
||||
let _ = entities.delete(*entity);
|
||||
}
|
||||
_ => {
|
||||
map.clear_tile_content_at(Point::from(**position));
|
||||
position.x = destination.x;
|
||||
position.y = destination.y;
|
||||
map.set_tile_content_at(destination, *entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
monster.ticks_until_move = ticks_for_kind(monster.kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
12
src/systems/powerups.rs
Normal file
12
src/systems/powerups.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use crate::resources::Resources;
|
||||
|
||||
pub fn run(resources: &mut Resources) {
|
||||
if resources.clock.has_ticked {
|
||||
if let Some(t) = resources.speed_time_ticks.checked_sub(1) {
|
||||
resources.speed_time_ticks = t;
|
||||
}
|
||||
if let Some(t) = resources.slow_time_ticks.checked_sub(1) {
|
||||
resources.slow_time_ticks = t;
|
||||
}
|
||||
}
|
||||
}
|
37
src/systems/time.rs
Normal file
37
src/systems/time.rs
Normal file
|
@ -0,0 +1,37 @@
|
|||
use instant::Instant;
|
||||
use std::time::Duration;
|
||||
|
||||
use crate::constants::CLOCK_PERIOD;
|
||||
|
||||
use crate::resources::{Clock, Resources};
|
||||
|
||||
pub fn run(resources: &mut Resources) {
|
||||
if !resources.stop_clock && resources.flashing_message.is_none() {
|
||||
try_tick(&mut resources.clock);
|
||||
} else {
|
||||
reset(&mut resources.clock);
|
||||
}
|
||||
}
|
||||
|
||||
fn try_tick(clock: &mut Clock) {
|
||||
if Instant::now() - clock.last_ticked > Duration::from_secs_f32(CLOCK_PERIOD) {
|
||||
tick(clock);
|
||||
} else {
|
||||
clock.has_ticked = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn force_tick(clock: &mut Clock) {
|
||||
tick(clock);
|
||||
}
|
||||
|
||||
fn tick(clock: &mut Clock) {
|
||||
clock.has_ticked = true;
|
||||
clock.last_ticked = Instant::now();
|
||||
clock.ticks += 1;
|
||||
}
|
||||
|
||||
fn reset(clock: &mut Clock) {
|
||||
clock.last_ticked = Instant::now();
|
||||
clock.has_ticked = false;
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
use crate::constants::CLOCK_PERIOD;
|
||||
use specs::prelude::*;
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use crate::resources::{Clock, StopClock};
|
||||
|
||||
pub struct TimeSystem {}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
impl<'a> System<'a> for TimeSystem {
|
||||
type SystemData = (WriteExpect<'a, Clock>, ReadExpect<'a, StopClock>);
|
||||
|
||||
fn run(&mut self, (mut clock, stop_clock): Self::SystemData) {
|
||||
if !stop_clock.0 {
|
||||
Self::try_tick(&mut clock);
|
||||
} else {
|
||||
Self::reset(&mut clock);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TimeSystem {
|
||||
pub fn try_tick(clock: &mut Clock) {
|
||||
if Instant::now() - clock.last_ticked > Duration::from_secs_f32(CLOCK_PERIOD) {
|
||||
Self::tick(clock);
|
||||
} else {
|
||||
clock.has_ticked = false;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn force_tick(clock: &mut Clock) {
|
||||
Self::tick(clock);
|
||||
}
|
||||
|
||||
fn tick(clock: &mut Clock) {
|
||||
clock.has_ticked = true;
|
||||
clock.last_ticked = Instant::now();
|
||||
clock.ticks += 1;
|
||||
}
|
||||
|
||||
pub fn reset(clock: &mut Clock) {
|
||||
clock.last_ticked = Instant::now();
|
||||
clock.has_ticked = false;
|
||||
}
|
||||
}
|
117
src/systems/whip.rs
Normal file
117
src/systems/whip.rs
Normal file
|
@ -0,0 +1,117 @@
|
|||
use instant::Instant;
|
||||
use std::time::Duration;
|
||||
|
||||
use bracket_lib::prelude::*;
|
||||
use hecs::{Entity, World};
|
||||
|
||||
use crate::{
|
||||
components::{monster::damage_for_kind, Monster, Position, WantsToWhip},
|
||||
resources::Resources,
|
||||
};
|
||||
|
||||
pub fn run(world: &mut World, resources: &mut Resources) {
|
||||
let mut to_kill: Vec<Entity> = Vec::new();
|
||||
let mut to_remove: Vec<Entity> = Vec::new();
|
||||
|
||||
for (entity, (position, mut wants_to_whip)) in
|
||||
&mut world.query::<(&Position, &mut WantsToWhip)>()
|
||||
{
|
||||
resources.stop_clock = true;
|
||||
let now = Instant::now();
|
||||
if now - wants_to_whip.last_frame > Duration::from_secs_f32(0.1) {
|
||||
let destination = loop {
|
||||
let destination = match wants_to_whip.frame {
|
||||
0 => Some(Point {
|
||||
x: position.x - 1,
|
||||
y: position.y - 1,
|
||||
}),
|
||||
1 => Some(Point {
|
||||
x: position.x - 1,
|
||||
y: position.y,
|
||||
}),
|
||||
2 => Some(Point {
|
||||
x: position.x - 1,
|
||||
y: position.y + 1,
|
||||
}),
|
||||
3 => Some(Point {
|
||||
x: position.x,
|
||||
y: position.y + 1,
|
||||
}),
|
||||
4 => Some(Point {
|
||||
x: position.x + 1,
|
||||
y: position.y + 1,
|
||||
}),
|
||||
5 => Some(Point {
|
||||
x: position.x + 1,
|
||||
y: position.y,
|
||||
}),
|
||||
6 => Some(Point {
|
||||
x: position.x + 1,
|
||||
y: position.y - 1,
|
||||
}),
|
||||
7 => Some(Point {
|
||||
x: position.x,
|
||||
y: position.y - 1,
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(dest) = destination {
|
||||
if resources.map.in_bounds(dest) {
|
||||
break destination;
|
||||
}
|
||||
wants_to_whip.frame += 1;
|
||||
if wants_to_whip.frame > 7 {
|
||||
break None;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(dest) = destination {
|
||||
if let Some(e) = resources.map.get_tile_content_at(dest) {
|
||||
if let Ok(monster) = world.get::<Monster>(e) {
|
||||
resources.stats.add_score(damage_for_kind(monster.kind));
|
||||
to_kill.push(e);
|
||||
resources.map.clear_tile_content_at(dest);
|
||||
if let Some(sound) = &mut wants_to_whip.sound {
|
||||
sound.control::<oddio::Stop<_>, _>().stop();
|
||||
}
|
||||
if wants_to_whip.frame == 7 {
|
||||
wants_to_whip.sound = None;
|
||||
if let (Some(sound_effects), Some(sound_output)) =
|
||||
(&mut resources.sound_effects, &mut resources.sound_output)
|
||||
{
|
||||
sound_output.play_sound(sound_effects.whipping_hit_end.clone());
|
||||
}
|
||||
} else 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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if wants_to_whip.frame < 7 {
|
||||
wants_to_whip.frame += 1;
|
||||
wants_to_whip.last_frame = now;
|
||||
} else {
|
||||
to_remove.push(entity);
|
||||
resources.stop_clock = false;
|
||||
if let Some(sound) = &mut wants_to_whip.sound {
|
||||
sound.control::<oddio::Stop<_>, _>().stop();
|
||||
wants_to_whip.sound = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for e in to_kill {
|
||||
let _ = world.despawn(e);
|
||||
}
|
||||
|
||||
for e in to_remove {
|
||||
let _ = world.remove_one::<WantsToWhip>(e);
|
||||
}
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
use std::time::{Duration, Instant};
|
||||
|
||||
use bracket_lib::prelude::*;
|
||||
use specs::prelude::*;
|
||||
|
||||
use crate::{
|
||||
components::{monster::damage_for_kind, Monster, Position, WantsToWhip},
|
||||
resources::{Map, SoundEffects, SoundOutput, Stats, StopClock},
|
||||
};
|
||||
|
||||
pub struct WhipSystem {}
|
||||
|
||||
#[allow(clippy::type_complexity)]
|
||||
impl<'a> System<'a> for WhipSystem {
|
||||
type SystemData = (
|
||||
WriteExpect<'a, Map>,
|
||||
WriteExpect<'a, StopClock>,
|
||||
WriteExpect<'a, SoundOutput>,
|
||||
ReadExpect<'a, SoundEffects>,
|
||||
WriteExpect<'a, Stats>,
|
||||
ReadStorage<'a, Position>,
|
||||
WriteStorage<'a, WantsToWhip>,
|
||||
WriteStorage<'a, Monster>,
|
||||
Entities<'a>,
|
||||
);
|
||||
|
||||
fn run(&mut self, data: Self::SystemData) {
|
||||
let (
|
||||
mut map,
|
||||
mut stop_clock,
|
||||
mut sound_output,
|
||||
sound_effects,
|
||||
mut stats,
|
||||
positions,
|
||||
mut wants_to_whips,
|
||||
monsters,
|
||||
entities,
|
||||
) = data;
|
||||
|
||||
let mut entities_to_remove: Vec<Entity> = vec![];
|
||||
|
||||
for (entity, position, mut wants_to_whip) in
|
||||
(&entities, &positions, &mut wants_to_whips).join()
|
||||
{
|
||||
stop_clock.0 = true;
|
||||
let now = Instant::now();
|
||||
if now - wants_to_whip.last_frame > Duration::from_secs_f32(0.1) {
|
||||
let destination = loop {
|
||||
let destination = match wants_to_whip.frame {
|
||||
0 => Some(Point {
|
||||
x: position.x - 1,
|
||||
y: position.y - 1,
|
||||
}),
|
||||
1 => Some(Point {
|
||||
x: position.x - 1,
|
||||
y: position.y,
|
||||
}),
|
||||
2 => Some(Point {
|
||||
x: position.x - 1,
|
||||
y: position.y + 1,
|
||||
}),
|
||||
3 => Some(Point {
|
||||
x: position.x,
|
||||
y: position.y + 1,
|
||||
}),
|
||||
4 => Some(Point {
|
||||
x: position.x + 1,
|
||||
y: position.y + 1,
|
||||
}),
|
||||
5 => Some(Point {
|
||||
x: position.x + 1,
|
||||
y: position.y,
|
||||
}),
|
||||
6 => Some(Point {
|
||||
x: position.x + 1,
|
||||
y: position.y - 1,
|
||||
}),
|
||||
7 => Some(Point {
|
||||
x: position.x,
|
||||
y: position.y - 1,
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
if let Some(dest) = destination {
|
||||
if map.in_bounds(dest) {
|
||||
break destination;
|
||||
}
|
||||
wants_to_whip.frame += 1;
|
||||
if wants_to_whip.frame > 7 {
|
||||
break None;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if let Some(dest) = destination {
|
||||
if let Some(e) = map.get_tile_content_at(dest) {
|
||||
if let Some(monster) = monsters.get(e) {
|
||||
stats.add_score(damage_for_kind(monster.kind));
|
||||
let _ = entities.delete(e);
|
||||
map.clear_tile_content_at(dest);
|
||||
if let Some(sound) = &mut wants_to_whip.sound {
|
||||
sound.control::<oddio::Stop<_>, _>().stop();
|
||||
}
|
||||
if wants_to_whip.frame == 7 {
|
||||
wants_to_whip.sound = None;
|
||||
sound_output.play_sound(sound_effects.whipping_hit_end.clone());
|
||||
} else {
|
||||
wants_to_whip.sound = Some(
|
||||
sound_output.play_sound(sound_effects.whipping_hit.clone()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if wants_to_whip.frame < 7 {
|
||||
wants_to_whip.frame += 1;
|
||||
wants_to_whip.last_frame = now;
|
||||
} else {
|
||||
entities_to_remove.push(entity);
|
||||
stop_clock.0 = false;
|
||||
if let Some(sound) = &mut wants_to_whip.sound {
|
||||
sound.control::<oddio::Stop<_>, _>().stop();
|
||||
wants_to_whip.sound = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for entity in entities_to_remove {
|
||||
wants_to_whips.remove(entity);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -375,3 +375,61 @@ pub fn tile_data(tile: TileType) -> TileData {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
impl From<char> for TileType {
|
||||
fn from(c: char) -> Self {
|
||||
match c {
|
||||
' ' => TileType::Floor,
|
||||
'1' => TileType::Slow,
|
||||
'2' => TileType::Medium,
|
||||
'3' => TileType::Fast,
|
||||
'X' => TileType::Block,
|
||||
'W' => TileType::Whip,
|
||||
'L' => TileType::Stairs,
|
||||
'C' => TileType::Chest,
|
||||
'S' => TileType::SlowTime,
|
||||
'+' => TileType::Gem,
|
||||
'I' => TileType::Invisible,
|
||||
'T' => TileType::Teleport,
|
||||
'K' => TileType::Key,
|
||||
'D' => TileType::Door,
|
||||
'#' => TileType::Wall,
|
||||
'F' => TileType::SpeedTime,
|
||||
'.' => TileType::Trap,
|
||||
'R' => TileType::River,
|
||||
'Q' => TileType::Power,
|
||||
'/' => TileType::Forest,
|
||||
'\\' => TileType::Tree,
|
||||
'B' => TileType::Bomb,
|
||||
'V' => TileType::Lava,
|
||||
'=' => TileType::Pit,
|
||||
'A' => TileType::Tome,
|
||||
'U' => TileType::Tunnel,
|
||||
'Z' => TileType::Freeze,
|
||||
'*' => TileType::Nugget,
|
||||
'E' => TileType::Quake,
|
||||
';' => TileType::InvisibleBlock,
|
||||
':' => TileType::InvisibleWall,
|
||||
'`' => TileType::InvisibleDoor,
|
||||
'-' => TileType::Stop,
|
||||
'%' => TileType::Zap,
|
||||
']' => TileType::Create,
|
||||
'G' => TileType::Generator,
|
||||
'@' => TileType::Trap2,
|
||||
')' => TileType::Trap3,
|
||||
'(' => TileType::Trap4,
|
||||
'$' => TileType::Trap5,
|
||||
'α' => TileType::Trap6,
|
||||
'ß' => TileType::Trap7,
|
||||
'Γ' => TileType::Trap8,
|
||||
'π' => TileType::Trap9,
|
||||
'Σ' => TileType::Trap10,
|
||||
'σ' => TileType::Trap11,
|
||||
'µ' => TileType::Trap12,
|
||||
'τ' => TileType::Trap13,
|
||||
'P' => TileType::Player,
|
||||
'!' => TileType::Punctuation,
|
||||
_ => TileType::Letter(c),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
BIN
static/icon.png
Normal file
BIN
static/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.9 KiB |
36
static/index.html
Normal file
36
static/index.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Kroz</title>
|
||||
<link rel="icon" type="image/png" href="icon.png" />
|
||||
<style>
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
body,
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#canvas {
|
||||
width: 100vw;
|
||||
height: 56.25vw;
|
||||
max-height: 100vh;
|
||||
max-width: 177.78vh;
|
||||
margin: auto;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<canvas id="canvas"></canvas>
|
||||
<script src="index.js"></script>
|
||||
</body>
|
||||
</html>
|
28
webpack.config.js
Normal file
28
webpack.config.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
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"
|
||||
},
|
||||
devServer: {
|
||||
contentBase: dist,
|
||||
},
|
||||
plugins: [
|
||||
new CopyPlugin([
|
||||
path.resolve(__dirname, "static")
|
||||
]),
|
||||
|
||||
new WasmPackPlugin({
|
||||
crateDirectory: __dirname,
|
||||
}),
|
||||
]
|
||||
};
|
Loading…
Add table
Reference in a new issue