From 8b54bfe0573724f677b4d6708e96eec9c52ac688 Mon Sep 17 00:00:00 2001 From: alexander Date: Mon, 26 Apr 2021 00:51:14 -0500 Subject: [PATCH 01/16] added clone to Evaluator trait (#18) Co-authored-by: doomy <2640792-_doomy@users.noreply.gitlab.com> --- src/evaluators.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evaluators.rs b/src/evaluators.rs index 0d964f7..65489b6 100644 --- a/src/evaluators.rs +++ b/src/evaluators.rs @@ -5,7 +5,7 @@ Utilities for turning values within a certain range into different curves. /** Trait that any evaluators must implement. Must return an `f32` value between `0.0..=100.0`. */ -pub trait Evaluator: std::fmt::Debug + Sync + Send { +pub trait Evaluator: std::fmt::Debug + Sync + Send + Clone { fn evaluate(&self, value: f32) -> f32; } From 55848a7d434a9810a41cba1a333c4db0b0a4e84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Sun, 25 Apr 2021 23:02:34 -0700 Subject: [PATCH 02/16] Revert "added clone to Evaluator trait (#18)" This reverts commit db52b7c40c6fa52740fdb46ba93c111c12f178e8. Oops, this prevents making trait objects. --- src/evaluators.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/evaluators.rs b/src/evaluators.rs index 65489b6..0d964f7 100644 --- a/src/evaluators.rs +++ b/src/evaluators.rs @@ -5,7 +5,7 @@ Utilities for turning values within a certain range into different curves. /** Trait that any evaluators must implement. Must return an `f32` value between `0.0..=100.0`. */ -pub trait Evaluator: std::fmt::Debug + Sync + Send + Clone { +pub trait Evaluator: std::fmt::Debug + Sync + Send { fn evaluate(&self, value: f32) -> f32; } From db487a699ac3b332f7d755c875b60d833203e9ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kat=20March=C3=A1n?= Date: Sun, 18 Apr 2021 18:37:47 -0700 Subject: [PATCH 03/16] start work on a more involved, graphical example --- Cargo.toml | 3 + assets/LICENSE_ASSETS | 23 ++ assets/textures/dwarf.png | Bin 0 -> 567 bytes assets/textures/square-dwarf.png | Bin 0 -> 567 bytes assets/textures/square-floor.png | Bin 0 -> 297 bytes assets/textures/square-floor_alt.png | Bin 0 -> 302 bytes assets/textures/square-wall.png | Bin 0 -> 618 bytes examples/dorfs.rs | 433 +++++++++++++++++++++++++++ 8 files changed, 459 insertions(+) create mode 100644 assets/LICENSE_ASSETS create mode 100644 assets/textures/dwarf.png create mode 100644 assets/textures/square-dwarf.png create mode 100644 assets/textures/square-floor.png create mode 100644 assets/textures/square-floor_alt.png create mode 100644 assets/textures/square-wall.png create mode 100644 examples/dorfs.rs diff --git a/Cargo.toml b/Cargo.toml index 389320f..f71c806 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,3 +14,6 @@ homepage = "https://github.com/zkat/big-brain" [dependencies] bevy = "0.5.0" +[dev-dependencies] +bevy_tilemap = "0.4.0" +rand = "0.8.3" diff --git a/assets/LICENSE_ASSETS b/assets/LICENSE_ASSETS new file mode 100644 index 0000000..efaa5e9 --- /dev/null +++ b/assets/LICENSE_ASSETS @@ -0,0 +1,23 @@ +The assets in this directory are from https://github.com/joshuajbouw/bevy_tilemap/tree/e9f4ec8/examples/assets/textures and have the following license: + +MIT License + +Copyright (c) 2020 Joshua J. Bouw + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/assets/textures/dwarf.png b/assets/textures/dwarf.png new file mode 100644 index 0000000000000000000000000000000000000000..ba7625498ef068e91a644e5c3ce08d23e36cc55a GIT binary patch literal 567 zcmV-70?7S|P)Px$@kvBMR9J=Wl|M)uQ5?rVDUzX`EF2OnSS}?tB6k|lC3O{N7Z+)1HkWAU4C3JI zpRG#+;^HE7CkxR4Orp=-?0v&mr9NE?&%gF`M_9-n-xLz3=ya_kQmn zAmFtV(p_Mgws6MB=Xve*jdbY>$EHUfAFd-_YD8(FW!l0c+`!rTLE9!;E@~zIQWHv_ z;P25t-F-V_z%p%-OZQ>K!vItZHF}aM-`wG;`OX_~s1|Af^dwVM_I}ARAm{C(+y#zc zWcD|9bcn+wh+k_%O zAF|v=JWPl$h+-Ll>&iAxE+BMFylE!xe(RVq>JfKDuPfV#_q!PJFqz3ypk6KaZK-X* zExt0-%g*H%0N;Mzdh(2TSekKInd#Lw;adSeV#a9GShY}NV)erFOw~kF1MY+6u(;VT zThcAQxY-XtB9oQpLKUSpObzVI@zn`Hw=DnF$qlK2eReME9gxUmwf>e*3>=^5L&H<^ z@-JtZw#b+MdvYS5A1|lISV!7WWfOS-|LDjm8fe6h*3-Uk-2t$?dOPx$@kvBMR9J=Wl|M)uQ5?rVDUzX`EF2OnSS}?tB6k|lC3O{N7Z+)1HkWAU4C3JI zpRG#+;^HE7CkxR4Orp=-?0v&mr9NE?&%gF`M_9-n-xLz3=ya_kQmn zAmFtV(p_Mgws6MB=Xve*jdbY>$EHUfAFd-_YD8(FW!l0c+`!rTLE9!;E@~zIQWHv_ z;P25t-F-V_z%p%-OZQ>K!vItZHF}aM-`wG;`OX_~s1|Af^dwVM_I}ARAm{C(+y#zc zWcD|9bcn+wh+k_%O zAF|v=JWPl$h+-Ll>&iAxE+BMFylE!xe(RVq>JfKDuPfV#_q!PJFqz3ypk6KaZK-X* zExt0-%g*H%0N;Mzdh(2TSekKInd#Lw;adSeV#a9GShY}NV)erFOw~kF1MY+6u(;VT zThcAQxY-XtB9oQpLKUSpObzVI@zn`Hw=DnF$qlK2eReME9gxUmwf>e*3>=^5L&H<^ z@-JtZw#b+MdvYS5A1|lISV!7WWfOS-|LDjm8fe6h*3-Uk-2t$?dO>XJjCZ-;EEj_=$s_yr}>qo2`BpiAgPaL=$H)Vm8 zm=~{#`ICf%4=PS64f=5>8GoEvV zP0T0Ot}0Bu&v>3y#q^|vgd4ZgDaNXsO_v#;sF);uSukDKLe{}AX7b|pCmIX3+-;Ea t(%@4#R*+O>{ez)OW1&Su(BYGe4C{ow-k3e~S`PFsgQu&X%Q~loCIHI$a*qH2 literal 0 HcmV?d00001 diff --git a/assets/textures/square-floor_alt.png b/assets/textures/square-floor_alt.png new file mode 100644 index 0000000000000000000000000000000000000000..1898f877fc7caab687e8e3578614f122693f6dc8 GIT binary patch literal 302 zcmV+}0nz@6P)Px#=t)FDR9J;$Ts@`gKf?e5rh&A4a5>=hjZXvX08tG-vJ7~A;}cHDZ$J2&cn1&z zh%pcuc-o5+RKr54f#il93=Ez`hz#(>D>(q4S#${je9?q84Nw}dq=3Ph21Xq~2_Q8G z!5u(qDMv1tyzmSPpOMt|!0Q{IsG3Vijsj|D(czZ}spPx%BuPX;R9J<*SFw)5FbsWEmDnnzs_FyH+qMrUN3HH-Dr{?c3Uq{`boa-ib()>YTc*?=XQ;h)?VcCkrWy1#jKxGo%qqpAfg20bUE$vGD8tWiSQGZQwqk z`kD!_3J?IQV=)uK#c`3uL3X-F;VAFKrFa+9rLH48uzBGzZ;Rs_($N4FR2Dn zj$qAR9SbxV7AGu;P-jA!vi>s628`HiDeI&<7J%#hwd@J%P)Z^`K6}3w5~xi-QlvF) zdjT48XzYqjz7pEJNo(pzCP`B!Un{ufA1y*{(j_4wfgG{zTAlXiCpDuGDKMQEDc_GN zA0))N*a8g{Tn@0(P6A^mDfiE{MF~DLl8BIxX0!Od0NRyzm%TG5umAu607*qoM6N<$ Ef*TbIm;e9( literal 0 HcmV?d00001 diff --git a/examples/dorfs.rs b/examples/dorfs.rs new file mode 100644 index 0000000..a9fea14 --- /dev/null +++ b/examples/dorfs.rs @@ -0,0 +1,433 @@ +/* +This example is based on one from bevy_tilemap, found here: https://github.com/joshuajbouw/bevy_tilemap/blob/9e19adb/examples/examples/random_dungeon.rs + +It includes the following license, reproduced here in accordance with its requirements: + +MIT License + +Copyright (c) 2020 Joshua J. Bouw + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +/*! +This is a more involved big-brain example. In this example, we're going to define an AI "Player" which will autonomously explore a randomized dungeon. They will also react to various situations they come across, such as enemies, power-ups, and their own personal needs (like going to the bathroom). +*/ + +use bevy::{ + asset::LoadState, + prelude::*, + render::camera::Camera, + sprite::{TextureAtlas, TextureAtlasBuilder}, + utils::HashSet, + window::WindowMode, +}; +use bevy_tilemap::prelude::*; +use big_brain::prelude::*; +use rand::Rng; + +fn main() { + App::build() + .insert_resource(WindowDescriptor { + title: "Endless Dungeon".to_string(), + width: 1024., + height: 1024., + vsync: false, + resizable: true, + mode: WindowMode::Windowed, + ..Default::default() + }) + .init_resource::() + .init_resource::() + .add_plugins(DefaultPlugins) + .add_plugins(TilemapDefaultPlugins) + // Here's the first important thing for you to do: include the plugin! + // If big-brain doesn't seem to be working at all, this might be what + // you're missing! + .add_plugin(BigBrainPlugin) + .add_startup_system(setup.system()) + .add_system(load.system()) + .add_system(build_random_dungeon.system()) + .add_system(meander_action.system()) + .run() +} + +// Here we have a pretty typical bundle, except we've added a ThinkerBuilder to it. +#[derive(Bundle)] +struct PlayerBundle { + player: Player, + position: Position, + render: Render, + thinker: ThinkerBuilder, +} + +// Let's define our "default" action, which will be used whenever there's nothing in particular getting our dorf's attention. +#[derive(Default, Debug, Clone)] +struct MeanderBuilder; + +#[derive(Debug, Default, Clone)] +struct Meander { + dx: i32, + dy: i32, +} + +impl Meander { + fn build() -> MeanderBuilder { + MeanderBuilder + } +} + +impl ActionBuilder for MeanderBuilder { + fn build(&self, cmd: &mut Commands, action: Entity, _actor: Entity) { + cmd.entity(action).insert(Meander::default()); + } +} + +fn meander_action( + mut game_state: ResMut, + time: Res