Compare commits
51
Commits
c9d43770b8
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
afdea8d093 | ||
|
|
f042ee50a3 | ||
|
|
effd08e05d | ||
|
|
bf9ef34bf8 | ||
|
|
504c8f2191 | ||
|
|
6480ea585a | ||
|
|
1946458807 | ||
|
|
c043487079 | ||
|
|
d8799c1f58 | ||
|
|
9ed562735e | ||
|
|
8d24093585 | ||
|
|
a31e1c3b98 | ||
|
|
c27897802a | ||
|
|
5feca5194d | ||
|
|
b80b4e1aab | ||
|
|
e41720c6ee | ||
|
|
1a4fd9b8ba | ||
|
|
d6e4c06d7e | ||
|
|
92f83c1c4e | ||
|
|
fb45de8223 | ||
|
|
f911cd3300 | ||
|
|
56d90253bd | ||
|
|
6143cac61d | ||
|
|
112540ef50 | ||
|
|
54db9d7986 | ||
|
|
c39993fc01 | ||
|
|
1a850787c7 | ||
|
|
33cbdb5443 | ||
|
|
c0ed583d5a | ||
|
|
90ef45ab47 | ||
|
|
832d4ba847 | ||
|
|
452d39dd45 | ||
|
|
3910eb4261 | ||
|
|
05616061ed | ||
|
|
f2f3e5c76c | ||
|
|
7234a3d664 | ||
|
|
9127d9bb1c | ||
|
|
d42f5af75f | ||
|
|
9df830bf18 | ||
|
|
87c39820d7 | ||
|
|
8d496eee73 | ||
|
|
26448cd0a0 | ||
|
|
62c06161e7 | ||
|
|
9ab3431c63 | ||
|
|
5c9cba9ad4 | ||
|
|
7f905e5546 | ||
|
|
11ae27cefe | ||
|
|
5d422ecef0 | ||
|
|
0e5c2407ed | ||
|
|
fe88997cd1 | ||
|
|
582f9ed226 |
Generated
+481
-11
@@ -200,9 +200,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0348a1c054491f4bfe6ab86a7b6ab1e44e45d899005de92f58b3df180b36ddaf"
|
||||
dependencies = [
|
||||
"clipboard-win",
|
||||
"image",
|
||||
"log",
|
||||
"objc2 0.6.4",
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-core-foundation",
|
||||
"objc2-core-graphics",
|
||||
"objc2-foundation 0.3.2",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
@@ -758,6 +761,54 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_egui"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e99e2d018c7e567a268638d3058e57895e914e5650dcf7bd80a5fead9e6413a9"
|
||||
dependencies = [
|
||||
"arboard",
|
||||
"bevy_app",
|
||||
"bevy_asset",
|
||||
"bevy_camera",
|
||||
"bevy_color",
|
||||
"bevy_core_pipeline",
|
||||
"bevy_derive",
|
||||
"bevy_ecs",
|
||||
"bevy_image",
|
||||
"bevy_input",
|
||||
"bevy_log",
|
||||
"bevy_math",
|
||||
"bevy_mesh",
|
||||
"bevy_picking",
|
||||
"bevy_platform",
|
||||
"bevy_reflect",
|
||||
"bevy_render",
|
||||
"bevy_shader",
|
||||
"bevy_time",
|
||||
"bevy_transform",
|
||||
"bevy_ui_render",
|
||||
"bevy_utils",
|
||||
"bevy_window",
|
||||
"bevy_winit",
|
||||
"bytemuck",
|
||||
"crossbeam-channel",
|
||||
"egui",
|
||||
"encase",
|
||||
"getrandom 0.4.3",
|
||||
"image",
|
||||
"itertools 0.14.0",
|
||||
"js-sys",
|
||||
"smithay-clipboard",
|
||||
"thread_local",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"webbrowser",
|
||||
"wgpu-types",
|
||||
"winit",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_encase_derive"
|
||||
version = "0.19.1"
|
||||
@@ -905,7 +956,7 @@ dependencies = [
|
||||
"bevy_world_serialization",
|
||||
"fixedbitset",
|
||||
"gltf",
|
||||
"itertools",
|
||||
"itertools 0.14.0",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -932,7 +983,7 @@ dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"bytemuck",
|
||||
"futures-lite",
|
||||
"guillotiere",
|
||||
"guillotiere 0.6.2",
|
||||
"half",
|
||||
"image",
|
||||
"ktx2",
|
||||
@@ -1138,7 +1189,7 @@ dependencies = [
|
||||
"bevy_reflect",
|
||||
"derive_more",
|
||||
"glam",
|
||||
"itertools",
|
||||
"itertools 0.14.0",
|
||||
"libm",
|
||||
"rand",
|
||||
"rand_distr",
|
||||
@@ -1382,7 +1433,7 @@ dependencies = [
|
||||
"glam",
|
||||
"image",
|
||||
"indexmap",
|
||||
"itertools",
|
||||
"itertools 0.14.0",
|
||||
"js-sys",
|
||||
"naga",
|
||||
"nonmax",
|
||||
@@ -1944,18 +1995,43 @@ dependencies = [
|
||||
"thiserror 1.0.69",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop"
|
||||
version = "0.14.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dbf9978365bac10f54d1d4b04f7ce4427e51f71d61f2fe15e3fed5166474df7"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"polling",
|
||||
"rustix 1.1.4",
|
||||
"slab",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20"
|
||||
dependencies = [
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"rustix 0.38.44",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "calloop-wayland-source"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "138efcf0940a02ebf0cc8d1eff41a1682a46b431630f4c52450d6265876021fa"
|
||||
dependencies = [
|
||||
"calloop 0.14.4",
|
||||
"rustix 1.1.4",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cc"
|
||||
version = "1.4.6"
|
||||
@@ -2028,6 +2104,15 @@ dependencies = [
|
||||
"unicode-width",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "color"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ec7c5eb7a16992b1904d76c517d170ab353b0e0b3d5a0c81a8a0cd1037893cf"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "4.6.8"
|
||||
@@ -2360,6 +2445,8 @@ name = "down_into_the_void"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_egui",
|
||||
"fastnoise-lite",
|
||||
"rand",
|
||||
]
|
||||
|
||||
@@ -2381,12 +2468,51 @@ version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
|
||||
|
||||
[[package]]
|
||||
name = "ecolor"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0656a7530b9e2841ee7a5f983965bdd9840c32f4012f759cfd44b912cced6b34"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"emath",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "egui"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc938cc27cd911415e1e4d151bc56ff9df063d8db081374e87aeb805ea74b2ba"
|
||||
dependencies = [
|
||||
"accesskit",
|
||||
"ahash",
|
||||
"bitflags 2.13.2",
|
||||
"emath",
|
||||
"epaint",
|
||||
"itertools 0.15.0",
|
||||
"log",
|
||||
"nohash-hasher",
|
||||
"profiling",
|
||||
"smallvec",
|
||||
"unicode-segmentation",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "252afb9ae5eaa683babdc6a068b3f5726eb19e05070c731f9b2a23a7c3e8ed34"
|
||||
|
||||
[[package]]
|
||||
name = "emath"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "52c8d4141cf0f60fb2f7aefaf352d3ffa5171ef0ab09731c64391801e95e48f1"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "encase"
|
||||
version = "0.12.1"
|
||||
@@ -2418,6 +2544,37 @@ dependencies = [
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "epaint"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a0ec0308dc23130fc1a7d4623a8534c2ed069c6dc84e258ee4f3de99615aa1a3"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"bytemuck",
|
||||
"ecolor",
|
||||
"emath",
|
||||
"epaint_default_fonts",
|
||||
"font-types 0.12.5",
|
||||
"harfrust 0.12.0",
|
||||
"log",
|
||||
"nohash-hasher",
|
||||
"parking_lot",
|
||||
"profiling",
|
||||
"self_cell",
|
||||
"skrifa 0.44.0",
|
||||
"smallvec",
|
||||
"unicode-general-category",
|
||||
"unicode-segmentation",
|
||||
"vello_cpu",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "epaint_default_fonts"
|
||||
version = "0.36.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "773fa9c96dd0dbef887e39d0ed6177f141cce4d68e6041df77570aa3702dfa13"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.2"
|
||||
@@ -2480,12 +2637,27 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastnoise-lite"
|
||||
version = "1.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e5f3c3cc9081e5d0e18bcd50e80cd33cba47fc22f88a9da9c33ecd1c87ea5c0"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223"
|
||||
|
||||
[[package]]
|
||||
name = "fax"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "caf1079563223d5d59d83c85886a56e586cfd5c1a26292e971a0fa266531ac5a"
|
||||
|
||||
[[package]]
|
||||
name = "fdeflate"
|
||||
version = "0.3.7"
|
||||
@@ -2495,6 +2667,12 @@ dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fearless_simd"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b97b65636e5b9ef369943878ac74335ba1c55c1cb6adbf1e2c293c624248d693"
|
||||
|
||||
[[package]]
|
||||
name = "find-msvc-tools"
|
||||
version = "0.1.12"
|
||||
@@ -2595,6 +2773,15 @@ version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
|
||||
|
||||
[[package]]
|
||||
name = "form_urlencoded"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"
|
||||
dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "futures-channel"
|
||||
version = "0.3.34"
|
||||
@@ -2688,9 +2875,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"libc",
|
||||
"r-efi 6.0.0",
|
||||
"rand_core",
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -2751,6 +2940,22 @@ dependencies = [
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glifo"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed4a1bb24121291d27230c1b1b44e07d6a9b28cefdb32fe1581dfb84e14f940a"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"foldhash 0.2.0",
|
||||
"hashbrown 0.17.1",
|
||||
"log",
|
||||
"peniko",
|
||||
"skrifa 0.44.0",
|
||||
"smallvec",
|
||||
"vello_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glow"
|
||||
version = "0.17.0"
|
||||
@@ -2858,6 +3063,15 @@ dependencies = [
|
||||
"svg_fmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "guillotiere"
|
||||
version = "0.7.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6b17e70c989c36bad147b27a58d148c0741c51448aa5653436547323e524d0ab"
|
||||
dependencies = [
|
||||
"euclid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "2.7.1"
|
||||
@@ -2884,6 +3098,18 @@ dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "harfrust"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c03d949a14aa089bbb282f7dd76a498a7f684428e4257202efc119ec010376f9"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"bytemuck",
|
||||
"read-fonts 0.41.0",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash32"
|
||||
version = "0.3.1"
|
||||
@@ -3086,6 +3312,27 @@ version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae293c039020f9ec10710af98d29ce6aa2051486638b49c9a6409f3b4a9e98ad"
|
||||
|
||||
[[package]]
|
||||
name = "idna"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de"
|
||||
dependencies = [
|
||||
"idna_adapter",
|
||||
"smallvec",
|
||||
"utf8_iter",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "idna_adapter"
|
||||
version = "1.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714"
|
||||
dependencies = [
|
||||
"icu_normalizer",
|
||||
"icu_properties",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "image"
|
||||
version = "0.25.10"
|
||||
@@ -3097,6 +3344,7 @@ dependencies = [
|
||||
"moxcms",
|
||||
"num-traits",
|
||||
"png",
|
||||
"tiff",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -3155,6 +3403,15 @@ dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8b4baf93f58d4425749ca49a51c50ebab072c5df6994d08fed93541c331481dc"
|
||||
dependencies = [
|
||||
"either",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.18"
|
||||
@@ -3282,6 +3539,18 @@ dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kurbo"
|
||||
version = "0.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4b60dfc32f652b926df6192e55525b16d186c69d47876c3ead4da5cc9f8450e2"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"euclid",
|
||||
"polycool",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
@@ -3537,6 +3806,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nohash-hasher"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2bf50223579dc7cdcfb3bfcacf7069ff68243f8c363f62ffa99cf000a6b9c451"
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "8.0.0"
|
||||
@@ -4106,7 +4381,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fad031076f48f0d4d85ce1aea9b94b4e715a4d636a030a123038f8f5b5e4343"
|
||||
dependencies = [
|
||||
"fontique",
|
||||
"harfrust",
|
||||
"harfrust 0.6.2",
|
||||
"hashbrown 0.17.1",
|
||||
"icu_normalizer",
|
||||
"icu_properties",
|
||||
@@ -4126,6 +4401,19 @@ dependencies = [
|
||||
"icu_properties",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "peniko"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "839c8299360d2e998bdb106dc0a6cd71dcc5f4df51df1b620361bf50e283cca6"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"color",
|
||||
"kurbo",
|
||||
"linebender_resource_handle",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "percent-encoding"
|
||||
version = "2.3.2"
|
||||
@@ -4221,6 +4509,15 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "polycool"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "50596ddc09eb5ad5f75cacd40209568e66df71baf86e1499a0e99c4cff12a5a6"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "portable-atomic"
|
||||
version = "1.15.0"
|
||||
@@ -4292,6 +4589,12 @@ version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea"
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "2.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3"
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.41.0"
|
||||
@@ -4582,10 +4885,16 @@ dependencies = [
|
||||
"ab_glyph",
|
||||
"log",
|
||||
"memmap2",
|
||||
"smithay-client-toolkit",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"tiny-skia",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "self_cell"
|
||||
version = "1.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2ab42ca02749e120097e328d91d415325bdf43b1c72c4c8badf37375fe40a813"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "1.0.28"
|
||||
@@ -4726,8 +5035,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"calloop",
|
||||
"calloop-wayland-source",
|
||||
"calloop 0.13.0",
|
||||
"calloop-wayland-source 0.3.0",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
@@ -4744,6 +5053,44 @@ dependencies = [
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-client-toolkit"
|
||||
version = "0.20.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0512da38f5e2b31201a93524adb8d3136276fa4fe4aafab4e1f727a82b534cc0"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"calloop 0.14.4",
|
||||
"calloop-wayland-source 0.4.1",
|
||||
"cursor-icon",
|
||||
"libc",
|
||||
"log",
|
||||
"memmap2",
|
||||
"rustix 1.1.4",
|
||||
"thiserror 2.0.20",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-csd-frame",
|
||||
"wayland-cursor",
|
||||
"wayland-protocols",
|
||||
"wayland-protocols-experimental",
|
||||
"wayland-protocols-misc",
|
||||
"wayland-protocols-wlr",
|
||||
"wayland-scanner",
|
||||
"xkeysym",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smithay-clipboard"
|
||||
version = "0.7.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226"
|
||||
dependencies = [
|
||||
"libc",
|
||||
"smithay-client-toolkit 0.20.0",
|
||||
"wayland-backend",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "smol_str"
|
||||
version = "0.2.2"
|
||||
@@ -4941,6 +5288,20 @@ dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiff"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b63feaf3343d35b6ca4d50483f94843803b0f51634937cc2ec519fc32232bc52"
|
||||
dependencies = [
|
||||
"fax",
|
||||
"flate2",
|
||||
"half",
|
||||
"quick-error",
|
||||
"weezl",
|
||||
"zune-jpeg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-skia"
|
||||
version = "0.11.4"
|
||||
@@ -5019,6 +5380,7 @@ version = "0.1.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100"
|
||||
dependencies = [
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
@@ -5132,6 +5494,12 @@ version = "1.15.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "214ca0b2191785cbc06209b9ca1861e048e39b5ba33574b3cedd58363d5bb5f6"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-general-category"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b993bddc193ae5bd0d623b49ec06ac3e9312875fdae725a975c51db1cc1677f"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
@@ -5156,6 +5524,18 @@ version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"
|
||||
|
||||
[[package]]
|
||||
name = "url"
|
||||
version = "2.5.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"idna",
|
||||
"percent-encoding",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "utf8_iter"
|
||||
version = "1.0.4"
|
||||
@@ -5197,6 +5577,33 @@ version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
|
||||
|
||||
[[package]]
|
||||
name = "vello_common"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b2e9aed918117e8152c9eddfd8362d73c465c23f26c44786aa331707b8a64fa2"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"fearless_simd",
|
||||
"guillotiere 0.7.0",
|
||||
"log",
|
||||
"peniko",
|
||||
"smallvec",
|
||||
"thiserror 2.0.20",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vello_cpu"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ac7349e1f55f6b801c7c277958df4ea53e7f20f21e8014910ad888b2ecda93ea"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"glifo",
|
||||
"hashbrown 0.17.1",
|
||||
"vello_common",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
@@ -5337,6 +5744,32 @@ dependencies = [
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-experimental"
|
||||
version = "20250721.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40a1f863128dcaaec790d7b4b396cc9b9a7a079e878e18c47e6c2d2c5a8dcbb1"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-misc"
|
||||
version = "0.3.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e9567599ef23e09b8dad6e429e5738d4509dfc46b3b21f32841a304d16b29c8"
|
||||
dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"wayland-backend",
|
||||
"wayland-client",
|
||||
"wayland-protocols",
|
||||
"wayland-scanner",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wayland-protocols-plasma"
|
||||
version = "0.3.12"
|
||||
@@ -5424,6 +5857,28 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "webbrowser"
|
||||
version = "1.2.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "62c35be770821a214dbc362fc26908c853e776c0004294d0b10b8a6bad582f94"
|
||||
dependencies = [
|
||||
"jni 0.22.4",
|
||||
"log",
|
||||
"ndk-context",
|
||||
"objc2 0.6.4",
|
||||
"objc2-app-kit 0.3.2",
|
||||
"objc2-foundation 0.3.2",
|
||||
"url",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "weezl"
|
||||
version = "0.1.12"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a28ac98ddc8b9274cb41bb4d9d4d5c425b6020c50c46f25559911905610b4a88"
|
||||
|
||||
[[package]]
|
||||
name = "wgpu"
|
||||
version = "29.0.4"
|
||||
@@ -5975,7 +6430,7 @@ dependencies = [
|
||||
"bitflags 2.13.2",
|
||||
"block2 0.5.1",
|
||||
"bytemuck",
|
||||
"calloop",
|
||||
"calloop 0.13.0",
|
||||
"cfg_aliases",
|
||||
"concurrent-queue",
|
||||
"core-foundation",
|
||||
@@ -5997,7 +6452,7 @@ dependencies = [
|
||||
"redox_syscall 0.4.1",
|
||||
"rustix 0.38.44",
|
||||
"sctk-adwaita",
|
||||
"smithay-client-toolkit",
|
||||
"smithay-client-toolkit 0.19.2",
|
||||
"smol_str",
|
||||
"tracing",
|
||||
"unicode-segmentation",
|
||||
@@ -6239,3 +6694,18 @@ name = "zmij"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b"
|
||||
|
||||
[[package]]
|
||||
name = "zune-core"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d56377fd46368984a170bc5aac5567e52ca5da874caa60bea39fcbca78fb658b"
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.5.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27bc9d5b815bc103f142aa054f561d9187d191692ec7c2d1e2b4737f8dbd7296"
|
||||
dependencies = [
|
||||
"zune-core",
|
||||
]
|
||||
|
||||
@@ -5,4 +5,6 @@ edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.19.1"
|
||||
bevy_egui = "0.42.0"
|
||||
fastnoise-lite = "1.1.1"
|
||||
rand = "0.10.2"
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
# TODO
|
||||
|
||||
## Find a goal to the game
|
||||
|
||||
## Obstacles
|
||||
- Chunk obstacles
|
||||
- Random seed generated obstacles
|
||||
- At the end : procedural map generation
|
||||
|
||||
## Player
|
||||
- Hit box slitly smallest that the sprite
|
||||
|
||||
## Game over
|
||||
- Create Events to replace global bool resources
|
||||
|
||||
## Game states
|
||||
- Add EscMenu
|
||||
- Add SettingsMenu
|
||||
|
||||
## UI
|
||||
- Better menu ui
|
||||
- Better playing score etc ui
|
||||
- Better GameOver screen with final score
|
||||
- Settings ui
|
||||
- ...
|
||||
|
||||
## Debug
|
||||
- More complex debug (what take the most resources at each frame...)
|
||||
|
||||
## Ideas
|
||||
- Camera shake / non-following patterns
|
||||
- Player trail (particuls) with normal / speed trails
|
||||
- Huge zone with projectiles to avoid
|
||||
- Near object bonus (maybe a bar for multiplicators)
|
||||
- Section with polarity : 2 player colors and obstacles with certain color and need to switch manualy between colors to pass througt obstacles
|
||||
- If not 1 life : multiples lifes and an ennemi that follows us (like subwaysurfer) ?
|
||||
- Key to press with certain order display on a wall or somewhere else
|
||||
- Random biomes
|
||||
- Add a dash !!!???
|
||||
- Wind that creates a force on the player
|
||||
- Reverse fall (fall on the side or up rather than down, maybe invert the controls)
|
||||
- 3D moment ??
|
||||
- Magnets wall (mandatory to be against a wall)
|
||||
|
||||
## Bugs
|
||||
- Camera adapts to screen...
|
||||
|
||||
## Assets & Musics & Sounds
|
||||
- Make assets for better looking
|
||||
- Musics
|
||||
- Sounds
|
||||
Binary file not shown.
@@ -1,39 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
// Test checkboard background
|
||||
|
||||
const COLS: usize = 35;
|
||||
const ROWS: usize = 500;
|
||||
const CELL_SIZE: f32 = 60.0;
|
||||
const COLOR_A: Color = Color::srgb(0.0, 0.0, 0.0);
|
||||
const COLOR_B: Color = Color::srgb(0.6, 0.2, 0.8);
|
||||
|
||||
fn spawn_board(mut commands: Commands) {
|
||||
for row in 0..ROWS {
|
||||
for col in 0..COLS {
|
||||
// Altern colors
|
||||
let color = if (row + col) % 2 == 0 {
|
||||
COLOR_A
|
||||
} else {
|
||||
COLOR_B
|
||||
};
|
||||
|
||||
commands.spawn((
|
||||
Sprite::from_color(color, Vec2::new(CELL_SIZE, CELL_SIZE)),
|
||||
Transform::from_xyz(
|
||||
(col as f32 + 0.5 - COLS as f32 / 2.0) * CELL_SIZE,
|
||||
(row as f32 + 0.5 - ROWS as f32 / 2.0) * CELL_SIZE,
|
||||
0.0,
|
||||
),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BackgroundPlugin;
|
||||
|
||||
impl Plugin for BackgroundPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_board);
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{collision::Collider, player::Player};
|
||||
|
||||
fn constrain_player(
|
||||
mut player: Single<(&Collider, &mut Transform), With<Player>>,
|
||||
camera: Single<&Camera, With<Camera2d>>,
|
||||
) {
|
||||
let viewport = camera
|
||||
.logical_viewport_size()
|
||||
.unwrap_or(Vec2::new(1920.0, 1080.0));
|
||||
let half_width = player.0.size.x / 2.0;
|
||||
let border = viewport.x / 2.0 - half_width;
|
||||
|
||||
// Restrict player position
|
||||
player.1.translation.x = player.1.translation.x.clamp(-border, border);
|
||||
}
|
||||
|
||||
pub struct BoundsPlugin;
|
||||
|
||||
impl Plugin for BoundsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Update, constrain_player);
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::player::Player;
|
||||
use crate::player::move_player;
|
||||
|
||||
fn spawn_camera(mut commands: Commands) {
|
||||
commands.spawn(Camera2d);
|
||||
}
|
||||
|
||||
// Follow the player with the camera
|
||||
fn follow_player(
|
||||
player: Single<&Transform, (With<Player>, Without<Camera2d>)>,
|
||||
mut camera: Single<&mut Transform, (With<Camera2d>, Without<Player>)>,
|
||||
// time: Res<Time>,
|
||||
) {
|
||||
camera.translation.y = player.translation.y; // without delay
|
||||
// camera.translation.y = camera.translation.y
|
||||
// + (player.translation.y - camera.translation.y) * 3.0 * time.delta_secs(); // with delay
|
||||
}
|
||||
|
||||
pub struct CameraPlugin;
|
||||
|
||||
impl Plugin for CameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_camera)
|
||||
.add_systems(Update, follow_player.after(move_player));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
// Fixed game screen
|
||||
pub const SCREEN_WIDTH: f32 = 720.0;
|
||||
pub const SCREEN_HEIGHT: f32 = 1080.0;
|
||||
pub const SCREEN_ASPECT: f32 = SCREEN_WIDTH / SCREEN_HEIGHT; // 2:3
|
||||
|
||||
// Grid
|
||||
pub const CELL_SIZE: f32 = 16.0;
|
||||
pub const TERRAIN_COLS: i32 = 45;
|
||||
pub const CHUNK_ROWS: i32 = 64;
|
||||
|
||||
pub const TERRAIN_WIDTH: f32 = CELL_SIZE * TERRAIN_COLS as f32;
|
||||
pub const HALF_TERRAIN_WIDTH: f32 = TERRAIN_WIDTH / 2.0;
|
||||
pub const CHUNK_HEIGHT: f32 = CELL_SIZE * CHUNK_ROWS as f32;
|
||||
|
||||
// Streaming
|
||||
pub const MARGIN_ABOVE: f32 = 400.0;
|
||||
pub const MARGIN_BELLOW: f32 = 400.0;
|
||||
|
||||
// Player
|
||||
pub const PLAYER_HITBOX: Vec2 = Vec2::new(16.0, 32.0);
|
||||
pub const FALL_SPEED: f32 = 500.0;
|
||||
pub const DIVE_SPEED: f32 = 2000.0;
|
||||
pub const HORIZONTAL_SPEED: f32 = 400.0;
|
||||
pub const START_POSITION: Vec3 = Vec3::new(0.0, 0.0, 2.0);
|
||||
pub const CAMERAE_OFFSET: f32 = 280.0;
|
||||
|
||||
// Movement intertia
|
||||
pub const HORIZONTAL_ACCEL: f32 = 2600.0;
|
||||
pub const HORIZONTAL_FRICTION: f32 = 1800.0;
|
||||
pub const VERTICAL_RATE: f32 = 4000.0;
|
||||
+312
@@ -0,0 +1,312 @@
|
||||
use bevy::{
|
||||
diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin},
|
||||
prelude::*,
|
||||
};
|
||||
use bevy_egui::{EguiContexts, EguiPrimaryContextPass, egui};
|
||||
|
||||
use crate::{
|
||||
config::{SCREEN_HEIGHT, SCREEN_WIDTH},
|
||||
gameplay::{
|
||||
camera::MainCamera,
|
||||
collision::ColliderDebug,
|
||||
player::{FallStarted, MoveSettings, Player, Velocity, spawn_player},
|
||||
score::Depth,
|
||||
},
|
||||
screen::DisplayImage,
|
||||
states::GameState,
|
||||
world::{Chunk, RunSeed, terrain::TerrainSettings},
|
||||
};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Debug;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct DebugCamera;
|
||||
|
||||
fn spawn_debug_camera(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Debug,
|
||||
DebugCamera,
|
||||
Camera2d,
|
||||
Camera {
|
||||
is_active: false,
|
||||
order: 2,
|
||||
..default()
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
fn setup_debug_camera(mut camera: Single<&mut Projection, With<DebugCamera>>) {
|
||||
if let Projection::Orthographic(ref mut projection) = **camera {
|
||||
projection.scale = 4.0;
|
||||
}
|
||||
}
|
||||
|
||||
fn toggle_debug_camera(
|
||||
mut main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||
mut debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||
mut display_image: Single<&mut Visibility, With<DisplayImage>>,
|
||||
) {
|
||||
main_camera.is_active = !main_camera.is_active;
|
||||
debug_camera.is_active = !debug_camera.is_active;
|
||||
|
||||
if debug_camera.is_active {
|
||||
**display_image = Visibility::Hidden;
|
||||
} else {
|
||||
**display_image = Visibility::Visible;
|
||||
}
|
||||
}
|
||||
|
||||
fn follow_player_debug(
|
||||
player: Single<&Transform, (With<Player>, Without<DebugCamera>)>,
|
||||
mut debug_camera: Single<&mut Transform, (With<DebugCamera>, Without<Player>)>,
|
||||
) {
|
||||
debug_camera.translation.y = player.translation.y;
|
||||
}
|
||||
|
||||
enum FrameSide {
|
||||
Top,
|
||||
Bottom,
|
||||
Left,
|
||||
Right,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct FramePart(FrameSide);
|
||||
|
||||
fn spawn_debug_frame(mut commands: Commands) {
|
||||
for side in [
|
||||
FrameSide::Top,
|
||||
FrameSide::Bottom,
|
||||
FrameSide::Left,
|
||||
FrameSide::Right,
|
||||
] {
|
||||
let size = match side {
|
||||
FrameSide::Top | FrameSide::Bottom => Vec2::new(SCREEN_WIDTH + 16.0, 8.0),
|
||||
FrameSide::Left | FrameSide::Right => Vec2::new(8.0, SCREEN_HEIGHT + 16.0),
|
||||
};
|
||||
|
||||
commands.spawn((
|
||||
Debug,
|
||||
FramePart(side),
|
||||
Sprite::from_color(Color::srgb(1.0, 0.0, 0.0), size),
|
||||
Visibility::Hidden,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
fn draw_view_frame(
|
||||
main_camera: Single<&Transform, (With<MainCamera>, Without<DebugCamera>)>,
|
||||
debug_camera: Single<&Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||
mut frame: Query<
|
||||
(&FramePart, &mut Transform, &mut Visibility),
|
||||
(Without<MainCamera>, Without<DebugCamera>),
|
||||
>,
|
||||
) {
|
||||
let center = main_camera.translation;
|
||||
let half_width = SCREEN_WIDTH / 2.0;
|
||||
let half_height = SCREEN_HEIGHT / 2.0;
|
||||
|
||||
let visible = if debug_camera.is_active {
|
||||
Visibility::Visible
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
|
||||
for (frame_part, mut frame_transform, mut visibility) in &mut frame {
|
||||
let position = match frame_part.0 {
|
||||
FrameSide::Top => Vec3::new(center.x, center.y + half_height, 10.0),
|
||||
FrameSide::Bottom => Vec3::new(center.x, center.y - half_height, 10.0),
|
||||
FrameSide::Left => Vec3::new(center.x - half_width, center.y, 10.0),
|
||||
FrameSide::Right => Vec3::new(center.x + half_width, center.y, 10.0),
|
||||
};
|
||||
frame_transform.translation = position;
|
||||
*visibility = visible;
|
||||
}
|
||||
}
|
||||
|
||||
// Real time tuning movement & inertia sliders
|
||||
fn move_tuning_panel(mut contexts: EguiContexts, mut settings: ResMut<MoveSettings>) {
|
||||
egui::Window::new("Movement / Inertia ").show(
|
||||
contexts.ctx_mut().expect("egui context missing"),
|
||||
|ui| {
|
||||
ui.add(
|
||||
egui::Slider::new(&mut settings.horizontal_speed, 0.0..=1000.0).text("Max speed"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut settings.horizontal_accel, 0.0..=10000.0)
|
||||
.text("Acceleration"),
|
||||
);
|
||||
ui.add(
|
||||
egui::Slider::new(&mut settings.horizontal_friction, 0.0..=10000.0)
|
||||
.text("Friction"),
|
||||
);
|
||||
ui.add(egui::Slider::new(&mut settings.fall_speed, 0.0..=2000.0).text("Fall"));
|
||||
ui.add(egui::Slider::new(&mut settings.dive_speed, 0.0..=5000.0).text("SpeeFall"));
|
||||
ui.add(
|
||||
egui::Slider::new(&mut settings.vertical_rate, 0.0..=10000.0).text("Vertical rate"),
|
||||
);
|
||||
|
||||
ui.separator();
|
||||
|
||||
if ui.button("Reset").clicked() {
|
||||
*settings = MoveSettings::default();
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
let export_text = format!(
|
||||
"pub const FALL_SPEED: f32 = {:.0};\npub const DIVE_SPEED: f32 = {:.0};\npub const HORIZONTAL_SPEED: f32 = {:.0};\npub const HORIZONTAL_ACCEL: f32 = {:.0};\npub const HORIZONTAL_FRICTION: f32 = {:.0};\npub const VERTICAL_RATE: f32 = {:.0};",
|
||||
settings.fall_speed,
|
||||
settings.dive_speed,
|
||||
settings.horizontal_speed,
|
||||
settings.horizontal_accel,
|
||||
settings.horizontal_friction,
|
||||
settings.vertical_rate,
|
||||
);
|
||||
// ui.monospace(&export_text);
|
||||
if ui.button("Copy -> config.rs").clicked() {
|
||||
ui.ctx().copy_text(export_text);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
fn debug_panel(
|
||||
mut contexts: EguiContexts,
|
||||
store: Res<DiagnosticsStore>,
|
||||
mut run_seed: ResMut<RunSeed>,
|
||||
player: Single<(Entity, &Transform, &Velocity), With<Player>>,
|
||||
chunk: Query<Entity, With<Chunk>>,
|
||||
main_camera: Single<&mut Camera, (With<MainCamera>, Without<DebugCamera>)>,
|
||||
debug_camera: Single<&mut Camera, (With<DebugCamera>, Without<MainCamera>)>,
|
||||
mut commands: Commands,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
mut depth: ResMut<Depth>,
|
||||
display_image: Single<&mut Visibility, With<DisplayImage>>,
|
||||
mut terrain_settings: ResMut<TerrainSettings>,
|
||||
mut collider_debug: ResMut<ColliderDebug>,
|
||||
) {
|
||||
egui::Window::new("Debug").show(contexts.ctx_mut().expect("gui context missing"), |ui| {
|
||||
// Fps
|
||||
let fps = store
|
||||
.get(&FrameTimeDiagnosticsPlugin::FPS)
|
||||
.and_then(|diagnostic| diagnostic.smoothed());
|
||||
|
||||
match fps {
|
||||
Some(fps) => ui.label(format!("FPS: {fps:.0}")),
|
||||
None => ui.label("FPS: -"),
|
||||
};
|
||||
|
||||
// Frame time in ms
|
||||
match store
|
||||
.get(&FrameTimeDiagnosticsPlugin::FRAME_TIME)
|
||||
.and_then(|d| d.smoothed())
|
||||
{
|
||||
Some(ms) => ui.label(format!("Frame: {ms:.2} ms")),
|
||||
None => ui.label("Frame : - ms"),
|
||||
};
|
||||
|
||||
// Run seed
|
||||
ui.label(format!("Seed: {}", run_seed.0));
|
||||
|
||||
let (player_entity, transform, velocity) = *player;
|
||||
ui.label(format!(
|
||||
"Position: ({:.0}, {:.0})",
|
||||
transform.translation.x, transform.translation.y
|
||||
));
|
||||
ui.label(format!(
|
||||
"Velocity: ({:.0},{:.0})",
|
||||
velocity.0.x, velocity.0.y
|
||||
));
|
||||
|
||||
// Resolution
|
||||
ui.label(format!("View: {SCREEN_WIDTH:.0}x{SCREEN_HEIGHT:.0}"));
|
||||
|
||||
ui.separator();
|
||||
|
||||
let state = if debug_camera.is_active { "ON" } else { "OFF" };
|
||||
if ui.button(format!("Debug camera: {state}")).clicked() {
|
||||
toggle_debug_camera(main_camera, debug_camera, display_image);
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
let restart = ui.button("Restart (same seed)").clicked();
|
||||
let new_map = ui.button("Restart (new map)").clicked();
|
||||
if restart || new_map {
|
||||
for entity in chunk.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
if new_map {
|
||||
run_seed.0 = rand::random::<u64>();
|
||||
}
|
||||
fall_started.0 = false;
|
||||
depth.0 = 0.0;
|
||||
|
||||
commands.entity(player_entity).despawn();
|
||||
|
||||
spawn_player(commands);
|
||||
}
|
||||
|
||||
ui.separator();
|
||||
|
||||
ui.label("Terrain");
|
||||
if ui.button("Reset terrain seed").clicked() {
|
||||
run_seed.0 = rand::random::<u64>();
|
||||
}
|
||||
let mut settings = *terrain_settings;
|
||||
let changed = ui
|
||||
.add(egui::Slider::new(&mut settings.threshold, -1.0..=1.0).text("Threshold"))
|
||||
.changed()
|
||||
| ui.add(egui::Slider::new(&mut settings.frequency, 0.0..=0.3).text("Frequency"))
|
||||
.changed()
|
||||
| ui.add(egui::Slider::new(&mut settings.octaves, 1..=10).text("Octaves"))
|
||||
.changed();
|
||||
|
||||
if changed {
|
||||
*terrain_settings = settings; // ne marque changed qu'au vrai changement
|
||||
}
|
||||
// ui.add(egui::Slider::new(&mut terrain_settings.threshold, -1.0..=1.0).text("Treshold"));
|
||||
// ui.add(egui::Slider::new(&mut terrain_settings.frequency, 0.0..=0.3).text("Frequency"));
|
||||
// ui.add(egui::Slider::new(&mut terrain_settings.octaves, 1..=10).text("Octaves"));
|
||||
//
|
||||
ui.separator();
|
||||
let state = if collider_debug.0 { "ON" } else { "OFF" };
|
||||
if ui.button(format!("Kill blocks: {state}")).clicked() {
|
||||
collider_debug.0 = !collider_debug.0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
fn cleanup_debug(mut commands: Commands, entities: Query<Entity, With<Debug>>) {
|
||||
for entity in entities {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct DebugPlugin;
|
||||
|
||||
impl Plugin for DebugPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
OnEnter(GameState::InGame),
|
||||
(
|
||||
spawn_debug_camera,
|
||||
setup_debug_camera.after(spawn_debug_camera),
|
||||
spawn_debug_frame,
|
||||
),
|
||||
)
|
||||
.add_systems(
|
||||
Update,
|
||||
(draw_view_frame, follow_player_debug).run_if(in_state(GameState::InGame)),
|
||||
)
|
||||
// Egui debug
|
||||
.add_systems(
|
||||
EguiPrimaryContextPass,
|
||||
(move_tuning_panel, debug_panel).run_if(in_state(GameState::InGame)),
|
||||
)
|
||||
.add_plugins(FrameTimeDiagnosticsPlugin::default())
|
||||
.add_systems(OnExit(GameState::InGame), cleanup_debug);
|
||||
}
|
||||
}
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
use bevy::{asset::AssetApp, prelude::*, text::Font};
|
||||
|
||||
const COZETTE_BYTES: &[u8] = include_bytes!("../assets/fonts/CozetteVector.ttf");
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct GameFont(pub Handle<Font>);
|
||||
|
||||
pub struct FontPlugin;
|
||||
|
||||
impl Plugin for FontPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_asset::<Font>();
|
||||
|
||||
let handle = {
|
||||
let mut fonts = app.world_mut().resource_mut::<Assets<Font>>();
|
||||
fonts.add(Font::from_bytes(COZETTE_BYTES.to_vec()))
|
||||
};
|
||||
|
||||
app.insert_resource(GameFont(handle));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
pub mod bounds;
|
||||
pub mod camera;
|
||||
pub mod collision;
|
||||
pub mod player;
|
||||
pub mod score;
|
||||
@@ -0,0 +1,31 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
config::HALF_TERRAIN_WIDTH,
|
||||
gameplay::{
|
||||
collision::Collider,
|
||||
player::{Player, move_player},
|
||||
},
|
||||
states::GameState,
|
||||
};
|
||||
|
||||
fn constrain_player(mut player: Single<(&Collider, &mut Transform), With<Player>>) {
|
||||
let half_width = player.0.size.x / 2.0;
|
||||
let border = HALF_TERRAIN_WIDTH - half_width;
|
||||
|
||||
// Restrict player position to the terrain widht
|
||||
player.1.translation.x = player.1.translation.x.clamp(-border, border);
|
||||
}
|
||||
|
||||
pub struct BoundsPlugin;
|
||||
|
||||
impl Plugin for BoundsPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(
|
||||
Update,
|
||||
constrain_player
|
||||
.after(move_player)
|
||||
.run_if(in_state(GameState::InGame)),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::config::CAMERAE_OFFSET;
|
||||
use crate::gameplay::player::{Player, move_player};
|
||||
use crate::states::GameState;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct MainCamera;
|
||||
|
||||
// Follow the player with the camera
|
||||
fn follow_player(
|
||||
player: Single<&Transform, (With<Player>, Without<MainCamera>)>,
|
||||
mut camera: Single<&mut Transform, (With<MainCamera>, Without<Player>)>,
|
||||
) {
|
||||
camera.translation.y = player.translation.y - CAMERAE_OFFSET;
|
||||
}
|
||||
|
||||
fn reset_camera(mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||
main_camera.is_active = true;
|
||||
}
|
||||
|
||||
pub struct CameraPlugin;
|
||||
|
||||
impl Plugin for CameraPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::InGame), reset_camera)
|
||||
.add_systems(
|
||||
Update,
|
||||
follow_player
|
||||
.run_if(in_state(GameState::InGame))
|
||||
.after(move_player),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
obstacle::Obstacle,
|
||||
player::{Player, move_player},
|
||||
gameplay::player::{Player, move_player},
|
||||
states::GameState,
|
||||
world::obstacle::Obstacle,
|
||||
};
|
||||
|
||||
// Hitbox
|
||||
@@ -11,20 +12,23 @@ pub struct Collider {
|
||||
pub size: Vec2,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct HasCollided(pub bool);
|
||||
// Collider debug
|
||||
#[derive(Resource)]
|
||||
pub struct ColliderDebug(pub bool);
|
||||
|
||||
impl Default for ColliderDebug {
|
||||
fn default() -> Self {
|
||||
Self(false)
|
||||
}
|
||||
}
|
||||
|
||||
// Check collision with Player
|
||||
pub fn check_collision_with_player(
|
||||
mut player: Single<(&Transform, &Collider, &mut Sprite), With<Player>>,
|
||||
player: Single<(&Transform, &Collider), With<Player>>,
|
||||
obstacle: Query<(&Transform, &Collider), With<Obstacle>>,
|
||||
mut has_collided: ResMut<HasCollided>,
|
||||
mut next_state: ResMut<NextState<GameState>>,
|
||||
) {
|
||||
if has_collided.0 {
|
||||
return;
|
||||
}
|
||||
|
||||
let (player_transform, player_collider, mut _player_sprite) = player.into_inner();
|
||||
let (player_transform, player_collider) = player.into_inner();
|
||||
|
||||
// Check whether or not each obstacles overlap the player
|
||||
for (collider_transform, collider_collider) in obstacle {
|
||||
@@ -35,7 +39,7 @@ pub fn check_collision_with_player(
|
||||
collider_collider.size / 2.0,
|
||||
) {
|
||||
// player_sprite.color = Color::srgb(1.0, 0.0, 0.0); // Change sprite color
|
||||
has_collided.0 = true;
|
||||
next_state.set(GameState::GameOver);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -52,7 +56,13 @@ pub struct CollisionPlugin;
|
||||
|
||||
impl Plugin for CollisionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<HasCollided>()
|
||||
.add_systems(Update, check_collision_with_player.after(move_player));
|
||||
app.init_resource::<ColliderDebug>() // Debug
|
||||
.add_systems(
|
||||
Update,
|
||||
check_collision_with_player
|
||||
.run_if(in_state(GameState::InGame))
|
||||
.run_if(|collision: Res<ColliderDebug>| collision.0) // Debug
|
||||
.after(move_player),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::config::DIVE_SPEED;
|
||||
use crate::config::FALL_SPEED;
|
||||
use crate::config::HORIZONTAL_ACCEL;
|
||||
use crate::config::HORIZONTAL_FRICTION;
|
||||
use crate::config::HORIZONTAL_SPEED;
|
||||
use crate::config::PLAYER_HITBOX;
|
||||
use crate::config::START_POSITION;
|
||||
use crate::config::VERTICAL_RATE;
|
||||
use crate::gameplay::collision::Collider;
|
||||
use crate::states::GameState;
|
||||
|
||||
// The player
|
||||
#[derive(Component)]
|
||||
pub struct Player;
|
||||
|
||||
// Speed of the player
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(pub Vec2);
|
||||
|
||||
// Falling bool
|
||||
#[derive(Resource, Default)]
|
||||
pub struct FallStarted(pub bool);
|
||||
|
||||
// Spawn entity player
|
||||
pub fn spawn_player(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Player,
|
||||
Collider {
|
||||
size: PLAYER_HITBOX,
|
||||
},
|
||||
Velocity(Vec2::ZERO),
|
||||
Sprite::from_color(Color::srgb(1.0, 1.0, 1.0), PLAYER_HITBOX),
|
||||
Transform::from_xyz(START_POSITION.x, START_POSITION.y, START_POSITION.z),
|
||||
));
|
||||
}
|
||||
|
||||
// Move value to target by max_step
|
||||
fn approach(value: f32, target: f32, max_step: f32) -> f32 {
|
||||
if value < target {
|
||||
(value + max_step).min(target)
|
||||
} else {
|
||||
(value - max_step).max(target)
|
||||
}
|
||||
}
|
||||
|
||||
// For debug
|
||||
#[derive(Resource)]
|
||||
pub struct MoveSettings {
|
||||
pub horizontal_speed: f32,
|
||||
pub horizontal_accel: f32,
|
||||
pub horizontal_friction: f32,
|
||||
pub fall_speed: f32,
|
||||
pub dive_speed: f32,
|
||||
pub vertical_rate: f32,
|
||||
}
|
||||
|
||||
impl Default for MoveSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
horizontal_speed: HORIZONTAL_SPEED,
|
||||
horizontal_accel: HORIZONTAL_ACCEL,
|
||||
horizontal_friction: HORIZONTAL_FRICTION,
|
||||
fall_speed: FALL_SPEED,
|
||||
dive_speed: DIVE_SPEED,
|
||||
vertical_rate: VERTICAL_RATE,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Input + movement system for the player
|
||||
pub(crate) fn move_player(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
settings: Res<MoveSettings>,
|
||||
time: Res<Time>,
|
||||
mut player: Query<(&mut Velocity, &mut Transform), With<Player>>,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
) {
|
||||
// If matching entity
|
||||
let Ok((mut velocity, mut transform)) = player.single_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
if !fall_started.0
|
||||
&& (input.just_pressed(KeyCode::KeyA)
|
||||
|| input.just_pressed(KeyCode::KeyD)
|
||||
|| input.just_pressed(KeyCode::KeyS))
|
||||
{
|
||||
fall_started.0 = true;
|
||||
} else if !fall_started.0 {
|
||||
// Null speed
|
||||
return;
|
||||
}
|
||||
|
||||
// Change then horizontal direction regardless the input
|
||||
let direction = if input.pressed(KeyCode::KeyA) {
|
||||
-1.0
|
||||
} else if input.pressed(KeyCode::KeyD) {
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
let dt = time.delta_secs();
|
||||
|
||||
// Inertia
|
||||
if direction != 0.0 {
|
||||
velocity.0.x = approach(
|
||||
velocity.0.x,
|
||||
direction * settings.horizontal_speed,
|
||||
settings.horizontal_accel * dt,
|
||||
);
|
||||
} else {
|
||||
velocity.0.x = approach(velocity.0.x, 0.0, settings.horizontal_friction * dt);
|
||||
}
|
||||
let vertical_target = if input.pressed(KeyCode::KeyS) {
|
||||
-settings.dive_speed
|
||||
} else {
|
||||
-settings.fall_speed
|
||||
};
|
||||
velocity.0.y = approach(velocity.0.y, vertical_target, settings.vertical_rate * dt);
|
||||
|
||||
// Position update
|
||||
transform.translation += velocity.0.extend(0.0) * dt;
|
||||
}
|
||||
|
||||
// To freeze player at the begining of the Ingame
|
||||
fn start_run(mut fall_started: ResMut<FallStarted>) {
|
||||
fall_started.0 = false;
|
||||
}
|
||||
|
||||
fn cleanup_player(mut commands: Commands, player: Single<Entity, With<Player>>) {
|
||||
commands.entity(*player).despawn();
|
||||
}
|
||||
|
||||
pub struct PlayerPlugin;
|
||||
|
||||
impl Plugin for PlayerPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::InGame), (spawn_player, start_run))
|
||||
.init_resource::<FallStarted>()
|
||||
.init_resource::<MoveSettings>()
|
||||
.add_systems(Update, (move_player,).run_if(in_state(GameState::InGame)))
|
||||
.add_systems(OnExit(GameState::InGame), cleanup_player);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
config::START_POSITION,
|
||||
font::GameFont,
|
||||
gameplay::player::{Player, move_player},
|
||||
states::GameState,
|
||||
};
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct Depth(pub f32);
|
||||
|
||||
// Update depth of the player
|
||||
fn update_depth(mut depth: ResMut<Depth>, player: Single<&Transform, With<Player>>) {
|
||||
depth.0 = START_POSITION.y - player.translation.y;
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct DepthText;
|
||||
|
||||
// Display the initial text of the depth (Score)
|
||||
fn spawn_depth_text(mut commands: Commands, game_font: Res<GameFont>) {
|
||||
commands.spawn((
|
||||
Text::new(""),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(60.0),
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::WHITE),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(20.0),
|
||||
left: Val::Px(20.0),
|
||||
..default()
|
||||
},
|
||||
DepthText,
|
||||
));
|
||||
}
|
||||
|
||||
// Update depth score texts
|
||||
fn update_depth_text(depth: Res<Depth>, texts: Query<&mut Text, With<DepthText>>) {
|
||||
for mut text in texts {
|
||||
text.0 = format!("{}", (depth.0 / 100.0).floor());
|
||||
}
|
||||
}
|
||||
|
||||
fn cleanup_score(mut commands: Commands, entities: Query<Entity, With<DepthText>>) {
|
||||
for entity in entities {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ScorePlugin;
|
||||
|
||||
impl Plugin for ScorePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_resource::<Depth>()
|
||||
.add_systems(OnEnter(GameState::InGame), spawn_depth_text)
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
update_depth_text.after(spawn_depth_text),
|
||||
update_depth.after(move_player),
|
||||
)
|
||||
.run_if(in_state(GameState::InGame)),
|
||||
)
|
||||
.add_systems(OnExit(GameState::InGame), cleanup_score);
|
||||
}
|
||||
}
|
||||
+43
-17
@@ -1,38 +1,64 @@
|
||||
use bevy::{prelude::*, window::PresentMode};
|
||||
|
||||
use crate::background::BackgroundPlugin;
|
||||
use crate::bounds::BoundsPlugin;
|
||||
use crate::camera::CameraPlugin;
|
||||
use crate::collision::CollisionPlugin;
|
||||
use crate::obstacle::ObstaclePlugin;
|
||||
use crate::player::PlayerPlugin;
|
||||
use crate::score::ScorePlugin;
|
||||
use bevy_egui::{EguiGlobalSettings, EguiPlugin};
|
||||
|
||||
mod background;
|
||||
mod bounds;
|
||||
mod camera;
|
||||
mod collision;
|
||||
mod obstacle;
|
||||
mod player;
|
||||
mod score;
|
||||
use crate::config::{SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||
use crate::debug::DebugPlugin;
|
||||
use crate::font::FontPlugin;
|
||||
use crate::gameplay::bounds::BoundsPlugin;
|
||||
use crate::gameplay::camera::CameraPlugin;
|
||||
use crate::gameplay::collision::CollisionPlugin;
|
||||
use crate::gameplay::player::PlayerPlugin;
|
||||
use crate::gameplay::score::ScorePlugin;
|
||||
use crate::screen::ScreenPlugin;
|
||||
use crate::states::GameStatePlugin;
|
||||
use crate::states::game_over::GameOverPlugin;
|
||||
use crate::states::main_menu::MainMenuPlugin;
|
||||
use crate::world::WorldPlugin;
|
||||
use crate::world::terrain::TerrainPlugin;
|
||||
|
||||
mod config;
|
||||
mod debug;
|
||||
mod font;
|
||||
mod gameplay;
|
||||
mod screen;
|
||||
mod states;
|
||||
mod world;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "Down Into The Void".into(),
|
||||
resolution: (1920, 1080).into(),
|
||||
resolution: (SCREEN_WIDTH as u32, SCREEN_HEIGHT as u32).into(),
|
||||
present_mode: PresentMode::AutoVsync,
|
||||
resize_constraints: WindowResizeConstraints {
|
||||
min_width: 360.0,
|
||||
min_height: 480.0,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
}),
|
||||
..default()
|
||||
}))
|
||||
.add_plugins(BackgroundPlugin) // Checkerboard background
|
||||
.add_plugins(FontPlugin) // Font
|
||||
.add_plugins(PlayerPlugin) // Player
|
||||
.add_plugins(ScreenPlugin) // Virtual screen
|
||||
.add_plugins(CameraPlugin) // Camera
|
||||
.add_plugins(CollisionPlugin) // Collisions
|
||||
.add_plugins(ObstaclePlugin) // Obstacles
|
||||
.add_plugins(BoundsPlugin) // Bound player
|
||||
.add_plugins(ScorePlugin) // Score
|
||||
.add_plugins(WorldPlugin) // Chunk logic
|
||||
.add_plugins(GameStatePlugin) // Game states
|
||||
.add_plugins(MainMenuPlugin) // Main Menu
|
||||
.add_plugins(GameOverPlugin) // GameOver
|
||||
// Debug UI
|
||||
.insert_resource(EguiGlobalSettings {
|
||||
auto_create_primary_context: false,
|
||||
..default()
|
||||
})
|
||||
.add_plugins(EguiPlugin::default()) // Debug UI
|
||||
.add_plugins(DebugPlugin) // Debug
|
||||
.add_plugins(TerrainPlugin) // Terrain debug
|
||||
.run();
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
use crate::{collision::Collider, player::reset_player};
|
||||
use bevy::prelude::*;
|
||||
use rand::RngExt;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Obstacle;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct RegenerateObstacles(pub bool);
|
||||
|
||||
fn spawn_obstacle(commands: &mut Commands, position: Vec2, size: Vec2) {
|
||||
commands.spawn((
|
||||
Obstacle,
|
||||
Collider { size },
|
||||
Transform::from_xyz(position.x, position.y, 1.0),
|
||||
Sprite::from_color(Color::srgb(1.0, 0.5, 0.1), size),
|
||||
));
|
||||
}
|
||||
|
||||
// Temporary fonction for display random obstacles
|
||||
fn spawn_random_obstacles(commands: &mut Commands) {
|
||||
let mut rng = rand::rng();
|
||||
|
||||
let min_x = -960.0;
|
||||
let max_x = 960.0;
|
||||
|
||||
let mut y = -1000.0;
|
||||
|
||||
for _ in 0..100 {
|
||||
let obstacle_count = rng.random_range(1..=3);
|
||||
|
||||
for _ in 0..obstacle_count {
|
||||
let width = rng.random_range(100.0..=400.0);
|
||||
let height = rng.random_range(20.0..=200.0);
|
||||
|
||||
let x = rng.random_range((min_x + width / 2.0)..=(max_x - width / 2.0));
|
||||
|
||||
spawn_obstacle(commands, Vec2::new(x, y), Vec2::new(width, height));
|
||||
}
|
||||
|
||||
y -= rng.random_range(80.0..=160.0);
|
||||
}
|
||||
}
|
||||
|
||||
fn regenerate_obstacles(
|
||||
mut commands: Commands,
|
||||
obstacles: Query<Entity, With<Obstacle>>,
|
||||
mut regenerate_obstacles: ResMut<RegenerateObstacles>,
|
||||
) {
|
||||
if regenerate_obstacles.0 {
|
||||
for obstacle in obstacles {
|
||||
commands.entity(obstacle).despawn();
|
||||
}
|
||||
spawn_random_obstacles(&mut commands);
|
||||
regenerate_obstacles.0 = false;
|
||||
}
|
||||
}
|
||||
|
||||
fn spawn_obstacles(mut commands: Commands) {
|
||||
spawn_random_obstacles(&mut commands);
|
||||
}
|
||||
|
||||
pub struct ObstaclePlugin;
|
||||
|
||||
impl Plugin for ObstaclePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_obstacles)
|
||||
.init_resource::<RegenerateObstacles>()
|
||||
.add_systems(Update, regenerate_obstacles.after(reset_player));
|
||||
}
|
||||
}
|
||||
-122
@@ -1,122 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::collision::check_collision_with_player;
|
||||
use crate::collision::{Collider, HasCollided};
|
||||
use crate::obstacle::RegenerateObstacles;
|
||||
|
||||
const FALL_SPEED: f32 = 600.0; // Falling speed
|
||||
const DIVE_SPEED: f32 = 1000.0; // Falling speed sped up
|
||||
const HORIZONTAL_SPEED: f32 = 350.0; // Lateral movement speed
|
||||
pub const START_POSITION: Vec3 = Vec3::new(0.0, 0.0, 2.0); // Start position
|
||||
const RATE: f32 = 13.0; // Inertia rate
|
||||
|
||||
// The player
|
||||
#[derive(Component)]
|
||||
pub struct Player;
|
||||
|
||||
// Speed of the player
|
||||
#[derive(Component)]
|
||||
pub struct Velocity(Vec2);
|
||||
|
||||
// Falling bool
|
||||
#[derive(Resource, Default)]
|
||||
pub struct FallStarted(pub bool);
|
||||
|
||||
// Spawn entity player
|
||||
fn spawn_player(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Player,
|
||||
Collider {
|
||||
size: Vec2::new(20.0, 40.0),
|
||||
},
|
||||
Velocity(Vec2::ZERO),
|
||||
Sprite::from_color(Color::srgb(1.0, 1.0, 1.0), Vec2::new(20.0, 40.0)),
|
||||
Transform::from_xyz(START_POSITION.x, START_POSITION.y, START_POSITION.z),
|
||||
));
|
||||
}
|
||||
|
||||
// Input + movement system for the player
|
||||
pub(crate) fn move_player(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
time: Res<Time>,
|
||||
mut player: Query<(&mut Velocity, &mut Transform), With<Player>>,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
) {
|
||||
// If matching entity
|
||||
let Ok((mut velocity, mut transform)) = player.single_mut() else {
|
||||
return;
|
||||
};
|
||||
|
||||
if !fall_started.0
|
||||
&& (input.just_pressed(KeyCode::KeyA)
|
||||
|| input.just_pressed(KeyCode::KeyD)
|
||||
|| input.just_pressed(KeyCode::KeyS))
|
||||
{
|
||||
fall_started.0 = true;
|
||||
} else if !fall_started.0 {
|
||||
// Null speed
|
||||
return;
|
||||
}
|
||||
|
||||
// Change then horizontal direction regardless the input
|
||||
let direction = if input.pressed(KeyCode::KeyA) {
|
||||
-1.0
|
||||
} else if input.pressed(KeyCode::KeyD) {
|
||||
1.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
||||
let facteur = 1.0 - (-RATE * time.delta_secs()).exp();
|
||||
let target = Vec2::new(
|
||||
direction * HORIZONTAL_SPEED,
|
||||
-if input.pressed(KeyCode::KeyS) {
|
||||
DIVE_SPEED
|
||||
} else {
|
||||
FALL_SPEED
|
||||
},
|
||||
);
|
||||
|
||||
velocity.0 = velocity.0.lerp(target, facteur);
|
||||
|
||||
// Position update (no smoothness in velocity)
|
||||
transform.translation += velocity.0.extend(0.0) * time.delta_secs();
|
||||
}
|
||||
|
||||
// Reset player position
|
||||
pub fn reset_player(
|
||||
mut player: Single<(&mut Transform, &mut Velocity, &mut Sprite), With<Player>>,
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
mut has_collided: ResMut<HasCollided>,
|
||||
mut fall_started: ResMut<FallStarted>,
|
||||
mut regenerate_obstacles: ResMut<RegenerateObstacles>,
|
||||
) {
|
||||
let (mut transform, mut velocity, mut sprite) = player.into_inner();
|
||||
|
||||
// R key for reset or player has collider
|
||||
if input.just_pressed(KeyCode::KeyR) || has_collided.0 {
|
||||
transform.translation = Vec3::new(START_POSITION.x, START_POSITION.y, START_POSITION.z);
|
||||
velocity.0 = Vec2::ZERO;
|
||||
sprite.color = Color::WHITE;
|
||||
|
||||
has_collided.0 = false;
|
||||
fall_started.0 = false;
|
||||
regenerate_obstacles.0 = true;
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PlayerPlugin;
|
||||
|
||||
impl Plugin for PlayerPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_player)
|
||||
.init_resource::<FallStarted>()
|
||||
.add_systems(Update, move_player)
|
||||
.add_systems(
|
||||
Update,
|
||||
reset_player
|
||||
.after(move_player)
|
||||
.after(check_collision_with_player),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::player::{Player, START_POSITION, move_player};
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct Depth(pub f32);
|
||||
|
||||
// Update depth of the player
|
||||
fn update_depth(mut depth: ResMut<Depth>, player: Single<&Transform, With<Player>>) {
|
||||
depth.0 = START_POSITION.y - player.translation.y;
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct DepthText;
|
||||
|
||||
// Display the initial text of the depth (Score)
|
||||
fn spawn_depth_text(mut commands: Commands) {
|
||||
commands.spawn((
|
||||
Text::new("0"),
|
||||
TextFont {
|
||||
font_size: FontSize::Px(50.0),
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::WHITE),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Px(20.0),
|
||||
left: Val::Px(20.0),
|
||||
..default()
|
||||
},
|
||||
DepthText,
|
||||
));
|
||||
}
|
||||
|
||||
// Update depth score text
|
||||
fn update_depth_text(
|
||||
mut commands: Commands,
|
||||
depth: Res<Depth>,
|
||||
mut texts: Query<&mut Text, With<DepthText>>,
|
||||
) {
|
||||
for mut text in texts {
|
||||
text.0 = format!("Score: {}", depth.0);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ScorePlugin;
|
||||
|
||||
impl Plugin for ScorePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_depth_text)
|
||||
.init_resource::<Depth>()
|
||||
.add_systems(Update, update_depth.after(move_player))
|
||||
.add_systems(Update, update_depth_text);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
use bevy::camera::RenderTarget;
|
||||
use bevy::camera::visibility::RenderLayers;
|
||||
use bevy::prelude::*;
|
||||
use bevy::render::render_resource::TextureFormat;
|
||||
use bevy_egui::PrimaryEguiContext;
|
||||
|
||||
use crate::config::{SCREEN_ASPECT, SCREEN_HEIGHT, SCREEN_WIDTH};
|
||||
use crate::gameplay::camera::MainCamera;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct DisplayScreen;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct DisplayImage;
|
||||
|
||||
fn spawn_virtual_screen(mut commands: Commands, mut images: ResMut<Assets<Image>>) {
|
||||
let game_image = images.add(Image::new_target_texture(
|
||||
SCREEN_WIDTH as u32,
|
||||
SCREEN_HEIGHT as u32,
|
||||
TextureFormat::Rgba8Unorm,
|
||||
Some(TextureFormat::Rgba8UnormSrgb),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
Camera2d,
|
||||
MainCamera,
|
||||
IsDefaultUiCamera,
|
||||
Camera {
|
||||
order: -1,
|
||||
clear_color: Color::BLACK.into(),
|
||||
..default()
|
||||
},
|
||||
RenderTarget::Image(game_image.clone().into()),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
DisplayScreen,
|
||||
PrimaryEguiContext, // egui render over
|
||||
Camera2d,
|
||||
Camera {
|
||||
order: 0,
|
||||
clear_color: Color::BLACK.into(),
|
||||
..default()
|
||||
},
|
||||
RenderLayers::layer(1),
|
||||
));
|
||||
|
||||
commands.spawn((
|
||||
DisplayImage,
|
||||
Sprite::from_image(game_image),
|
||||
Transform::default(),
|
||||
Visibility::Visible,
|
||||
RenderLayers::layer(1),
|
||||
));
|
||||
}
|
||||
|
||||
fn fit_display_screen(
|
||||
window: Single<&Window>,
|
||||
mut sprite: Single<&mut Sprite, With<DisplayImage>>,
|
||||
) {
|
||||
let scale_factor = window.scale_factor();
|
||||
|
||||
let win = Vec2::new(
|
||||
window.physical_width() as f32 / scale_factor,
|
||||
window.physical_height() as f32 / scale_factor,
|
||||
);
|
||||
|
||||
let size = if win.x / win.y > SCREEN_ASPECT {
|
||||
Vec2::new(win.y * SCREEN_ASPECT, win.y)
|
||||
} else {
|
||||
Vec2::new(win.x, win.x / SCREEN_ASPECT)
|
||||
};
|
||||
|
||||
sprite.custom_size = Some(size);
|
||||
}
|
||||
|
||||
pub struct ScreenPlugin;
|
||||
|
||||
impl Plugin for ScreenPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, spawn_virtual_screen)
|
||||
.add_systems(Update, fit_display_screen);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
pub mod game_over;
|
||||
pub mod main_menu;
|
||||
|
||||
#[derive(States, Default, Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum GameState {
|
||||
#[default]
|
||||
MainMenu,
|
||||
InGame,
|
||||
GameOver,
|
||||
_SettingsMenu,
|
||||
_EscMenu,
|
||||
}
|
||||
|
||||
pub struct GameStatePlugin;
|
||||
|
||||
impl Plugin for GameStatePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_state::<GameState>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{font::GameFont, gameplay::camera::MainCamera, states::GameState, world::RunSeed};
|
||||
|
||||
// To delete game over's components
|
||||
#[derive(Component)]
|
||||
pub struct GameOver;
|
||||
|
||||
fn game_over(
|
||||
mut commands: Commands,
|
||||
mut main_camera: Single<&mut Camera, With<MainCamera>>,
|
||||
game_font: Res<GameFont>,
|
||||
) {
|
||||
main_camera.is_active = true;
|
||||
|
||||
commands.spawn((
|
||||
GameOver,
|
||||
Node {
|
||||
width: Val::Percent(100.0),
|
||||
height: Val::Percent(100.0),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
flex_direction: FlexDirection::Column,
|
||||
row_gap: Val::Px(30.0),
|
||||
..default()
|
||||
},
|
||||
// Black background
|
||||
BackgroundColor(Color::BLACK),
|
||||
// Texts
|
||||
children![
|
||||
(
|
||||
Text::new("GAME OVER"),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(120.0),
|
||||
..default()
|
||||
},
|
||||
),
|
||||
(
|
||||
Text::new("N new map | R restart | T main menu"),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(40.0),
|
||||
..default()
|
||||
}
|
||||
)
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
fn cleanup_game_over(mut commands: Commands, game_over: Query<Entity, With<GameOver>>) {
|
||||
for entity in game_over {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
// For debug bug same logic on collision (will be renamed)
|
||||
fn game_over_input(
|
||||
input: Res<ButtonInput<KeyCode>>,
|
||||
mut run_seed: ResMut<RunSeed>,
|
||||
mut next_state: ResMut<NextState<GameState>>,
|
||||
) {
|
||||
if input.just_pressed(KeyCode::KeyN) {
|
||||
// New seed
|
||||
run_seed.0 = rand::random::<u64>();
|
||||
next_state.set(GameState::InGame);
|
||||
} else if input.just_pressed(KeyCode::KeyR) {
|
||||
// Same seed
|
||||
next_state.set(GameState::InGame);
|
||||
} else if input.just_pressed(KeyCode::KeyT) {
|
||||
// Return to the Main Menu
|
||||
next_state.set(GameState::MainMenu);
|
||||
}
|
||||
}
|
||||
|
||||
pub struct GameOverPlugin;
|
||||
|
||||
impl Plugin for GameOverPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::GameOver), game_over)
|
||||
.add_systems(
|
||||
Update,
|
||||
game_over_input.run_if(in_state(GameState::GameOver)),
|
||||
)
|
||||
.add_systems(OnExit(GameState::GameOver), cleanup_game_over);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,111 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{font::GameFont, gameplay::camera::MainCamera, states::GameState};
|
||||
|
||||
// To delete menu's components
|
||||
#[derive(Component)]
|
||||
pub struct MainMenu;
|
||||
|
||||
fn main_menu(mut commands: Commands, game_font: Res<GameFont>) {
|
||||
commands.spawn((
|
||||
MainMenu,
|
||||
Node {
|
||||
width: Val::Percent(100.0),
|
||||
height: Val::Percent(100.0),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
flex_direction: FlexDirection::Column,
|
||||
row_gap: Val::Px(30.0),
|
||||
..default()
|
||||
},
|
||||
// Black background
|
||||
BackgroundColor(Color::BLACK),
|
||||
// Texts
|
||||
children![
|
||||
(
|
||||
Text::new("DOWN INTO"),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(100.0),
|
||||
..default()
|
||||
},
|
||||
Node {
|
||||
margin: UiRect::bottom(Val::Px(-30.0)),
|
||||
..default()
|
||||
},
|
||||
),
|
||||
(
|
||||
Text::new("THE VOID"),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(100.0),
|
||||
..default()
|
||||
},
|
||||
Node {
|
||||
margin: UiRect::bottom(Val::Px(40.0)),
|
||||
..default()
|
||||
},
|
||||
),
|
||||
(
|
||||
Node {
|
||||
flex_direction: FlexDirection::Row,
|
||||
..default()
|
||||
},
|
||||
children![
|
||||
(
|
||||
Text::new("Press "),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(40.0),
|
||||
..default()
|
||||
},
|
||||
),
|
||||
(
|
||||
Text::new("Enter"),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(40.0),
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::srgb(1.0, 1.0, 0.0)),
|
||||
),
|
||||
(
|
||||
Text::new(" to fall"),
|
||||
TextFont {
|
||||
font: FontSource::Handle(game_font.0.clone()),
|
||||
font_size: FontSize::Px(40.0),
|
||||
..default()
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
|
||||
// Wait player to press enter for starting the fall
|
||||
fn menu_input(input: Res<ButtonInput<KeyCode>>, mut next_state: ResMut<NextState<GameState>>) {
|
||||
if input.just_pressed(KeyCode::Enter) {
|
||||
next_state.set(GameState::InGame);
|
||||
}
|
||||
}
|
||||
|
||||
// Clean all menu's entities
|
||||
fn cleanup_menu(mut commands: Commands, menu: Query<Entity, With<MainMenu>>) {
|
||||
for entity in menu {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
fn reset_camera(mut main_camera: Single<&mut Camera, With<MainCamera>>) {
|
||||
main_camera.is_active = true;
|
||||
}
|
||||
|
||||
pub struct MainMenuPlugin;
|
||||
|
||||
impl Plugin for MainMenuPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(OnEnter(GameState::MainMenu), (main_menu, reset_camera))
|
||||
.add_systems(Update, menu_input.run_if(in_state(GameState::MainMenu)))
|
||||
.add_systems(OnExit(GameState::MainMenu), cleanup_menu);
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
config::{CAMERAE_OFFSET, CHUNK_HEIGHT, MARGIN_ABOVE, MARGIN_BELLOW, SCREEN_HEIGHT},
|
||||
gameplay::player::Player,
|
||||
states::GameState,
|
||||
world::terrain::TerrainSettings,
|
||||
};
|
||||
|
||||
pub mod background;
|
||||
pub mod grid;
|
||||
pub mod obstacle;
|
||||
pub mod terrain;
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Chunk {
|
||||
pub id: i64,
|
||||
}
|
||||
|
||||
#[derive(Resource)]
|
||||
pub struct RunSeed(pub u64);
|
||||
|
||||
fn stream_world(
|
||||
player: Single<&Transform, With<Player>>,
|
||||
entities: Query<(Entity, &Chunk)>,
|
||||
mut commands: Commands,
|
||||
run_seed: Res<RunSeed>,
|
||||
terrain_settings: Res<TerrainSettings>, // Debug
|
||||
) {
|
||||
let (min_id, max_id) = visible_chunk_range(player.translation.y);
|
||||
|
||||
let existing_ids: Vec<i64> = entities.iter().map(|(_, chunk)| chunk.id).collect();
|
||||
|
||||
for (entity, chunk) in entities {
|
||||
// Out of bounds implies despawn
|
||||
if chunk.id < min_id || chunk.id > max_id {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
for id in min_id..=max_id {
|
||||
if !existing_ids.contains(&id) {
|
||||
spawn_chunk(
|
||||
&mut commands,
|
||||
id,
|
||||
run_seed.0,
|
||||
*terrain_settings, // Debug
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Bounds of chunk's ids to be generated
|
||||
fn visible_chunk_range(player_y: f32) -> (i64, i64) {
|
||||
let bottom = player_y - CAMERAE_OFFSET - SCREEN_HEIGHT / 2.0 - MARGIN_BELLOW;
|
||||
let top = player_y - CAMERAE_OFFSET + SCREEN_HEIGHT / 2.0 + MARGIN_ABOVE;
|
||||
(
|
||||
(bottom / CHUNK_HEIGHT).floor() as i64,
|
||||
(top / CHUNK_HEIGHT).floor() as i64,
|
||||
)
|
||||
}
|
||||
|
||||
fn spawn_chunk(
|
||||
commands: &mut Commands,
|
||||
id: i64,
|
||||
run_seed: u64,
|
||||
terrain_settings: TerrainSettings, // Debug
|
||||
) {
|
||||
crate::world::background::spawn_background_chunk(commands, id);
|
||||
crate::world::obstacle::spawn_obstacle_chunk(commands, id, run_seed, terrain_settings);
|
||||
}
|
||||
|
||||
// Debug
|
||||
fn rebuild_terrain_on_settings_change(
|
||||
mut commands: Commands,
|
||||
terrain_settings: Res<TerrainSettings>,
|
||||
run_seed: Res<RunSeed>, // Debug
|
||||
entities: Query<Entity, With<Chunk>>,
|
||||
) {
|
||||
if terrain_settings.is_changed() || run_seed.is_changed() {
|
||||
for entity in entities {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cleanup_chunk(mut commands: Commands, entities: Query<Entity, With<Chunk>>) {
|
||||
for entity in entities {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorldPlugin;
|
||||
|
||||
impl Plugin for WorldPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(RunSeed(rand::random::<u64>()))
|
||||
.add_systems(
|
||||
Update,
|
||||
(rebuild_terrain_on_settings_change, stream_world)
|
||||
.chain()
|
||||
.run_if(in_state(GameState::InGame)),
|
||||
)
|
||||
.add_systems(OnExit(GameState::InGame), cleanup_chunk);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
config::{
|
||||
CELL_SIZE, CHUNK_HEIGHT, CHUNK_ROWS, HALF_TERRAIN_WIDTH, TERRAIN_COLS, TERRAIN_WIDTH,
|
||||
},
|
||||
world::Chunk,
|
||||
};
|
||||
|
||||
const GRID_COLOR: Color = Color::srgb(0.22, 0.25, 0.30);
|
||||
const EDGE_COLOR: Color = Color::srgb(0.40, 0.45, 0.55);
|
||||
|
||||
const LINE_THICKNESS: f32 = 1.0;
|
||||
const CHUNK_BORDER_THICKNESS: f32 = 3.0;
|
||||
|
||||
// Thin line sprite
|
||||
fn spawn_line(commands: &mut Commands, id: i64, center: Vec2, size: Vec2, color: Color) {
|
||||
commands.spawn((
|
||||
Chunk { id },
|
||||
Sprite::from_color(color, size),
|
||||
Transform::from_xyz(center.x, center.y, 0.0),
|
||||
));
|
||||
}
|
||||
|
||||
// Grid lines background
|
||||
pub fn spawn_background_chunk(commands: &mut Commands, id: i64) {
|
||||
let y0 = CHUNK_HEIGHT * id as f32;
|
||||
let x0 = -HALF_TERRAIN_WIDTH;
|
||||
|
||||
// Horizontal lines
|
||||
for row in 0..=CHUNK_ROWS {
|
||||
let is_edge = row == 0 || row == CHUNK_ROWS;
|
||||
spawn_line(
|
||||
commands,
|
||||
id,
|
||||
Vec2::new(0.0, y0 + row as f32 * CELL_SIZE),
|
||||
Vec2::new(
|
||||
TERRAIN_WIDTH,
|
||||
if is_edge {
|
||||
CHUNK_BORDER_THICKNESS
|
||||
} else {
|
||||
LINE_THICKNESS
|
||||
},
|
||||
),
|
||||
if is_edge { EDGE_COLOR } else { GRID_COLOR },
|
||||
);
|
||||
}
|
||||
|
||||
// Vertical lines
|
||||
for col in 0..=TERRAIN_COLS {
|
||||
let is_edge = col == 0 || col == TERRAIN_COLS;
|
||||
spawn_line(
|
||||
commands,
|
||||
id,
|
||||
Vec2::new(x0 + col as f32 * CELL_SIZE, y0 + CHUNK_HEIGHT / 2.0),
|
||||
Vec2::new(
|
||||
if is_edge {
|
||||
CHUNK_BORDER_THICKNESS
|
||||
} else {
|
||||
LINE_THICKNESS
|
||||
},
|
||||
CHUNK_HEIGHT,
|
||||
),
|
||||
if is_edge { EDGE_COLOR } else { GRID_COLOR },
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::config::{CELL_SIZE, CHUNK_ROWS, TERRAIN_COLS};
|
||||
|
||||
// Cell rectangle
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct GridRect {
|
||||
pub col: i32,
|
||||
pub row: i32,
|
||||
pub width: i32,
|
||||
pub height: i32,
|
||||
}
|
||||
|
||||
impl GridRect {
|
||||
// One cell rectangle
|
||||
pub fn cell(col: i32, row: i32) -> Self {
|
||||
Self {
|
||||
col,
|
||||
row,
|
||||
width: 1,
|
||||
height: 1,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Conversion grid to world
|
||||
pub fn grid_to_world(chunk_id: i64, rect: GridRect) -> (Vec2, Vec2) {
|
||||
let global_row = chunk_id * CHUNK_ROWS as i64 + rect.row as i64;
|
||||
|
||||
let center = Vec2::new(
|
||||
(rect.col as f32 + rect.width as f32 / 2.0 - TERRAIN_COLS as f32 / 2.0) * CELL_SIZE,
|
||||
(global_row as f32 + rect.height as f32 / 2.0) * CELL_SIZE,
|
||||
);
|
||||
|
||||
let size = Vec2::new(
|
||||
rect.width as f32 * CELL_SIZE,
|
||||
rect.height as f32 * CELL_SIZE,
|
||||
);
|
||||
|
||||
(center, size)
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::{
|
||||
config::{CHUNK_ROWS, TERRAIN_COLS},
|
||||
gameplay::collision::Collider,
|
||||
world::{
|
||||
Chunk,
|
||||
grid::{GridRect, grid_to_world},
|
||||
terrain::{Terrain, TerrainSettings},
|
||||
},
|
||||
};
|
||||
|
||||
const OBSTACLE_COLOR: Color = Color::srgb(0.1, 0.7, 0.3);
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct Obstacle;
|
||||
|
||||
pub fn spawn_obstacle_chunk(
|
||||
commands: &mut Commands,
|
||||
id: i64,
|
||||
run_seed: u64,
|
||||
terrain_settings: TerrainSettings, // Debug
|
||||
) {
|
||||
// No blocks in chunk 0
|
||||
if id >= -1 {
|
||||
return;
|
||||
}
|
||||
|
||||
let terrain = Terrain::new(run_seed, terrain_settings);
|
||||
for row in 0..CHUNK_ROWS {
|
||||
let global_row = id * CHUNK_ROWS as i64 + row as i64;
|
||||
for col in 0..TERRAIN_COLS {
|
||||
if terrain.solid_at(col as i64, global_row, terrain_settings) {
|
||||
let (center, size) = grid_to_world(id, GridRect::cell(col, row));
|
||||
commands.spawn((
|
||||
Chunk { id },
|
||||
Obstacle,
|
||||
Collider { size },
|
||||
Sprite::from_color(OBSTACLE_COLOR, size),
|
||||
Transform::from_xyz(center.x, center.y, 1.0),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
use bevy::{app::Plugin, ecs::resource::Resource};
|
||||
use fastnoise_lite::{FastNoiseLite, FractalType, NoiseType};
|
||||
|
||||
const THRESHOLD: f32 = 0.0;
|
||||
const FREQUENCY: f32 = 0.1;
|
||||
const OCTAVES: i32 = 3;
|
||||
|
||||
pub struct Terrain {
|
||||
noise: FastNoiseLite,
|
||||
}
|
||||
|
||||
#[derive(Resource, Clone, Copy)]
|
||||
pub struct TerrainSettings {
|
||||
pub threshold: f32,
|
||||
pub frequency: f32,
|
||||
pub octaves: i32,
|
||||
}
|
||||
|
||||
impl Default for TerrainSettings {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
threshold: THRESHOLD,
|
||||
frequency: FREQUENCY,
|
||||
octaves: OCTAVES,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Terrain {
|
||||
pub fn new(seed: u64, terrain_settings: TerrainSettings) -> Self {
|
||||
let mut noise = FastNoiseLite::with_seed(seed as i32);
|
||||
noise.set_noise_type(Some(NoiseType::OpenSimplex2));
|
||||
noise.set_frequency(Some(terrain_settings.frequency));
|
||||
noise.set_fractal_type(Some(FractalType::FBm));
|
||||
noise.set_fractal_octaves(Some(terrain_settings.octaves));
|
||||
Self { noise }
|
||||
}
|
||||
|
||||
pub fn solid_at(&self, col: i64, row: i64, terrain_settings: TerrainSettings) -> bool {
|
||||
self.noise.get_noise_2d(col as f32, row as f32) > terrain_settings.threshold
|
||||
}
|
||||
}
|
||||
|
||||
pub struct TerrainPlugin;
|
||||
|
||||
impl Plugin for TerrainPlugin {
|
||||
fn build(&self, app: &mut bevy::app::App) {
|
||||
app.init_resource::<TerrainSettings>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user