├── .gitignore ├── src └── main.rs ├── github-images └── cover.jpg ├── InstallingRust ├── HelloWorld │ ├── src │ │ └── main.rs │ └── Cargo.toml ├── Clippy │ ├── src │ │ └── main.rs │ └── Cargo.toml └── ClippyFixed │ ├── src │ └── main.rs │ └── Cargo.toml ├── Loot ├── loot_tables │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ ├── camera.rs │ │ └── map_builder │ │ │ ├── rooms.rs │ │ │ ├── empty.rs │ │ │ └── themes.rs │ └── Cargo.toml └── better_combat │ ├── resources │ ├── dungeonfont.png │ └── terminal8x8.png │ ├── src │ ├── turn_state.rs │ ├── systems │ │ ├── fov.rs │ │ └── entity_render.rs │ ├── camera.rs │ └── map_builder │ │ ├── rooms.rs │ │ ├── empty.rs │ │ └── themes.rs │ └── Cargo.toml ├── WhatCanISee ├── fov │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── movement.rs │ │ │ ├── hud.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ └── camera.rs │ └── Cargo.toml ├── memory │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── hud.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ └── camera.rs │ └── Cargo.toml └── eyesight │ ├── resources │ ├── dungeonfont.png │ └── terminal8x8.png │ ├── src │ ├── turn_state.rs │ ├── systems │ │ ├── fov.rs │ │ ├── hud.rs │ │ ├── entity_render.rs │ │ └── combat.rs │ └── camera.rs │ └── Cargo.toml ├── MapTheming └── themed │ ├── resources │ ├── dungeonfont.png │ └── terminal8x8.png │ ├── src │ ├── turn_state.rs │ ├── systems │ │ ├── fov.rs │ │ ├── hud.rs │ │ ├── entity_render.rs │ │ └── combat.rs │ ├── camera.rs │ └── map_builder │ │ ├── themes.rs │ │ ├── rooms.rs │ │ └── empty.rs │ └── Cargo.toml ├── FirstStepsWithRust ├── inline_closure_include.rs ├── hello_yourname │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── treehouse_guestlist │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── hello_yourname_function │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── treehouse_guestlist_enum │ └── Cargo.toml ├── treehouse_guestlist_struct │ └── Cargo.toml ├── treehouse_guestlist_trim │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── treehouse_guestlist_vector │ └── Cargo.toml └── treehouse_guestlist_problem │ ├── Cargo.toml │ └── src │ └── main.rs ├── TurnBasedGames ├── intent │ ├── resources │ │ └── dungeonfont.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── end_turn.rs │ │ │ ├── entity_render.rs │ │ │ ├── collisions.rs │ │ │ ├── random_move.rs │ │ │ ├── movement.rs │ │ │ ├── player_input.rs │ │ │ └── map_render.rs │ │ ├── components.rs │ │ ├── camera.rs │ │ ├── spawner.rs │ │ └── map.rs │ └── Cargo.toml ├── turnbased │ ├── resources │ │ └── dungeonfont.png │ ├── src │ │ ├── turn_state.rs │ │ ├── components.rs │ │ ├── systems │ │ │ ├── end_turn.rs │ │ │ ├── entity_render.rs │ │ │ ├── collisions.rs │ │ │ └── random_move.rs │ │ ├── camera.rs │ │ └── spawner.rs │ └── Cargo.toml └── wandering │ ├── resources │ └── dungeonfont.png │ ├── Cargo.toml │ └── src │ ├── components.rs │ ├── systems │ ├── mod.rs │ ├── entity_render.rs │ ├── collisions.rs │ └── random_move.rs │ ├── camera.rs │ └── spawner.rs ├── HealthSimpleMelee ├── combat │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── end_turn.rs │ │ │ ├── entity_render.rs │ │ │ ├── movement.rs │ │ │ ├── combat.rs │ │ │ ├── hud.rs │ │ │ └── map_render.rs │ │ ├── camera.rs │ │ └── components.rs │ └── Cargo.toml ├── health │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── end_turn.rs │ │ │ ├── entity_render.rs │ │ │ ├── collisions.rs │ │ │ ├── movement.rs │ │ │ ├── random_move.rs │ │ │ ├── player_input.rs │ │ │ ├── hud.rs │ │ │ └── map_render.rs │ │ ├── components.rs │ │ └── camera.rs │ └── Cargo.toml └── healing │ ├── resources │ ├── dungeonfont.png │ └── terminal8x8.png │ ├── src │ ├── turn_state.rs │ ├── systems │ │ ├── end_turn.rs │ │ ├── entity_render.rs │ │ ├── movement.rs │ │ ├── combat.rs │ │ ├── hud.rs │ │ └── map_render.rs │ ├── camera.rs │ └── components.rs │ └── Cargo.toml ├── WinningAndLosing ├── losing │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── entity_render.rs │ │ │ ├── movement.rs │ │ │ ├── end_turn.rs │ │ │ ├── hud.rs │ │ │ └── combat.rs │ │ ├── camera.rs │ │ └── components.rs │ └── Cargo.toml ├── winning │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── entity_render.rs │ │ │ ├── movement.rs │ │ │ ├── hud.rs │ │ │ └── combat.rs │ │ └── camera.rs │ └── Cargo.toml └── gauntlet │ ├── resources │ ├── dungeonfont.png │ └── terminal8x8.png │ ├── src │ ├── turn_state.rs │ ├── systems │ │ ├── end_turn.rs │ │ ├── entity_render.rs │ │ ├── movement.rs │ │ ├── combat.rs │ │ └── hud.rs │ ├── camera.rs │ └── components.rs │ └── Cargo.toml ├── DeeperDungeons └── more_levels │ ├── resources │ ├── dungeonfont.png │ └── terminal8x8.png │ ├── src │ ├── turn_state.rs │ ├── systems │ │ ├── fov.rs │ │ ├── entity_render.rs │ │ └── combat.rs │ ├── camera.rs │ └── map_builder │ │ ├── rooms.rs │ │ ├── empty.rs │ │ └── themes.rs │ └── Cargo.toml ├── FirstGameFlappyAscii ├── flappy_bonus │ ├── resources │ │ └── flappy32.png │ └── Cargo.toml ├── hello_bterm │ ├── Cargo.toml │ └── src │ │ └── main.rs ├── flappy_dragon │ └── Cargo.toml ├── flappy_player │ └── Cargo.toml └── flappy_states │ └── Cargo.toml ├── MoreInterestingDungeons ├── prefab │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── hud.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ ├── map_builder │ │ │ ├── rooms.rs │ │ │ └── empty.rs │ │ └── camera.rs │ └── Cargo.toml ├── traits │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── hud.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ ├── camera.rs │ │ └── map_builder │ │ │ └── empty.rs │ └── Cargo.toml ├── cellular │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── hud.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ ├── map_builder │ │ │ ├── rooms.rs │ │ │ └── empty.rs │ │ └── camera.rs │ └── Cargo.toml ├── drunkard │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── hud.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ ├── map_builder │ │ │ ├── rooms.rs │ │ │ └── empty.rs │ │ └── camera.rs │ └── Cargo.toml ├── traits_rooms │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── hud.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ ├── camera.rs │ │ └── map_builder │ │ │ ├── rooms.rs │ │ │ └── empty.rs │ └── Cargo.toml └── output_harness │ ├── Cargo.toml │ └── src │ ├── main.rs │ └── map_builder │ └── empty.rs ├── InventoryAndPowerUps ├── carrying_items │ ├── resources │ │ ├── dungeonfont.png │ │ └── terminal8x8.png │ ├── src │ │ ├── turn_state.rs │ │ ├── systems │ │ │ ├── fov.rs │ │ │ ├── entity_render.rs │ │ │ └── combat.rs │ │ ├── camera.rs │ │ └── map_builder │ │ │ ├── themes.rs │ │ │ ├── rooms.rs │ │ │ └── empty.rs │ └── Cargo.toml └── potions_and_scrolls │ ├── resources │ ├── dungeonfont.png │ └── terminal8x8.png │ ├── src │ ├── turn_state.rs │ ├── systems │ │ ├── fov.rs │ │ ├── hud.rs │ │ ├── entity_render.rs │ │ └── combat.rs │ ├── camera.rs │ └── map_builder │ │ ├── themes.rs │ │ ├── rooms.rs │ │ └── empty.rs │ └── Cargo.toml ├── EntitiesComponentsAndSystems ├── dungeonecs │ ├── resources │ │ └── dungeonfont.png │ ├── Cargo.toml │ └── src │ │ ├── components.rs │ │ ├── systems │ │ ├── mod.rs │ │ ├── entity_render.rs │ │ └── collisions.rs │ │ ├── camera.rs │ │ └── spawner.rs └── playerecs │ ├── resources │ └── dungeonfont.png │ ├── src │ ├── components.rs │ ├── spawner.rs │ ├── systems │ │ ├── mod.rs │ │ └── entity_render.rs │ └── camera.rs │ └── Cargo.toml └── BasicDungeonCrawler ├── dungeon_crawl_graphics ├── resources │ └── dungeonfont.png ├── Cargo.toml └── src │ └── camera.rs ├── dungeon_crawl_rooms └── Cargo.toml ├── dungeon_crawl_map ├── Cargo.toml └── src │ └── main.rs └── dungeon_crawl_player └── Cargo.toml /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Workspace: you wanted to run a member."); 3 | } -------------------------------------------------------------------------------- /github-images/cover.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/github-images/cover.jpg -------------------------------------------------------------------------------- /InstallingRust/HelloWorld/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { // (1) 2 | println!("Hello, world!"); // (2) 3 | } 4 | -------------------------------------------------------------------------------- /Loot/loot_tables/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/Loot/loot_tables/resources/dungeonfont.png -------------------------------------------------------------------------------- /Loot/loot_tables/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/Loot/loot_tables/resources/terminal8x8.png -------------------------------------------------------------------------------- /WhatCanISee/fov/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WhatCanISee/fov/resources/dungeonfont.png -------------------------------------------------------------------------------- /WhatCanISee/fov/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WhatCanISee/fov/resources/terminal8x8.png -------------------------------------------------------------------------------- /Loot/better_combat/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/Loot/better_combat/resources/dungeonfont.png -------------------------------------------------------------------------------- /Loot/better_combat/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/Loot/better_combat/resources/terminal8x8.png -------------------------------------------------------------------------------- /MapTheming/themed/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MapTheming/themed/resources/dungeonfont.png -------------------------------------------------------------------------------- /MapTheming/themed/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MapTheming/themed/resources/terminal8x8.png -------------------------------------------------------------------------------- /WhatCanISee/memory/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WhatCanISee/memory/resources/dungeonfont.png -------------------------------------------------------------------------------- /WhatCanISee/memory/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WhatCanISee/memory/resources/terminal8x8.png -------------------------------------------------------------------------------- /FirstStepsWithRust/inline_closure_include.rs: -------------------------------------------------------------------------------- 1 | fn check_visitor_name(visitor: &Visitor, name: &String) -> bool { 2 | return visitor.name == name; 3 | } -------------------------------------------------------------------------------- /TurnBasedGames/intent/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/TurnBasedGames/intent/resources/dungeonfont.png -------------------------------------------------------------------------------- /WhatCanISee/eyesight/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WhatCanISee/eyesight/resources/dungeonfont.png -------------------------------------------------------------------------------- /WhatCanISee/eyesight/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WhatCanISee/eyesight/resources/terminal8x8.png -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/HealthSimpleMelee/combat/resources/dungeonfont.png -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/HealthSimpleMelee/combat/resources/terminal8x8.png -------------------------------------------------------------------------------- /HealthSimpleMelee/health/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/HealthSimpleMelee/health/resources/dungeonfont.png -------------------------------------------------------------------------------- /HealthSimpleMelee/health/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/HealthSimpleMelee/health/resources/terminal8x8.png -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/TurnBasedGames/turnbased/resources/dungeonfont.png -------------------------------------------------------------------------------- /TurnBasedGames/wandering/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/TurnBasedGames/wandering/resources/dungeonfont.png -------------------------------------------------------------------------------- /WinningAndLosing/losing/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WinningAndLosing/losing/resources/dungeonfont.png -------------------------------------------------------------------------------- /WinningAndLosing/losing/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WinningAndLosing/losing/resources/terminal8x8.png -------------------------------------------------------------------------------- /WinningAndLosing/winning/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WinningAndLosing/winning/resources/dungeonfont.png -------------------------------------------------------------------------------- /WinningAndLosing/winning/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WinningAndLosing/winning/resources/terminal8x8.png -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/DeeperDungeons/more_levels/resources/dungeonfont.png -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/DeeperDungeons/more_levels/resources/terminal8x8.png -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/HealthSimpleMelee/healing/resources/dungeonfont.png -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/HealthSimpleMelee/healing/resources/terminal8x8.png -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WinningAndLosing/gauntlet/resources/dungeonfont.png -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/WinningAndLosing/gauntlet/resources/terminal8x8.png -------------------------------------------------------------------------------- /FirstGameFlappyAscii/flappy_bonus/resources/flappy32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/FirstGameFlappyAscii/flappy_bonus/resources/flappy32.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/prefab/resources/dungeonfont.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/prefab/resources/terminal8x8.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/traits/resources/dungeonfont.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/traits/resources/terminal8x8.png -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn 6 | } -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn 6 | } -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn 6 | } -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn 6 | } -------------------------------------------------------------------------------- /InstallingRust/Clippy/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let MYLIST = [ "One", "Two", "Three" ]; 3 | for i in 0..3 { 4 | println!("{}", MYLIST[i]); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/cellular/resources/dungeonfont.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/cellular/resources/terminal8x8.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/drunkard/resources/dungeonfont.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/drunkard/resources/terminal8x8.png -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn 6 | } -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn 6 | } -------------------------------------------------------------------------------- /InstallingRust/ClippyFixed/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let my_list = [ "One", "Two", "Three" ]; 3 | for num in &my_list { 4 | println!("{}", num); 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/InventoryAndPowerUps/carrying_items/resources/dungeonfont.png -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/InventoryAndPowerUps/carrying_items/resources/terminal8x8.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/traits_rooms/resources/dungeonfont.png -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/MoreInterestingDungeons/traits_rooms/resources/terminal8x8.png -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/EntitiesComponentsAndSystems/dungeonecs/resources/dungeonfont.png -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/playerecs/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/EntitiesComponentsAndSystems/playerecs/resources/dungeonfont.png -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/InventoryAndPowerUps/potions_and_scrolls/resources/dungeonfont.png -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/resources/terminal8x8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/InventoryAndPowerUps/potions_and_scrolls/resources/terminal8x8.png -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver 7 | } -------------------------------------------------------------------------------- /BasicDungeonCrawler/dungeon_crawl_graphics/resources/dungeonfont.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/thebracket/HandsOnRust/HEAD/BasicDungeonCrawler/dungeon_crawl_graphics/resources/dungeonfont.png -------------------------------------------------------------------------------- /WhatCanISee/fov/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /InstallingRust/ClippyFixed/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "clippy_fixed" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | -------------------------------------------------------------------------------- /MapTheming/themed/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /WhatCanISee/eyesight/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /WhatCanISee/memory/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /WinningAndLosing/winning/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /Loot/loot_tables/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory, 8 | NextLevel 9 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory 8 | } -------------------------------------------------------------------------------- /Loot/better_combat/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory, 8 | NextLevel 9 | } -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/turn_state.rs: -------------------------------------------------------------------------------- 1 | #[derive(Copy, Clone, Debug, PartialEq)] 2 | pub enum TurnState { 3 | AwaitingInput, 4 | PlayerTurn, 5 | MonsterTurn, 6 | GameOver, 7 | Victory, 8 | NextLevel 9 | } -------------------------------------------------------------------------------- /FirstGameFlappyAscii/flappy_bonus/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flappy_bonus" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | bracket-lib.workspace = true -------------------------------------------------------------------------------- /FirstGameFlappyAscii/hello_bterm/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_bterm" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | bracket-lib.workspace = true 9 | -------------------------------------------------------------------------------- /FirstGameFlappyAscii/flappy_dragon/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flappy_dragon" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | bracket-lib.workspace = true 9 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dungeonecs" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | [dependencies] 8 | bracket-lib.workspace = true 9 | legion = "=0.3.1" 10 | -------------------------------------------------------------------------------- /InstallingRust/HelloWorld/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello" 3 | version = "0.1.0" 4 | authors = ["Your Name"] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at 8 | # https://doc.rust-lang.org/cargo/reference/manifest.html 9 | 10 | [dependencies] 11 | -------------------------------------------------------------------------------- /InstallingRust/Clippy/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "clippy" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /FirstStepsWithRust/hello_yourname/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_yourname" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /FirstStepsWithRust/hello_yourname/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn main() { 4 | println!("Hello, what's your name?"); 5 | let mut your_name = String::new(); 6 | stdin() 7 | .read_line(&mut your_name) 8 | .expect("Failed to read line"); 9 | println!("Hello, {}", your_name) 10 | } 11 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "treehouse_guestlist" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/playerecs/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, // (1) 6 | pub glyph : FontCharType // (2) 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; // (3) 11 | 12 | 13 | -------------------------------------------------------------------------------- /FirstStepsWithRust/hello_yourname_function/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "hello_yourname_function" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist_enum/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "treehouse_guestlist_enum" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist_struct/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "treehouse_guestlist_struct" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist_trim/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "treehouse_guestlist_trim" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist_vector/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "treehouse_guestlist_vector" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist_problem/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "treehouse_guestlist_problem" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | -------------------------------------------------------------------------------- /WhatCanISee/fov/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "fov" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /FirstGameFlappyAscii/flappy_player/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flappy_player" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | -------------------------------------------------------------------------------- /FirstGameFlappyAscii/flappy_states/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "flappy_states" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | -------------------------------------------------------------------------------- /MapTheming/themed/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "themed" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /WhatCanISee/eyesight/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "eyesight" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" -------------------------------------------------------------------------------- /WhatCanISee/memory/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "memory" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /BasicDungeonCrawler/dungeon_crawl_rooms/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dungeon_crawl_rooms" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true -------------------------------------------------------------------------------- /TurnBasedGames/intent/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "intent" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /WinningAndLosing/losing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "losing" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /BasicDungeonCrawler/dungeon_crawl_map/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dungeon_crawl_map" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "combat" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "healing" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "health" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "turnbased" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wandering" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "gauntlet" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /WinningAndLosing/winning/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "winning" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /BasicDungeonCrawler/dungeon_crawl_player/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dungeon_crawl_player" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "more_levels" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "prefab" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "traits" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /BasicDungeonCrawler/dungeon_crawl_graphics/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "dungeon_crawl_graphics" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "cellular" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "drunkard" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/output_harness/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "output_harness" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | colored = "2" -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/playerecs/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "playerecs" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "carrying_items" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "traits_rooms" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "potions_and_scrolls" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | -------------------------------------------------------------------------------- /Loot/loot_tables/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "loot_tables" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | serde = "1" 13 | ron = "=0.6.1" 14 | -------------------------------------------------------------------------------- /Loot/better_combat/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "better_combat" 3 | version = "0.1.0" 4 | authors = ["Herbert Wolverson "] 5 | edition = "2018" 6 | 7 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 8 | 9 | [dependencies] 10 | bracket-lib.workspace = true 11 | legion = "=0.3.1" 12 | serde = "1" 13 | ron = "=0.6.1" 14 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/playerecs/src/spawner.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub fn spawn_player(ecs : &mut World, pos : Point) { // (1) 4 | ecs.push(// (2) 5 | ( 6 | Player,// (3) 7 | pos, // (4) 8 | Render{// (5) 9 | color: ColorPair::new(WHITE, BLACK), 10 | glyph : to_cp437('@') 11 | } 12 | ) 13 | ); 14 | } 15 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/systems/end_turn.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn end_turn(#[resource] turn_state: &mut TurnState) { 5 | let new_state = match turn_state { 6 | TurnState::AwaitingInput => return, 7 | TurnState::PlayerTurn => TurnState::MonsterTurn, 8 | TurnState::MonsterTurn => TurnState::AwaitingInput 9 | }; 10 | 11 | *turn_state = new_state; 12 | } 13 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/systems/end_turn.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn end_turn(#[resource] turn_state: &mut TurnState) { 5 | let new_state = match turn_state { 6 | TurnState::AwaitingInput => return, 7 | TurnState::PlayerTurn => TurnState::MonsterTurn, 8 | TurnState::MonsterTurn => TurnState::AwaitingInput 9 | }; 10 | 11 | *turn_state = new_state; 12 | } 13 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/end_turn.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn end_turn(#[resource] turn_state: &mut TurnState) { 5 | let new_state = match turn_state { 6 | TurnState::AwaitingInput => return, 7 | TurnState::PlayerTurn => TurnState::MonsterTurn, 8 | TurnState::MonsterTurn => TurnState::AwaitingInput 9 | }; 10 | 11 | *turn_state = new_state; 12 | } 13 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/systems/end_turn.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn end_turn(#[resource] turn_state: &mut TurnState) { 5 | let new_state = match turn_state { 6 | TurnState::AwaitingInput => return, 7 | TurnState::PlayerTurn => TurnState::MonsterTurn, 8 | TurnState::MonsterTurn => TurnState::AwaitingInput 9 | }; 10 | 11 | *turn_state = new_state; 12 | } 13 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/playerecs/src/systems/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | mod map_render; 4 | mod entity_render; 5 | mod player_input; 6 | 7 | pub fn build_scheduler() -> Schedule { 8 | Schedule::builder() 9 | .add_system(player_input::player_input_system()) 10 | .add_system(map_render::map_render_system()) 11 | .add_system(entity_render::entity_render_system()) 12 | .build() 13 | } -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist_problem/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn what_is_your_name() -> String { 4 | let mut your_name = String::new(); 5 | stdin() 6 | .read_line(&mut your_name) 7 | .expect("Failed to read line"); 8 | your_name 9 | } 10 | 11 | fn main() { 12 | println!("Hello, what's your name?"); 13 | let name = what_is_your_name(); 14 | println!("{:?}", name); 15 | } 16 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/systems/end_turn.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn end_turn(#[resource] turn_state: &mut TurnState) { 5 | let new_state = match turn_state { 6 | TurnState::AwaitingInput => return,// (1) 7 | TurnState::PlayerTurn => TurnState::MonsterTurn,// (2) 8 | TurnState::MonsterTurn => TurnState::AwaitingInput// (3) 9 | }; 10 | 11 | *turn_state = new_state;// (4) 12 | } 13 | -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/systems/end_turn.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn end_turn(#[resource] turn_state: &mut TurnState) {// (1) 5 | let new_state = match turn_state { 6 | TurnState::AwaitingInput => return,// (2) 7 | TurnState::PlayerTurn => TurnState::MonsterTurn,// (3) 8 | TurnState::MonsterTurn => TurnState::AwaitingInput// (4) 9 | }; 10 | 11 | *turn_state = new_state;// (5) 12 | } 13 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist_trim/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn what_is_your_name() -> String { 4 | let mut your_name = String::new(); 5 | stdin() 6 | .read_line(&mut your_name) 7 | .expect("Failed to read line"); 8 | 9 | your_name 10 | .trim() 11 | .to_lowercase() 12 | } 13 | 14 | fn main() { 15 | println!("Hello, what's your name?"); 16 | let name = what_is_your_name(); 17 | println!("{:?}", name); 18 | } 19 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/src/systems/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | mod map_render; 4 | mod entity_render; 5 | mod player_input; 6 | mod collisions; 7 | 8 | pub fn build_scheduler() -> Schedule { 9 | Schedule::builder() 10 | .add_system(player_input::player_input_system()) 11 | .add_system(collisions::collisions_system()) 12 | .add_system(map_render::map_render_system()) 13 | .add_system(entity_render::entity_render_system()) 14 | .build() 15 | } -------------------------------------------------------------------------------- /FirstStepsWithRust/hello_yourname_function/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn what_is_your_name() -> String { // (1) 4 | let mut your_name = String::new(); // (2) 5 | stdin() 6 | .read_line(&mut your_name) 7 | .expect("Failed to read line"); 8 | your_name // (3) 9 | } 10 | 11 | fn main() { 12 | println!("Hello, what's your name?"); 13 | let name = what_is_your_name(); // (4) 14 | println!("Hello, {}", name); 15 | } 16 | -------------------------------------------------------------------------------- /FirstGameFlappyAscii/hello_bterm/src/main.rs: -------------------------------------------------------------------------------- 1 | use bracket_lib::prelude::*; 2 | 3 | struct State {} 4 | 5 | impl GameState for State {// (1) 6 | fn tick(&mut self, ctx: &mut BTerm) { // (2) 7 | ctx.cls(); // (3) 8 | ctx.print(1, 1, "Hello, Bracket Terminal!"); // (4) 9 | } 10 | } 11 | 12 | fn main() -> BError { 13 | let context = BTermBuilder::simple80x50() // (5) 14 | .with_title("Flappy Dragon") // (6) 15 | .build()?; // (7) 16 | 17 | main_loop(context, State{}) 18 | } 19 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | 18 | #[derive(Clone, Copy, Debug, PartialEq)] 19 | pub struct WantsToMove { 20 | pub entity : Entity, 21 | pub destination : Point 22 | } 23 | -------------------------------------------------------------------------------- /Loot/better_combat/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /Loot/loot_tables/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /MapTheming/themed/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/src/systems/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | mod map_render; 4 | mod entity_render; 5 | mod player_input; 6 | mod collisions; 7 | mod random_move; 8 | 9 | pub fn build_scheduler() -> Schedule { 10 | Schedule::builder() 11 | .add_system(player_input::player_input_system()) 12 | .add_system(collisions::collisions_system()) 13 | .flush() 14 | .add_system(map_render::map_render_system()) 15 | .add_system(entity_render::entity_render_system()) 16 | .add_system(random_move::random_move_system()) 17 | .build() 18 | } -------------------------------------------------------------------------------- /WhatCanISee/fov/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /WhatCanISee/memory/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /WhatCanISee/eyesight/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/systems/fov.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[write_component(FieldOfView)] 6 | pub fn fov( 7 | ecs: &mut SubWorld, 8 | #[resource] map: &Map, 9 | ) { 10 | let mut views = <(&Point, &mut FieldOfView)>::query();// (1) 11 | views 12 | .iter_mut(ecs)// (2) 13 | .filter(|(_, fov)| fov.is_dirty)// (3) 14 | .for_each(|(pos, mut fov)| { 15 | fov.visible_tiles = field_of_view_set(*pos, fov.radius, map);// (4) 16 | fov.is_dirty = false;// (5) 17 | } 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/output_harness/src/main.rs: -------------------------------------------------------------------------------- 1 | mod map; 2 | mod map_builder; 3 | 4 | mod prelude { 5 | pub use bracket_lib::prelude::*; 6 | pub use crate::map::*; 7 | pub use crate::map_builder::*; 8 | pub const SCREEN_WIDTH: i32 = 80; 9 | pub const SCREEN_HEIGHT: i32 = 50; 10 | pub const NUM_TILES: usize = (SCREEN_WIDTH * SCREEN_HEIGHT) as usize; 11 | } 12 | 13 | fn main() { 14 | use crate::prelude::*; 15 | let mut rng = RandomNumberGenerator::new(); 16 | let mb = MapBuilder::build(&mut rng, Algorithm::Drunkard); 17 | display("Final Map", &mb.map, &mb.player_start, &mb.amulet_start, &mb.monster_spawns); 18 | } 19 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /WinningAndLosing/winning/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new(); 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query() 12 | .iter(ecs) 13 | .for_each(|(pos, render)| { 14 | draw_batch.set( 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error"); 22 | } 23 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/systems/collisions.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Player)] 6 | #[read_component(Enemy)] 7 | pub fn collisions(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut player_pos = Point::zero(); 9 | let mut players = <&Point>::query() 10 | .filter(component::()); 11 | players.iter(ecs).for_each(|pos| player_pos = *pos); 12 | let mut enemies = <(Entity, &Point)>::query() 13 | .filter(component::()); 14 | enemies 15 | .iter(ecs) 16 | .filter(|(_,pos)| **pos == player_pos) 17 | .for_each(|(entity, _)| { 18 | commands.remove(*entity); 19 | } 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/collisions.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Player)] 6 | #[read_component(Enemy)] 7 | pub fn collisions(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut player_pos = Point::zero(); 9 | let mut players = <&Point>::query() 10 | .filter(component::()); 11 | players.iter(ecs).for_each(|pos| player_pos = *pos); 12 | let mut enemies = <(Entity, &Point)>::query() 13 | .filter(component::()); 14 | enemies 15 | .iter(ecs) 16 | .filter(|(_,pos)| **pos == player_pos) 17 | .for_each(|(entity, _)| { 18 | commands.remove(*entity); 19 | } 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/systems/collisions.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Player)] 6 | #[read_component(Enemy)] 7 | pub fn collisions(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut player_pos = Point::zero(); 9 | let mut players = <&Point>::query() 10 | .filter(component::()); 11 | players.iter(ecs).for_each(|pos| player_pos = *pos); 12 | let mut enemies = <(Entity, &Point)>::query() 13 | .filter(component::()); 14 | enemies 15 | .iter(ecs) 16 | .filter(|(_,pos)| **pos == player_pos) 17 | .for_each(|(entity, _)| { 18 | commands.remove(*entity); 19 | } 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/src/systems/collisions.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Player)] 6 | #[read_component(Enemy)] 7 | pub fn collisions(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut player_pos = Point::zero(); 9 | let mut players = <&Point>::query() 10 | .filter(component::()); 11 | players.iter(ecs).for_each(|pos| player_pos = *pos); 12 | let mut enemies = <(Entity, &Point)>::query() 13 | .filter(component::()); 14 | enemies 15 | .iter(ecs) 16 | .filter(|(_,pos)| **pos == player_pos) 17 | .for_each(|(entity, _)| { 18 | commands.remove(*entity); 19 | } 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/systems/random_move.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(MovingRandomly)] 6 | pub fn random_move(ecs: &SubWorld, commands: &mut CommandBuffer) { 7 | let mut movers = <(Entity, &Point, &MovingRandomly)>::query(); 8 | movers.iter(ecs).for_each(| (entity, pos, _) | { 9 | let mut rng = RandomNumberGenerator::new(); 10 | let destination = match rng.range(0, 4) { 11 | 0 => Point::new(-1, 0), 12 | 1 => Point::new(1, 0), 13 | 2 => Point::new(0, -1), 14 | _ => Point::new(0, 1), 15 | } + *pos; 16 | 17 | commands 18 | .push(((), WantsToMove{ entity: *entity, destination })); 19 | }); 20 | } -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/playerecs/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | pub fn entity_render(ecs: &SubWorld, #[resource] camera: &Camera) { 7 | let mut draw_batch = DrawBatch::new();// (1) 8 | draw_batch.target(1); 9 | let offset = Point::new(camera.left_x, camera.top_y); 10 | 11 | <(&Point, &Render)>::query()// (2) 12 | .iter(ecs)// (3) 13 | .for_each(|(pos, render)| {// (4) 14 | draw_batch.set(// (5) 15 | *pos - offset, 16 | render.color, 17 | render.glyph 18 | ); 19 | } 20 | ); 21 | draw_batch.submit(5000).expect("Batch error");// (6) 22 | } 23 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)] 4 | #[read_component(Player)] 5 | pub fn movement( 6 | entity: &Entity, 7 | want_move: &WantsToMove, 8 | #[resource] map: &Map, 9 | #[resource] camera: &mut Camera, 10 | ecs: &mut SubWorld, 11 | commands: &mut CommandBuffer 12 | ) { 13 | if map.can_enter_tile(want_move.destination) { 14 | commands.add_component(want_move.entity, want_move.destination); 15 | 16 | if ecs.entry_ref(want_move.entity) 17 | .unwrap() 18 | .get_component::().is_ok() 19 | { 20 | camera.on_player_move(want_move.destination); 21 | } 22 | } 23 | commands.remove(*entity); 24 | } 25 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/random_move.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(MovingRandomly)] 6 | pub fn random_move(ecs: &SubWorld, commands: &mut CommandBuffer) { 7 | let mut movers = <(Entity, &Point, &MovingRandomly)>::query(); 8 | movers.iter(ecs).for_each(| (entity, pos, _) | { 9 | let mut rng = RandomNumberGenerator::new(); 10 | let destination = match rng.range(0, 4) { 11 | 0 => Point::new(-1, 0), 12 | 1 => Point::new(1, 0), 13 | 2 => Point::new(0, -1), 14 | _ => Point::new(0, 1), 15 | } + *pos; 16 | 17 | commands 18 | .push(((), WantsToMove{ entity: *entity, destination })); 19 | }); 20 | } -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/systems/random_move.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[write_component(Point)] 5 | #[read_component(MovingRandomly)] 6 | pub fn random_move(ecs: &mut SubWorld, #[resource] map: &Map) { 7 | let mut movers = <(&mut Point, &MovingRandomly)>::query(); 8 | movers.iter_mut(ecs).for_each(|(pos, _)| { 9 | let mut rng = RandomNumberGenerator::new(); 10 | let destination = match rng.range(0, 4) { 11 | 0 => Point::new(-1, 0), 12 | 1 => Point::new(1, 0), 13 | 2 => Point::new(0, -1), 14 | _ => Point::new(0, 1), 15 | } + *pos; 16 | 17 | if map.can_enter_tile(destination) { 18 | *pos = destination; 19 | } 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)] 4 | #[read_component(Player)] 5 | pub fn movement( 6 | entity: &Entity, 7 | want_move: &WantsToMove, 8 | #[resource] map: &Map, 9 | #[resource] camera: &mut Camera, 10 | ecs: &mut SubWorld, 11 | commands: &mut CommandBuffer 12 | ) { 13 | if map.can_enter_tile(want_move.destination) { 14 | commands.add_component(want_move.entity, want_move.destination); 15 | 16 | if ecs.entry_ref(want_move.entity) 17 | .unwrap() 18 | .get_component::().is_ok() 19 | { 20 | camera.on_player_move(want_move.destination); 21 | } 22 | } 23 | commands.remove(*entity); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)] 4 | #[read_component(Player)] 5 | pub fn movement( 6 | entity: &Entity, 7 | want_move: &WantsToMove, 8 | #[resource] map: &Map, 9 | #[resource] camera: &mut Camera, 10 | ecs: &mut SubWorld, 11 | commands: &mut CommandBuffer 12 | ) { 13 | if map.can_enter_tile(want_move.destination) { 14 | commands.add_component(want_move.entity, want_move.destination); 15 | 16 | if ecs.entry_ref(want_move.entity) 17 | .unwrap() 18 | .get_component::().is_ok() 19 | { 20 | camera.on_player_move(want_move.destination); 21 | } 22 | } 23 | commands.remove(*entity); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)] 4 | #[read_component(Player)] 5 | pub fn movement( 6 | entity: &Entity, 7 | want_move: &WantsToMove, 8 | #[resource] map: &Map, 9 | #[resource] camera: &mut Camera, 10 | ecs: &mut SubWorld, 11 | commands: &mut CommandBuffer 12 | ) { 13 | if map.can_enter_tile(want_move.destination) { 14 | commands.add_component(want_move.entity, want_move.destination); 15 | 16 | if ecs.entry_ref(want_move.entity) 17 | .unwrap() 18 | .get_component::().is_ok() 19 | { 20 | camera.on_player_move(want_move.destination); 21 | } 22 | } 23 | commands.remove(*entity); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)] 4 | #[read_component(Player)] 5 | pub fn movement( 6 | entity: &Entity, 7 | want_move: &WantsToMove, 8 | #[resource] map: &Map, 9 | #[resource] camera: &mut Camera, 10 | ecs: &mut SubWorld, 11 | commands: &mut CommandBuffer 12 | ) { 13 | if map.can_enter_tile(want_move.destination) { 14 | commands.add_component(want_move.entity, want_move.destination); 15 | 16 | if ecs.entry_ref(want_move.entity) 17 | .unwrap() 18 | .get_component::().is_ok() 19 | { 20 | camera.on_player_move(want_move.destination); 21 | } 22 | } 23 | commands.remove(*entity); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /WinningAndLosing/winning/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)] 4 | #[read_component(Player)] 5 | pub fn movement( 6 | entity: &Entity, 7 | want_move: &WantsToMove, 8 | #[resource] map: &Map, 9 | #[resource] camera: &mut Camera, 10 | ecs: &mut SubWorld, 11 | commands: &mut CommandBuffer 12 | ) { 13 | if map.can_enter_tile(want_move.destination) { 14 | commands.add_component(want_move.entity, want_move.destination); 15 | 16 | if ecs.entry_ref(want_move.entity) 17 | .unwrap() 18 | .get_component::().is_ok() 19 | { 20 | camera.on_player_move(want_move.destination); 21 | } 22 | } 23 | commands.remove(*entity); 24 | } 25 | 26 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/src/systems/collisions.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] // (1) 5 | #[read_component(Player)] 6 | #[read_component(Enemy)] 7 | pub fn collisions(ecs: &mut SubWorld, commands: &mut CommandBuffer) {// (2) 8 | let mut player_pos = Point::zero(); 9 | let mut players = <&Point>::query() 10 | .filter(component::()); 11 | players.iter(ecs).for_each(|pos| player_pos = *pos); 12 | let mut enemies = <(Entity, &Point)>::query() 13 | .filter(component::()); 14 | enemies 15 | .iter(ecs) 16 | .filter(|(_,pos)| **pos == player_pos)// (3) 17 | .for_each(|(entity, _)| {// (4) 18 | commands.remove(*entity);// (5) 19 | } 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)]// (1) 4 | #[read_component(Player)] 5 | pub fn movement( 6 | entity: &Entity, 7 | want_move: &WantsToMove, 8 | #[resource] map: &Map, 9 | #[resource] camera: &mut Camera, 10 | ecs: &mut SubWorld, 11 | commands: &mut CommandBuffer 12 | ) { 13 | if map.can_enter_tile(want_move.destination) { 14 | commands.add_component(want_move.entity, want_move.destination);// (2) 15 | 16 | if ecs.entry_ref(want_move.entity)// (3) 17 | .unwrap()// (4) 18 | .get_component::().is_ok()// (5) 19 | { 20 | camera.on_player_move(want_move.destination);// (6) 21 | } 22 | } 23 | commands.remove(*entity);// (7) 24 | } 25 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | 18 | 19 | #[derive(Clone, Copy, Debug, PartialEq)] 20 | pub struct WantsToMove { 21 | pub entity : Entity, 22 | pub destination : Point 23 | } 24 | 25 | #[derive(Clone, Copy, Debug, PartialEq)] 26 | pub struct Health { 27 | pub current: i32, 28 | pub max: i32 29 | } 30 | 31 | #[derive(Clone, PartialEq)] 32 | pub struct Name(pub String); 33 | -------------------------------------------------------------------------------- /FirstStepsWithRust/treehouse_guestlist/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::io::stdin; 2 | 3 | fn what_is_your_name() -> String { 4 | let mut your_name = String::new(); 5 | stdin() 6 | .read_line(&mut your_name) 7 | .expect("Failed to read line"); 8 | your_name.trim().to_lowercase() 9 | } 10 | 11 | fn main() { 12 | let visitor_list = ["bert", "steve", "fred"]; 13 | 14 | println!("Hello, what's your name?"); 15 | let name = what_is_your_name(); 16 | 17 | let mut allow_them_in = false; 18 | for visitor in &visitor_list { 19 | if visitor == &name { 20 | allow_them_in = true; 21 | } 22 | } 23 | 24 | if allow_them_in { 25 | println!("Welcome to the Treehouse, {}", name); 26 | } else { 27 | println!("Sorry, you aren't on the list."); 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/src/systems/random_move.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[write_component(Point)] 5 | #[read_component(MovingRandomly)] 6 | pub fn random_move(ecs: &mut SubWorld, #[resource] map: &Map) {// (1) 7 | let mut movers = <(&mut Point, &MovingRandomly)>::query();// (2) 8 | movers 9 | .iter_mut(ecs) 10 | .for_each(|(pos, _)| { 11 | let mut rng = RandomNumberGenerator::new(); 12 | let destination = match rng.range(0, 4) {// (3) 13 | 0 => Point::new(-1, 0), 14 | 1 => Point::new(1, 0), 15 | 2 => Point::new(0, -1), 16 | _ => Point::new(0, 1), 17 | } + *pos; 18 | 19 | if map.can_enter_tile(destination) {// (4) 20 | *pos = destination;// (5) 21 | } 22 | } 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/systems/end_turn.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn end_turn( 7 | ecs: &SubWorld, 8 | #[resource] turn_state: &mut TurnState 9 | ) { 10 | let mut player_hp = <&Health>::query().filter(component::());// (1) 11 | let current_state = turn_state.clone(); 12 | let mut new_state = match current_state {// (2) 13 | TurnState::AwaitingInput => return, 14 | TurnState::PlayerTurn => TurnState::MonsterTurn, 15 | TurnState::MonsterTurn => TurnState::AwaitingInput, 16 | _ => current_state // (3) 17 | }; 18 | 19 | player_hp.iter(ecs).for_each(|hp| {// (4) 20 | if hp.current < 1 { 21 | new_state = TurnState::GameOver; 22 | } 23 | }); 24 | 25 | *turn_state = new_state; 26 | } 27 | -------------------------------------------------------------------------------- /BasicDungeonCrawler/dungeon_crawl_map/src/main.rs: -------------------------------------------------------------------------------- 1 | #![warn(clippy::pedantic)] 2 | 3 | mod map; // (1) 4 | 5 | mod prelude { // (2) 6 | pub use bracket_lib::prelude::*; // (3) 7 | pub const SCREEN_WIDTH: i32 = 80; // (4) 8 | pub const SCREEN_HEIGHT: i32 = 50; 9 | pub use crate::map::*; // (5) 10 | } 11 | 12 | use prelude::*; // (6) 13 | 14 | struct State { 15 | map: Map, 16 | } 17 | 18 | impl State { 19 | fn new() -> Self { 20 | Self { map: Map::new() } 21 | } 22 | } 23 | 24 | impl GameState for State { 25 | fn tick(&mut self, ctx: &mut BTerm) { 26 | ctx.cls(); 27 | self.map.render(ctx); 28 | } 29 | } 30 | 31 | fn main() -> BError { 32 | let context = BTermBuilder::simple80x50() 33 | .with_title("Dungeon Crawler") 34 | .with_fps_cap(30.0)// (7) 35 | .build()?; 36 | 37 | main_loop(context, State::new()) 38 | } 39 | -------------------------------------------------------------------------------- /Loot/loot_tables/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MapTheming/themed/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WhatCanISee/fov/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Loot/better_combat/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | 16 | mb.fill(TileType::Wall); 17 | mb.build_random_rooms(rng); 18 | mb.build_corridors(rng); 19 | mb.player_start = mb.rooms[0].center(); 20 | mb.amulet_start = mb.find_most_distant(); 21 | for room in mb.rooms.iter().skip(1) { 22 | mb.monster_spawns.push(room.center()); 23 | } 24 | 25 | mb 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WhatCanISee/eyesight/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WhatCanISee/memory/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | 16 | mb.fill(TileType::Wall); 17 | mb.build_random_rooms(rng); 18 | mb.build_corridors(rng); 19 | mb.player_start = mb.rooms[0].center(); 20 | mb.amulet_start = mb.find_most_distant(); 21 | for room in mb.rooms.iter().skip(1) { 22 | mb.monster_spawns.push(room.center()); 23 | } 24 | 25 | mb 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | 16 | mb.fill(TileType::Wall); 17 | mb.build_random_rooms(rng); 18 | mb.build_corridors(rng); 19 | mb.player_start = mb.rooms[0].center(); 20 | mb.amulet_start = mb.find_most_distant(); 21 | for room in mb.rooms.iter().skip(1) { 22 | mb.monster_spawns.push(room.center()); 23 | } 24 | 25 | mb 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /WinningAndLosing/winning/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder {//(1) 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | 16 | mb.fill(TileType::Wall); 17 | mb.build_random_rooms(rng); 18 | mb.build_corridors(rng); 19 | mb.player_start = mb.rooms[0].center(); 20 | mb.amulet_start = mb.find_most_distant(); 21 | for room in mb.rooms.iter().skip(1) { 22 | mb.monster_spawns.push(room.center()); 23 | } 24 | 25 | mb 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /BasicDungeonCrawler/dungeon_crawl_graphics/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/playerecs/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/camera.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct Camera { 4 | pub left_x : i32, 5 | pub right_x : i32, 6 | pub top_y : i32, 7 | pub bottom_y : i32 8 | } 9 | 10 | impl Camera { 11 | pub fn new(player_position: Point) -> Self { 12 | Self{ 13 | left_x : player_position.x - DISPLAY_WIDTH/2, 14 | right_x : player_position.x + DISPLAY_WIDTH/2, 15 | top_y : player_position.y - DISPLAY_HEIGHT/2, 16 | bottom_y : player_position.y + DISPLAY_HEIGHT/2 17 | } 18 | } 19 | 20 | pub fn on_player_move(&mut self, player_position: Point) { 21 | self.left_x = player_position.x - DISPLAY_WIDTH/2; 22 | self.right_x = player_position.x + DISPLAY_WIDTH/2; 23 | self.top_y = player_position.y - DISPLAY_HEIGHT/2; 24 | self.bottom_y = player_position.y + DISPLAY_HEIGHT/2; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /MapTheming/themed/src/map_builder/themes.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct DungeonTheme {} 4 | 5 | impl DungeonTheme { 6 | pub fn new() -> Box {// (1) 7 | Box::new(Self{})// (2) 8 | } 9 | } 10 | 11 | impl MapTheme for DungeonTheme { 12 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 13 | match tile_type { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#') 16 | } 17 | } 18 | } 19 | 20 | pub struct ForestTheme {} 21 | 22 | impl MapTheme for ForestTheme { 23 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 24 | match tile_type { 25 | TileType::Floor => to_cp437(';'), 26 | TileType::Wall => to_cp437('"') 27 | } 28 | } 29 | } 30 | 31 | impl ForestTheme { 32 | pub fn new() -> Box { 33 | Box::new(Self{}) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /EntitiesComponentsAndSystems/dungeonecs/src/spawner.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub fn spawn_player(ecs : &mut World, pos : Point) { 4 | ecs.push( 5 | (Player, 6 | pos, 7 | Render{ 8 | color: ColorPair::new(WHITE, BLACK), 9 | glyph : to_cp437('@') 10 | } 11 | ) 12 | ); 13 | } 14 | 15 | pub fn spawn_monster( 16 | ecs: &mut World, 17 | rng: &mut RandomNumberGenerator, 18 | pos : Point 19 | ) { 20 | ecs.push( 21 | (Enemy, 22 | pos, 23 | Render{ 24 | color: ColorPair::new(WHITE, BLACK), 25 | glyph : match rng.range(0,4) { 26 | 0 => to_cp437('E'), 27 | 1 => to_cp437('O'), 28 | 2 => to_cp437('o'), 29 | _ => to_cp437('g'), 30 | } 31 | } 32 | ) 33 | ); 34 | } 35 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | 18 | 19 | #[derive(Clone, Copy, Debug, PartialEq)] 20 | pub struct WantsToMove { 21 | pub entity : Entity, 22 | pub destination : Point 23 | } 24 | 25 | #[derive(Clone, Copy, Debug, PartialEq)] 26 | pub struct WantsToAttack { 27 | pub attacker : Entity, 28 | pub victim : Entity 29 | } 30 | 31 | #[derive(Clone, Copy, Debug, PartialEq)] 32 | pub struct Health { 33 | pub current: i32, 34 | pub max: i32 35 | } 36 | 37 | #[derive(Clone, PartialEq)] 38 | pub struct Name(pub String); 39 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | 18 | 19 | #[derive(Clone, Copy, Debug, PartialEq)] 20 | pub struct WantsToMove { 21 | pub entity : Entity, 22 | pub destination : Point 23 | } 24 | 25 | #[derive(Clone, Copy, Debug, PartialEq)] 26 | pub struct WantsToAttack { 27 | pub attacker : Entity, 28 | pub victim : Entity 29 | } 30 | 31 | #[derive(Clone, Copy, Debug, PartialEq)] 32 | pub struct Health { 33 | pub current: i32, 34 | pub max: i32 35 | } 36 | 37 | #[derive(Clone, PartialEq)] 38 | pub struct Name(pub String); 39 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/output_harness/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | monster_spawns : Vec::new(), 11 | player_start : Point::zero(), 12 | amulet_start : Point::zero() 13 | }; 14 | mb.fill(TileType::Floor); 15 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 16 | mb.amulet_start = mb.find_most_distant(); 17 | for _ in 0..50 { 18 | mb.monster_spawns.push( 19 | Point::new( 20 | rng.range(1, SCREEN_WIDTH), 21 | rng.range(1, SCREEN_HEIGHT) 22 | ) 23 | ) 24 | } 25 | mb 26 | } 27 | } -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/map_builder/themes.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct DungeonTheme {} 4 | 5 | impl DungeonTheme { 6 | pub fn new() -> Box {// (1) 7 | Box::new(Self{})// (2) 8 | } 9 | } 10 | 11 | impl MapTheme for DungeonTheme { 12 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 13 | match tile_type { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#') 16 | } 17 | } 18 | } 19 | 20 | pub struct ForestTheme {} 21 | 22 | impl MapTheme for ForestTheme { 23 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 24 | match tile_type { 25 | TileType::Floor => to_cp437(';'), 26 | TileType::Wall => to_cp437('"') 27 | } 28 | } 29 | } 30 | 31 | impl ForestTheme { 32 | pub fn new() -> Box { 33 | Box::new(Self{}) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/map_builder/themes.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct DungeonTheme {} 4 | 5 | impl DungeonTheme { 6 | pub fn new() -> Box {// (1) 7 | Box::new(Self{})// (2) 8 | } 9 | } 10 | 11 | impl MapTheme for DungeonTheme { 12 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 13 | match tile_type { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#') 16 | } 17 | } 18 | } 19 | 20 | pub struct ForestTheme {} 21 | 22 | impl MapTheme for ForestTheme { 23 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 24 | match tile_type { 25 | TileType::Floor => to_cp437(';'), 26 | TileType::Wall => to_cp437('"') 27 | } 28 | } 29 | } 30 | 31 | impl ForestTheme { 32 | pub fn new() -> Box { 33 | Box::new(Self{}) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Loot/better_combat/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | 17 | mb.fill(TileType::Wall); 18 | mb.build_random_rooms(rng); 19 | mb.build_corridors(rng); 20 | mb.player_start = mb.rooms[0].center(); 21 | mb.amulet_start = mb.find_most_distant(); 22 | for room in mb.rooms.iter().skip(1) { 23 | mb.monster_spawns.push(room.center()); 24 | } 25 | 26 | mb 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /Loot/loot_tables/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | 17 | mb.fill(TileType::Wall); 18 | mb.build_random_rooms(rng); 19 | mb.build_corridors(rng); 20 | mb.player_start = mb.rooms[0].center(); 21 | mb.amulet_start = mb.find_most_distant(); 22 | for room in mb.rooms.iter().skip(1) { 23 | mb.monster_spawns.push(room.center()); 24 | } 25 | 26 | mb 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /MapTheming/themed/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | 17 | mb.fill(TileType::Wall); 18 | mb.build_random_rooms(rng); 19 | mb.build_corridors(rng); 20 | mb.player_start = mb.rooms[0].center(); 21 | mb.amulet_start = mb.find_most_distant(); 22 | for room in mb.rooms.iter().skip(1) { 23 | mb.monster_spawns.push(room.center()); 24 | } 25 | 26 | mb 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/spawner.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub fn spawn_player(ecs : &mut World, pos : Point) { 4 | ecs.push( 5 | (Player, 6 | pos, 7 | Render{ 8 | color: ColorPair::new(WHITE, BLACK), 9 | glyph : to_cp437('@') 10 | } 11 | ) 12 | ); 13 | } 14 | 15 | pub fn spawn_monster( 16 | ecs: &mut World, 17 | rng: &mut RandomNumberGenerator, 18 | pos : Point 19 | ) { 20 | ecs.push( 21 | (Enemy, 22 | pos, 23 | Render{ 24 | color: ColorPair::new(WHITE, BLACK), 25 | glyph : match rng.range(0,4) { 26 | 0 => to_cp437('E'), 27 | 1 => to_cp437('O'), 28 | 2 => to_cp437('o'), 29 | _ => to_cp437('g'), 30 | } 31 | }, 32 | MovingRandomly{} 33 | ) 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /TurnBasedGames/wandering/src/spawner.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub fn spawn_player(ecs : &mut World, pos : Point) { 4 | ecs.push( 5 | (Player, 6 | pos, 7 | Render{ 8 | color: ColorPair::new(WHITE, BLACK), 9 | glyph : to_cp437('@') 10 | } 11 | ) 12 | ); 13 | } 14 | 15 | pub fn spawn_monster( 16 | ecs: &mut World, 17 | rng: &mut RandomNumberGenerator, 18 | pos : Point 19 | ) { 20 | ecs.push( 21 | (Enemy, 22 | pos, 23 | Render{ 24 | color: ColorPair::new(WHITE, BLACK), 25 | glyph : match rng.range(0,4) { 26 | 0 => to_cp437('E'), 27 | 1 => to_cp437('O'), 28 | 2 => to_cp437('o'), 29 | _ => to_cp437('g'), 30 | } 31 | }, 32 | MovingRandomly{} 33 | ) 34 | ); 35 | } -------------------------------------------------------------------------------- /TurnBasedGames/turnbased/src/spawner.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub fn spawn_player(ecs : &mut World, pos : Point) { 4 | ecs.push( 5 | (Player, 6 | pos, 7 | Render{ 8 | color: ColorPair::new(WHITE, BLACK), 9 | glyph : to_cp437('@') 10 | } 11 | ) 12 | ); 13 | } 14 | 15 | pub fn spawn_monster( 16 | ecs: &mut World, 17 | rng: &mut RandomNumberGenerator, 18 | pos : Point 19 | ) { 20 | ecs.push( 21 | (Enemy, 22 | pos, 23 | Render{ 24 | color: ColorPair::new(WHITE, BLACK), 25 | glyph : match rng.range(0,4) { 26 | 0 => to_cp437('E'), 27 | 1 => to_cp437('O'), 28 | 2 => to_cp437('o'), 29 | _ => to_cp437('g'), 30 | } 31 | }, 32 | MovingRandomly{} 33 | ) 34 | ); 35 | } 36 | -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | 17 | mb.fill(TileType::Wall); 18 | mb.build_random_rooms(rng); 19 | mb.build_corridors(rng); 20 | mb.player_start = mb.rooms[0].center(); 21 | mb.amulet_start = mb.find_most_distant(); 22 | for room in mb.rooms.iter().skip(1) { 23 | mb.monster_spawns.push(room.center()); 24 | } 25 | 26 | mb 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | 17 | mb.fill(TileType::Wall); 18 | mb.build_random_rooms(rng); 19 | mb.build_corridors(rng); 20 | mb.player_start = mb.rooms[0].center(); 21 | mb.amulet_start = mb.find_most_distant(); 22 | for room in mb.rooms.iter().skip(1) { 23 | mb.monster_spawns.push(room.center()); 24 | } 25 | 26 | mb 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/map_builder/rooms.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct RoomsArchitect {} 5 | 6 | impl MapArchitect for RoomsArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | 17 | mb.fill(TileType::Wall); 18 | mb.build_random_rooms(rng); 19 | mb.build_corridors(rng); 20 | mb.player_start = mb.rooms[0].center(); 21 | mb.amulet_start = mb.find_most_distant(); 22 | for room in mb.rooms.iter().skip(1) { 23 | mb.monster_spawns.push(room.center()); 24 | } 25 | 26 | mb 27 | } 28 | } 29 | 30 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | mb.fill(TileType::Floor); 16 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 17 | mb.amulet_start = mb.find_most_distant(); 18 | for _ in 0..50 { 19 | mb.monster_spawns.push( 20 | Point::new( 21 | rng.range(1, SCREEN_WIDTH), 22 | rng.range(1, SCREEN_HEIGHT) 23 | ) 24 | ) 25 | } 26 | mb 27 | } 28 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | mb.fill(TileType::Floor); 16 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 17 | mb.amulet_start = mb.find_most_distant(); 18 | for _ in 0..50 { 19 | mb.monster_spawns.push( 20 | Point::new( 21 | rng.range(1, SCREEN_WIDTH), 22 | rng.range(1, SCREEN_HEIGHT) 23 | ) 24 | ) 25 | } 26 | mb 27 | } 28 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms : Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | mb.fill(TileType::Floor); 16 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 17 | mb.amulet_start = mb.find_most_distant(); 18 | for _ in 0..50 { 19 | mb.monster_spawns.push( 20 | Point::new( 21 | rng.range(1, SCREEN_WIDTH), 22 | rng.range(1, SCREEN_HEIGHT) 23 | ) 24 | ) 25 | } 26 | mb 27 | } 28 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | mb.fill(TileType::Floor); 16 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 17 | mb.amulet_start = mb.find_most_distant(); 18 | for _ in 0..50 { 19 | mb.monster_spawns.push( 20 | Point::new( 21 | rng.range(1, SCREEN_WIDTH), 22 | rng.range(1, SCREEN_HEIGHT) 23 | ) 24 | ) 25 | } 26 | mb 27 | } 28 | } -------------------------------------------------------------------------------- /WhatCanISee/fov/src/systems/movement.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system(for_each)] 4 | #[read_component(Player)] 5 | #[read_component(FieldOfView)]// (1) 6 | pub fn movement( 7 | entity: &Entity, 8 | want_move: &WantsToMove, 9 | #[resource] map: &Map, 10 | #[resource] camera: &mut Camera, 11 | ecs: &mut SubWorld, 12 | commands: &mut CommandBuffer 13 | ) { 14 | if map.can_enter_tile(want_move.destination) { 15 | commands.add_component(want_move.entity, want_move.destination); 16 | 17 | if let Ok(entry) = ecs.entry_ref(want_move.entity) {// (2) 18 | if let Ok(fov) = entry.get_component::() { 19 | commands.add_component(want_move.entity, fov.clone_dirty());// (3) 20 | } 21 | 22 | if entry.get_component::().is_ok() 23 | { 24 | camera.on_player_move(want_move.destination); 25 | } 26 | } 27 | } 28 | commands.remove(*entity); 29 | } 30 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect;//(1) 3 | 4 | pub struct EmptyArchitect {}//(2) 5 | 6 | impl MapArchitect for EmptyArchitect {//(3) 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder {//(4) 8 | let mut mb = MapBuilder{//(5) 9 | map : Map::new(), 10 | rooms: Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero() 14 | }; 15 | mb.fill(TileType::Floor); 16 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 17 | mb.amulet_start = mb.find_most_distant();//(6) 18 | for _ in 0..50 {//(7) 19 | mb.monster_spawns.push( 20 | Point::new( 21 | rng.range(1, SCREEN_WIDTH), 22 | rng.range(1, SCREEN_WIDTH) 23 | ) 24 | ) 25 | } 26 | mb 27 | } 28 | } -------------------------------------------------------------------------------- /Loot/better_combat/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms : Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | mb.fill(TileType::Floor); 17 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 18 | mb.amulet_start = mb.find_most_distant(); 19 | for _ in 0..50 { 20 | mb.monster_spawns.push( 21 | Point::new( 22 | rng.range(1, SCREEN_WIDTH), 23 | rng.range(1, SCREEN_HEIGHT) 24 | ) 25 | ) 26 | } 27 | mb 28 | } 29 | } -------------------------------------------------------------------------------- /Loot/better_combat/src/map_builder/themes.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct DungeonTheme {} 4 | 5 | impl DungeonTheme { 6 | pub fn new() -> Box { 7 | Box::new(Self{}) 8 | } 9 | } 10 | 11 | impl MapTheme for DungeonTheme { 12 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 13 | match tile_type { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#'), 16 | TileType::Exit => to_cp437('>'), 17 | } 18 | } 19 | } 20 | 21 | pub struct ForestTheme {} 22 | 23 | impl MapTheme for ForestTheme { 24 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 25 | match tile_type { 26 | TileType::Floor => to_cp437(';'), 27 | TileType::Wall => to_cp437('"'), 28 | TileType::Exit => to_cp437('>'), 29 | } 30 | } 31 | } 32 | 33 | impl ForestTheme { 34 | pub fn new() -> Box { 35 | Box::new(Self{}) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Loot/loot_tables/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms : Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | mb.fill(TileType::Floor); 17 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 18 | mb.amulet_start = mb.find_most_distant(); 19 | for _ in 0..50 { 20 | mb.monster_spawns.push( 21 | Point::new( 22 | rng.range(1, SCREEN_WIDTH), 23 | rng.range(1, SCREEN_HEIGHT) 24 | ) 25 | ) 26 | } 27 | mb 28 | } 29 | } -------------------------------------------------------------------------------- /Loot/loot_tables/src/map_builder/themes.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct DungeonTheme {} 4 | 5 | impl DungeonTheme { 6 | pub fn new() -> Box { 7 | Box::new(Self{}) 8 | } 9 | } 10 | 11 | impl MapTheme for DungeonTheme { 12 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 13 | match tile_type { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#'), 16 | TileType::Exit => to_cp437('>'), 17 | } 18 | } 19 | } 20 | 21 | pub struct ForestTheme {} 22 | 23 | impl MapTheme for ForestTheme { 24 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 25 | match tile_type { 26 | TileType::Floor => to_cp437(';'), 27 | TileType::Wall => to_cp437('"'), 28 | TileType::Exit => to_cp437('>'), 29 | } 30 | } 31 | } 32 | 33 | impl ForestTheme { 34 | pub fn new() -> Box { 35 | Box::new(Self{}) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /MapTheming/themed/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms : Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | mb.fill(TileType::Floor); 17 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 18 | mb.amulet_start = mb.find_most_distant(); 19 | for _ in 0..50 { 20 | mb.monster_spawns.push( 21 | Point::new( 22 | rng.range(1, SCREEN_WIDTH), 23 | rng.range(1, SCREEN_HEIGHT) 24 | ) 25 | ) 26 | } 27 | mb 28 | } 29 | } -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | 18 | #[derive(Clone, Copy, Debug, PartialEq)] 19 | pub struct ChasingPlayer; 20 | 21 | 22 | #[derive(Clone, Copy, Debug, PartialEq)] 23 | pub struct WantsToMove { 24 | pub entity : Entity, 25 | pub destination : Point 26 | } 27 | 28 | #[derive(Clone, Copy, Debug, PartialEq)] 29 | pub struct WantsToAttack { 30 | pub attacker : Entity, 31 | pub victim : Entity 32 | } 33 | 34 | #[derive(Clone, Copy, Debug, PartialEq)] 35 | pub struct Health { 36 | pub current: i32, 37 | pub max: i32 38 | } 39 | 40 | #[derive(Clone, PartialEq)] 41 | pub struct Name(pub String); 42 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/components.rs: -------------------------------------------------------------------------------- 1 | pub use crate::prelude::*; 2 | 3 | #[derive(Clone, Copy, Debug, PartialEq)] 4 | pub struct Render { 5 | pub color : ColorPair, 6 | pub glyph : FontCharType 7 | } 8 | 9 | #[derive(Clone, Copy, Debug, PartialEq)] 10 | pub struct Player; 11 | 12 | #[derive(Clone, Copy, Debug, PartialEq)] 13 | pub struct Enemy; 14 | 15 | #[derive(Clone, Copy, Debug, PartialEq)] 16 | pub struct MovingRandomly; 17 | 18 | #[derive(Clone, Copy, Debug, PartialEq)] 19 | pub struct ChasingPlayer; 20 | 21 | 22 | #[derive(Clone, Copy, Debug, PartialEq)] 23 | pub struct WantsToMove { 24 | pub entity : Entity, 25 | pub destination : Point 26 | } 27 | 28 | #[derive(Clone, Copy, Debug, PartialEq)] 29 | pub struct WantsToAttack { 30 | pub attacker : Entity, 31 | pub victim : Entity 32 | } 33 | 34 | #[derive(Clone, Copy, Debug, PartialEq)] 35 | pub struct Health { 36 | pub current: i32, 37 | pub max: i32 38 | } 39 | 40 | #[derive(Clone, PartialEq)] 41 | pub struct Name(pub String); 42 | -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms : Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | mb.fill(TileType::Floor); 17 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 18 | mb.amulet_start = mb.find_most_distant(); 19 | for _ in 0..50 { 20 | mb.monster_spawns.push( 21 | Point::new( 22 | rng.range(1, SCREEN_WIDTH), 23 | rng.range(1, SCREEN_HEIGHT) 24 | ) 25 | ) 26 | } 27 | mb 28 | } 29 | } -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/map_builder/themes.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | pub struct DungeonTheme {} 4 | 5 | impl DungeonTheme { 6 | pub fn new() -> Box { 7 | Box::new(Self{}) 8 | } 9 | } 10 | 11 | impl MapTheme for DungeonTheme { 12 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 13 | match tile_type { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#'), 16 | TileType::Exit => to_cp437('>'), 17 | } 18 | } 19 | } 20 | 21 | pub struct ForestTheme {} 22 | 23 | impl MapTheme for ForestTheme { 24 | fn tile_to_render(&self, tile_type: TileType) -> FontCharType { 25 | match tile_type { 26 | TileType::Floor => to_cp437(';'), 27 | TileType::Wall => to_cp437('"'), 28 | TileType::Exit => to_cp437('>'), 29 | } 30 | } 31 | } 32 | 33 | impl ForestTheme { 34 | pub fn new() -> Box { 35 | Box::new(Self{}) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[write_component(Health)] 6 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 7 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 8 | let victims : Vec<(Entity, Entity)> = attackers 9 | .iter(ecs) 10 | .map(|(entity, attack)| (*entity, attack.victim) ) 11 | .collect(); 12 | 13 | victims.iter().for_each(|(message, victim)| { 14 | if let Ok(mut health) = ecs 15 | .entry_mut(*victim) 16 | .unwrap() 17 | .get_component_mut::() 18 | { 19 | println!("Health before attack: {}", health.current); 20 | health.current -= 1; 21 | if health.current < 1 { 22 | commands.remove(*victim); 23 | } 24 | println!("Health after attack: {}", health.current); 25 | } 26 | commands.remove(*message); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[write_component(Health)] 6 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 7 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 8 | let victims : Vec<(Entity, Entity)> = attackers 9 | .iter(ecs) 10 | .map(|(entity, attack)| (*entity, attack.victim) ) 11 | .collect(); 12 | 13 | victims.iter().for_each(|(message, victim)| { 14 | if let Ok(mut health) = ecs 15 | .entry_mut(*victim) 16 | .unwrap() 17 | .get_component_mut::() 18 | { 19 | println!("Health before attack: {}", health.current); 20 | health.current -= 1; 21 | if health.current < 1 { 22 | commands.remove(*victim); 23 | } 24 | println!("Health after attack: {}", health.current); 25 | } 26 | commands.remove(*message); 27 | }); 28 | } 29 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms : Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | mb.fill(TileType::Floor); 17 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 18 | mb.amulet_start = mb.find_most_distant(); 19 | for _ in 0..50 { 20 | mb.monster_spawns.push( 21 | Point::new( 22 | rng.range(1, SCREEN_WIDTH), 23 | rng.range(1, SCREEN_HEIGHT) 24 | ) 25 | ) 26 | } 27 | mb 28 | } 29 | } -------------------------------------------------------------------------------- /WhatCanISee/fov/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/map_builder/empty.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | use super::MapArchitect; 3 | 4 | pub struct EmptyArchitect {} 5 | 6 | impl MapArchitect for EmptyArchitect { 7 | fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder { 8 | let mut mb = MapBuilder{ 9 | map : Map::new(), 10 | rooms : Vec::new(), 11 | monster_spawns : Vec::new(), 12 | player_start : Point::zero(), 13 | amulet_start : Point::zero(), 14 | theme: super::themes::DungeonTheme::new() 15 | }; 16 | mb.fill(TileType::Floor); 17 | mb.player_start = Point::new(SCREEN_WIDTH/2, SCREEN_HEIGHT/2); 18 | mb.amulet_start = mb.find_most_distant(); 19 | for _ in 0..50 { 20 | mb.monster_spawns.push( 21 | Point::new( 22 | rng.range(1, SCREEN_WIDTH), 23 | rng.range(1, SCREEN_HEIGHT) 24 | ) 25 | ) 26 | } 27 | mb 28 | } 29 | } -------------------------------------------------------------------------------- /MapTheming/themed/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WhatCanISee/eyesight/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WhatCanISee/memory/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[write_component(Health)] 6 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 7 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 8 | 9 | let victims : Vec<(Entity, Entity)> = attackers// (1) 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) )// (2) 12 | .collect();// (3) 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | if let Ok(mut health) = ecs 16 | .entry_mut(*victim) 17 | .unwrap() 18 | .get_component_mut::() 19 | { 20 | println!("Health before attack: {}", health.current); 21 | health.current -= 1; 22 | if health.current < 1 { 23 | commands.remove(*victim); 24 | } 25 | println!("Health after attack: {}", health.current); 26 | } 27 | commands.remove(*message); 28 | }); 29 | } 30 | -------------------------------------------------------------------------------- /Loot/better_combat/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /Loot/loot_tables/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MapTheming/themed/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WhatCanISee/fov/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WhatCanISee/memory/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WinningAndLosing/gauntlet/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WinningAndLosing/winning/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /WhatCanISee/eyesight/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/player_input.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | pub fn player_input( 6 | ecs: &mut SubWorld, 7 | commands: &mut CommandBuffer, 8 | #[resource] key: &Option, 9 | #[resource] turn_state: &mut TurnState 10 | ) { 11 | let mut players = <(Entity, &Point)>::query().filter(component::()); 12 | 13 | if let Some(key) = *key { 14 | let delta = match key { 15 | VirtualKeyCode::Left => Point::new(-1, 0), 16 | VirtualKeyCode::Right => Point::new(1, 0), 17 | VirtualKeyCode::Up => Point::new(0, -1), 18 | VirtualKeyCode::Down => Point::new(0, 1), 19 | _ => Point::new(0, 0), 20 | }; 21 | 22 | players.iter(ecs).for_each(| (entity, pos) | { 23 | let destination = *pos + delta; 24 | commands 25 | .push(((), WantsToMove{ entity: *entity, destination })); 26 | }); 27 | *turn_state = TurnState::PlayerTurn; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::()); 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2); 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move."); 17 | draw_batch.bar_horizontal( 18 | Point::zero(), 19 | SCREEN_WIDTH*2, 20 | player_health.current, 21 | player_health.max, 22 | ColorPair::new(RED, BLACK) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/systems/entity_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Render)] 6 | #[read_component(FieldOfView)] 7 | #[read_component(Player)] 8 | pub fn entity_render( 9 | #[resource] camera: &Camera, 10 | ecs: &SubWorld, 11 | ) { 12 | let mut renderables = <(&Point, &Render)>::query(); 13 | let mut fov = <&FieldOfView>::query().filter(component::()); 14 | let mut draw_batch = DrawBatch::new(); 15 | draw_batch.target(1); 16 | let offset = Point::new(camera.left_x, camera.top_y); 17 | 18 | let player_fov = fov.iter(ecs).nth(0).unwrap(); 19 | 20 | renderables. 21 | iter(ecs) 22 | .filter(|(pos, _)| player_fov.visible_tiles.contains(&pos)) 23 | .for_each(|(pos, render)| { 24 | draw_batch.set( 25 | *pos - offset, 26 | render.color, 27 | render.glyph 28 | ); 29 | } 30 | ); 31 | 32 | draw_batch.submit(5000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /Loot/loot_tables/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /MapTheming/themed/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /WhatCanISee/fov/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /WhatCanISee/eyesight/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /WhatCanISee/memory/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /DeeperDungeons/more_levels/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/systems/player_input.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Point)] 5 | #[read_component(Player)] 6 | pub fn player_input( 7 | ecs: &mut SubWorld, 8 | commands: &mut CommandBuffer, 9 | #[resource] key: &Option, 10 | #[resource] turn_state: &mut TurnState 11 | ) { 12 | let mut players = <(Entity, &Point)>::query() 13 | .filter(component::()); 14 | 15 | if let Some(key) = *key { 16 | let delta = match key { 17 | VirtualKeyCode::Left => Point::new(-1, 0), 18 | VirtualKeyCode::Right => Point::new(1, 0), 19 | VirtualKeyCode::Up => Point::new(0, -1), 20 | VirtualKeyCode::Down => Point::new(0, 1), 21 | _ => Point::new(0, 0), 22 | }; 23 | 24 | players.iter(ecs).for_each(| (entity, pos) | { 25 | let destination = *pos + delta; 26 | commands 27 | .push(((), WantsToMove{ entity: *entity, destination })); 28 | }); 29 | *turn_state = TurnState::PlayerTurn; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /WinningAndLosing/losing/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /WinningAndLosing/winning/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/cellular/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/drunkard/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/prefab/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /InventoryAndPowerUps/carrying_items/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /MoreInterestingDungeons/traits_rooms/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::());// (1) 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) // (2) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2);// (3) 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move.");// (4) 17 | draw_batch.bar_horizontal(// (5) 18 | Point::zero(),// (6) 19 | SCREEN_WIDTH*2,// (7) 20 | player_health.current,// (8) 21 | player_health.max,// (9) 22 | ColorPair::new(RED, BLACK)// (10) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::());// (1) 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) // (2) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2);// (3) 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move.");// (4) 17 | draw_batch.bar_horizontal(// (5) 18 | Point::zero(),// (6) 19 | SCREEN_WIDTH*2,// (7) 20 | player_health.current,// (8) 21 | player_health.max,// (9) 22 | ColorPair::new(RED, BLACK)// (10) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/hud.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(Health)] 5 | #[read_component(Player)] 6 | pub fn hud(ecs: &SubWorld) { 7 | let mut health_query = <&Health>::query().filter(component::());// (1) 8 | let player_health = health_query 9 | .iter(ecs) 10 | .nth(0) // (2) 11 | .unwrap(); 12 | 13 | let mut draw_batch = DrawBatch::new(); 14 | draw_batch.target(2);// (3) 15 | draw_batch.print_centered(1, 16 | "Explore the Dungeon. Cursor keys to move.");// (4) 17 | draw_batch.bar_horizontal(// (5) 18 | Point::zero(),// (6) 19 | SCREEN_WIDTH*2,// (7) 20 | player_health.current,// (8) 21 | player_health.max,// (9) 22 | ColorPair::new(RED, BLACK)// (10) 23 | ); 24 | draw_batch.print_color_centered( 25 | 0, 26 | format!(" Health: {} / {} ", 27 | player_health.current, 28 | player_health.max 29 | ), 30 | ColorPair::new(WHITE, RED) 31 | ); 32 | draw_batch.submit(10000).expect("Batch error"); 33 | } 34 | -------------------------------------------------------------------------------- /InventoryAndPowerUps/potions_and_scrolls/src/systems/combat.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | #[read_component(WantsToAttack)] 5 | #[read_component(Player)] 6 | #[write_component(Health)] 7 | pub fn combat(ecs: &mut SubWorld, commands: &mut CommandBuffer) { 8 | let mut attackers = <(Entity, &WantsToAttack)>::query(); 9 | let victims : Vec<(Entity, Entity)> = attackers 10 | .iter(ecs) 11 | .map(|(entity, attack)| (*entity, attack.victim) ) 12 | .collect(); 13 | 14 | victims.iter().for_each(|(message, victim)| { 15 | let is_player = ecs 16 | .entry_ref(*victim) 17 | .unwrap() 18 | .get_component::() 19 | .is_ok(); 20 | 21 | if let Ok(mut health) = ecs 22 | .entry_mut(*victim) 23 | .unwrap() 24 | .get_component_mut::() 25 | { 26 | health.current -= 1; 27 | if health.current < 1 && !is_player { 28 | commands.remove(*victim); 29 | } 30 | } 31 | commands.remove(*message); 32 | }); 33 | } -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/systems/map_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn map_render(#[resource] map: &Map, #[resource] camera: &Camera) { 5 | let mut draw_batch = DrawBatch::new(); 6 | draw_batch.target(0); 7 | for y in camera.top_y ..= camera.bottom_y { 8 | for x in camera.left_x .. camera.right_x { 9 | let pt = Point::new(x, y); 10 | let offset = Point::new(camera.left_x, camera.top_y); 11 | if map.in_bounds(pt) { 12 | let idx = map_idx(x, y); 13 | let glyph = match map.tiles[idx] { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#'), 16 | }; 17 | draw_batch.set(// (1) 18 | pt - offset, 19 | ColorPair::new( 20 | WHITE, 21 | BLACK 22 | ), 23 | glyph 24 | ); 25 | } 26 | } 27 | } 28 | draw_batch.submit(0).expect("Batch error");// (2) 29 | } 30 | 31 | -------------------------------------------------------------------------------- /HealthSimpleMelee/combat/src/systems/map_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn map_render(#[resource] map: &Map, #[resource] camera: &Camera) { 5 | let mut draw_batch = DrawBatch::new(); 6 | draw_batch.target(0); 7 | for y in camera.top_y ..= camera.bottom_y { 8 | for x in camera.left_x .. camera.right_x { 9 | let pt = Point::new(x, y); 10 | let offset = Point::new(camera.left_x, camera.top_y); 11 | if map.in_bounds(pt) { 12 | let idx = map_idx(x, y); 13 | let glyph = match map.tiles[idx] { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#'), 16 | }; 17 | draw_batch.set(// (1) 18 | pt - offset, 19 | ColorPair::new( 20 | WHITE, 21 | BLACK 22 | ), 23 | glyph 24 | ); 25 | } 26 | } 27 | } 28 | draw_batch.submit(0).expect("Batch error");// (2) 29 | } 30 | 31 | -------------------------------------------------------------------------------- /HealthSimpleMelee/healing/src/systems/map_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn map_render(#[resource] map: &Map, #[resource] camera: &Camera) { 5 | let mut draw_batch = DrawBatch::new(); 6 | draw_batch.target(0); 7 | for y in camera.top_y ..= camera.bottom_y { 8 | for x in camera.left_x .. camera.right_x { 9 | let pt = Point::new(x, y); 10 | let offset = Point::new(camera.left_x, camera.top_y); 11 | if map.in_bounds(pt) { 12 | let idx = map_idx(x, y); 13 | let glyph = match map.tiles[idx] { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#'), 16 | }; 17 | draw_batch.set(// (1) 18 | pt - offset, 19 | ColorPair::new( 20 | WHITE, 21 | BLACK 22 | ), 23 | glyph 24 | ); 25 | } 26 | } 27 | } 28 | draw_batch.submit(0).expect("Batch error");// (2) 29 | } 30 | 31 | -------------------------------------------------------------------------------- /HealthSimpleMelee/health/src/systems/map_render.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | #[system] 4 | pub fn map_render(#[resource] map: &Map, #[resource] camera: &Camera) { 5 | let mut draw_batch = DrawBatch::new(); 6 | draw_batch.target(0); 7 | for y in camera.top_y ..= camera.bottom_y { 8 | for x in camera.left_x .. camera.right_x { 9 | let pt = Point::new(x, y); 10 | let offset = Point::new(camera.left_x, camera.top_y); 11 | if map.in_bounds(pt) { 12 | let idx = map_idx(x, y); 13 | let glyph = match map.tiles[idx] { 14 | TileType::Floor => to_cp437('.'), 15 | TileType::Wall => to_cp437('#'), 16 | }; 17 | draw_batch.set(// (1) 18 | pt - offset, 19 | ColorPair::new( 20 | WHITE, 21 | BLACK 22 | ), 23 | glyph 24 | ); 25 | } 26 | } 27 | } 28 | draw_batch.submit(0).expect("Batch error");// (2) 29 | } 30 | 31 | -------------------------------------------------------------------------------- /TurnBasedGames/intent/src/map.rs: -------------------------------------------------------------------------------- 1 | use crate::prelude::*; 2 | 3 | const NUM_TILES: usize = (SCREEN_WIDTH * SCREEN_HEIGHT) as usize; 4 | 5 | #[derive(Copy, Clone, PartialEq)] 6 | pub enum TileType { 7 | Wall, 8 | Floor, 9 | } 10 | 11 | pub fn map_idx(x: i32, y: i32) -> usize { 12 | ((y * SCREEN_WIDTH) + x) as usize 13 | } 14 | 15 | pub struct Map { 16 | pub tiles: Vec, 17 | } 18 | 19 | impl Map { 20 | pub fn new() -> Self { 21 | Self { 22 | tiles: vec![TileType::Floor; NUM_TILES], 23 | } 24 | } 25 | 26 | pub fn in_bounds(&self, point : Point) -> bool { 27 | point.x >= 0 && point.x < SCREEN_WIDTH && point.y >= 0 && point.y < SCREEN_HEIGHT 28 | } 29 | 30 | pub fn try_idx(&self, point : Point) -> Option { 31 | if !self.in_bounds(point) { 32 | None 33 | } else { 34 | Some(map_idx(point.x, point.y)) 35 | } 36 | } 37 | 38 | pub fn can_enter_tile(&self, point : Point) -> bool { 39 | self.in_bounds(point) && self.tiles[map_idx(point.x, point.y)]==TileType::Floor 40 | } 41 | } 42 | --------------------------------------------------------------------------------