├── web
├── .gitignore
└── index.html
├── renovate.json
├── src
├── gamelog.rs
├── prefabs
│ ├── spawn_table_structs.rs
│ ├── loot_structs.rs
│ ├── prop_structs.rs
│ ├── item_structs.rs
│ ├── mob_structs.rs
│ └── mod.rs
├── map_builders
│ ├── waveform_collapse
│ │ ├── common.rs
│ │ ├── mod.rs
│ │ ├── constraints.rs
│ │ └── solver.rs
│ ├── room_corridor_spawner.rs
│ ├── room_based_starting_position.rs
│ ├── room_based_stairs.rs
│ ├── prefab_builder
│ │ ├── prefab_rooms.rs
│ │ ├── prefab_sections.rs
│ │ └── prefab_levels.rs
│ ├── room_based_spawner.rs
│ ├── cull_unreachable.rs
│ ├── rooms_corridors_bsp.rs
│ ├── simple_map.rs
│ ├── distant_exit.rs
│ ├── rooms_corridors_dogleg.rs
│ ├── room_sorter.rs
│ ├── voronoi_spawning.rs
│ ├── room_corner_rounding.rs
│ ├── room_draw.rs
│ ├── rooms_corridors_nearest.rs
│ ├── area_starting_points.rs
│ ├── rooms_corridors_lines.rs
│ ├── room_exploder.rs
│ ├── door_placement.rs
│ ├── cellular_automata.rs
│ ├── bsp_interior.rs
│ ├── bsp_dungeon.rs
│ ├── voronoi.rs
│ ├── forest.rs
│ ├── common.rs
│ ├── maze.rs
│ ├── drunkard.rs
│ └── dla.rs
├── rex_assets.rs
├── rect.rs
├── map
│ ├── dungeon.rs
│ ├── astar.rs
│ ├── tile_type.rs
│ ├── mod.rs
│ ├── themes.rs
│ └── fov.rs
├── game_system.rs
├── map_indexing_system.rs
├── random_table.rs
├── particle_system.rs
├── hunger_system.rs
├── trigger_system.rs
├── bystander_ai_system.rs
├── monster_ai_system.rs
├── visibility_system.rs
├── camera.rs
├── animal_ai_system.rs
├── spawner.rs
├── damage_system.rs
├── player.rs
└── components.rs
├── resources
├── nyan.xp
├── mltest.xp
├── vga8x16.jpg
├── wfc-demo1.xp
├── wfc-demo2.xp
├── terminal8x8.jpg
├── wfc-populated.xp
├── example_tiles.jpg
├── example_tiles.xcf
├── SmallDungeon_80x50.xp
├── backing.fs
├── backing.vs
├── scanlines.vs
├── console_no_bg.fs
├── console_with_bg.fs
├── console_no_bg.vs
├── console_with_bg.vs
└── scanlines.fs
├── .gitmodules
├── .gitignore
├── .vscode
└── settings.json
├── Cargo.toml
├── LICENSE
└── README.md
/web/.gitignore:
--------------------------------------------------------------------------------
1 | *.wasm
2 | *.js
3 | *.d.ts
4 |
--------------------------------------------------------------------------------
/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base"
4 | ]
5 | }
6 |
--------------------------------------------------------------------------------
/src/gamelog.rs:
--------------------------------------------------------------------------------
1 | pub struct GameLog {
2 | pub entries: Vec,
3 | }
4 |
--------------------------------------------------------------------------------
/resources/nyan.xp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/nyan.xp
--------------------------------------------------------------------------------
/resources/mltest.xp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/mltest.xp
--------------------------------------------------------------------------------
/resources/vga8x16.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/vga8x16.jpg
--------------------------------------------------------------------------------
/resources/wfc-demo1.xp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/wfc-demo1.xp
--------------------------------------------------------------------------------
/resources/wfc-demo2.xp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/wfc-demo2.xp
--------------------------------------------------------------------------------
/resources/terminal8x8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/terminal8x8.jpg
--------------------------------------------------------------------------------
/resources/wfc-populated.xp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/wfc-populated.xp
--------------------------------------------------------------------------------
/resources/example_tiles.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/example_tiles.jpg
--------------------------------------------------------------------------------
/resources/example_tiles.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/example_tiles.xcf
--------------------------------------------------------------------------------
/.gitmodules:
--------------------------------------------------------------------------------
1 | [submodule "external/legion"]
2 | path = external/legion
3 | url = https://github.com/TomGillen/legion.git
4 |
--------------------------------------------------------------------------------
/resources/SmallDungeon_80x50.xp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/smokku/rust_roguelike_tutorial/HEAD/resources/SmallDungeon_80x50.xp
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | /target/
4 |
5 | # These are backup files generated by rustfmt
6 | **/*.rs.bk
7 |
8 | # Do not commit savegame
9 | /savegame.json
10 |
--------------------------------------------------------------------------------
/resources/backing.fs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | out vec4 FragColor;
3 |
4 | in vec2 TexCoords;
5 |
6 | uniform sampler2D screenTexture;
7 |
8 | void main()
9 | {
10 | vec3 col = texture(screenTexture, TexCoords).rgb;
11 | FragColor = vec4(col, 1.0);
12 | }
--------------------------------------------------------------------------------
/resources/backing.vs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | layout (location = 0) in vec2 aPos;
3 | layout (location = 1) in vec2 aTexCoords;
4 |
5 | out vec2 TexCoords;
6 |
7 | void main()
8 | {
9 | TexCoords = aTexCoords;
10 | gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
11 | }
12 |
--------------------------------------------------------------------------------
/resources/scanlines.vs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | layout (location = 0) in vec2 aPos;
3 | layout (location = 1) in vec2 aTexCoords;
4 |
5 | out vec2 TexCoords;
6 |
7 | void main()
8 | {
9 | TexCoords = aTexCoords;
10 | gl_Position = vec4(aPos.x, aPos.y, 0.0, 1.0);
11 | }
12 |
--------------------------------------------------------------------------------
/src/prefabs/spawn_table_structs.rs:
--------------------------------------------------------------------------------
1 | use serde::Deserialize;
2 |
3 | #[derive(Deserialize, Debug)]
4 | pub struct SpawnTableEntry {
5 | pub name: String,
6 | pub weight: i32,
7 | pub min_depth: i32,
8 | pub max_depth: i32,
9 | pub add_map_depth_to_weight: Option,
10 | }
11 |
--------------------------------------------------------------------------------
/src/prefabs/loot_structs.rs:
--------------------------------------------------------------------------------
1 | use serde::Deserialize;
2 |
3 | #[derive(Deserialize, Debug)]
4 | pub struct LootTable {
5 | pub name: String,
6 | pub drops: Vec,
7 | }
8 |
9 | #[derive(Deserialize, Debug)]
10 | pub struct LootDrop {
11 | pub name: String,
12 | pub weight: i32,
13 | }
14 |
--------------------------------------------------------------------------------
/src/map_builders/waveform_collapse/common.rs:
--------------------------------------------------------------------------------
1 | use super::TileType;
2 |
3 | #[derive(PartialEq, Eq, Hash, Clone, Debug)]
4 | pub struct MapChunk {
5 | pub pattern: Vec,
6 | pub exits: [Vec; 4],
7 | pub has_exits: bool,
8 | pub compatible_with: [Vec; 4],
9 | }
10 |
11 | pub fn tile_idx_in_chunk(chunk_size: i32, x: i32, y: i32) -> usize {
12 | ((y * chunk_size) + x) as usize
13 | }
14 |
--------------------------------------------------------------------------------
/resources/console_no_bg.fs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | out vec4 FragColor;
3 |
4 | in vec3 ourColor;
5 | in vec2 TexCoord;
6 | in vec3 ourBackground;
7 |
8 | // texture sampler
9 | uniform sampler2D texture1;
10 |
11 | void main()
12 | {
13 | vec4 original = texture(texture1, TexCoord);
14 | if (original.r < 0.1f || original.g < 0.1f || original.b < 0.1f) discard;
15 | vec4 fg = original * vec4(ourColor, 1.f);
16 | FragColor = fg;
17 | }
18 |
--------------------------------------------------------------------------------
/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/resources/console_with_bg.fs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | out vec4 FragColor;
3 |
4 | in vec3 ourColor;
5 | in vec2 TexCoord;
6 | in vec3 ourBackground;
7 |
8 | // texture sampler
9 | uniform sampler2D texture1;
10 |
11 | void main()
12 | {
13 | vec4 original = texture(texture1, TexCoord);
14 | vec4 fg = original.r > 0.1f || original.g > 0.1f || original.b > 0.1f ? original * vec4(ourColor, 1.f) : vec4(ourBackground, 1.f);
15 | FragColor = fg;
16 | }
17 |
--------------------------------------------------------------------------------
/resources/console_no_bg.vs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | layout (location = 0) in vec3 aPos;
3 | layout (location = 1) in vec3 aColor;
4 | layout (location = 2) in vec3 bColor;
5 | layout (location = 3) in vec2 aTexCoord;
6 |
7 | out vec3 ourColor;
8 | out vec3 ourBackground;
9 | out vec2 TexCoord;
10 |
11 | void main()
12 | {
13 | gl_Position = vec4(aPos, 1.0);
14 | ourColor = aColor;
15 | ourBackground = bColor;
16 | TexCoord = vec2(aTexCoord.x, aTexCoord.y);
17 | }
--------------------------------------------------------------------------------
/resources/console_with_bg.vs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | layout (location = 0) in vec3 aPos;
3 | layout (location = 1) in vec3 aColor;
4 | layout (location = 2) in vec3 bColor;
5 | layout (location = 3) in vec2 aTexCoord;
6 |
7 | out vec3 ourColor;
8 | out vec3 ourBackground;
9 | out vec2 TexCoord;
10 |
11 | void main()
12 | {
13 | gl_Position = vec4(aPos, 1.0);
14 | ourColor = aColor;
15 | ourBackground = bColor;
16 | TexCoord = vec2(aTexCoord.x, aTexCoord.y);
17 | }
--------------------------------------------------------------------------------
/src/prefabs/prop_structs.rs:
--------------------------------------------------------------------------------
1 | use super::Renderable;
2 | use serde::Deserialize;
3 | use std::collections::HashMap;
4 |
5 | #[derive(Deserialize, Debug)]
6 | pub struct Prop {
7 | pub name: String,
8 | pub renderable: Option,
9 | pub hidden: Option,
10 | pub blocks_tile: Option,
11 | pub blocks_visibility: Option,
12 | pub door_open: Option,
13 | pub entry_trigger: Option,
14 | }
15 |
16 | #[derive(Deserialize, Debug)]
17 | pub struct EntryTrigger {
18 | pub effects: HashMap,
19 | }
20 |
--------------------------------------------------------------------------------
/src/rex_assets.rs:
--------------------------------------------------------------------------------
1 | use rltk::rex::XpFile;
2 |
3 | rltk::embedded_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
4 | rltk::embedded_resource!(WFC_DEMO_IMAGE1, "../resources/wfc-demo1.xp");
5 | rltk::embedded_resource!(WFC_POPULATED, "../resources/wfc-populated.xp");
6 |
7 | pub struct RexAssets {
8 | pub menu: XpFile,
9 | }
10 |
11 | impl RexAssets {
12 | pub fn new() -> Self {
13 | rltk::link_resource!(SMALL_DUNGEON, "../resources/SmallDungeon_80x50.xp");
14 | rltk::link_resource!(WFC_DEMO_IMAGE1, "../resources/wfc-demo1.xp");
15 | rltk::link_resource!(WFC_POPULATED, "../resources/wfc-populated.xp");
16 |
17 | RexAssets {
18 | menu: XpFile::from_resource("../resources/SmallDungeon_80x50.xp").unwrap(),
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/rect.rs:
--------------------------------------------------------------------------------
1 | use serde::{Deserialize, Serialize};
2 |
3 | #[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
4 | pub struct Rect {
5 | pub x1: i32,
6 | pub x2: i32,
7 | pub y1: i32,
8 | pub y2: i32,
9 | }
10 |
11 | impl Rect {
12 | pub fn new(x: i32, y: i32, w: i32, h: i32) -> Rect {
13 | Rect {
14 | x1: x,
15 | y1: y,
16 | x2: x + w,
17 | y2: y + h,
18 | }
19 | }
20 |
21 | // Returns true if this overlaps with other
22 | pub fn intersects(&self, other: &Self) -> bool {
23 | self.x1 <= other.x2 && self.x2 >= other.x1 && self.y1 <= other.y2 && self.y2 >= other.y1
24 | }
25 |
26 | pub fn center(&self) -> (i32, i32) {
27 | ((self.x1 + self.x2) / 2, (self.y1 + self.y2) / 2)
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/resources/scanlines.fs:
--------------------------------------------------------------------------------
1 | #version 330 core
2 | out vec4 FragColor;
3 |
4 | in vec2 TexCoords;
5 |
6 | uniform sampler2D screenTexture;
7 | uniform vec3 screenSize;
8 | uniform bool screenBurn;
9 |
10 | void main()
11 | {
12 | vec3 col = texture(screenTexture, TexCoords).rgb;
13 | float scanLine = mod(gl_FragCoord.y, 2.0) * 0.25;
14 | vec3 scanColor = col.rgb - scanLine;
15 |
16 | if (col.r < 0.1f && col.g < 0.1f && col.b < 0.1f) {
17 | if (screenBurn) {
18 | float dist = (1.0 - distance(vec2(gl_FragCoord.x / screenSize.x, gl_FragCoord.y / screenSize.y), vec2(0.5,0.5))) * 0.2;
19 | FragColor = vec4(0.0, dist, dist, 1.0);
20 | } else {
21 | FragColor = vec4(0.0, 0.0, 0.0, 1.0);
22 | }
23 | } else {
24 | FragColor = vec4(scanColor, 1.0);
25 | }
26 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "cSpell.words": [
3 | "astar",
4 | "backtrace",
5 | "bindgen",
6 | "bresenham",
7 | "chebyshev",
8 | "dedupe",
9 | "deser",
10 | "equippable",
11 | "gamelog",
12 | "greyscale",
13 | "insectoid",
14 | "longsword",
15 | "mapgen",
16 | "numpad",
17 | "rects",
18 | "renderable",
19 | "rltk",
20 | "roguelike",
21 | "runstate",
22 | "savegame",
23 | "saveload",
24 | "scanlines",
25 | "schedulable",
26 | "structs",
27 | "unequip",
28 | "unserializable",
29 | "uuid",
30 | "viewshed",
31 | "viewsheds",
32 | "voronoi"
33 | ],
34 | "search.exclude": {
35 | "external/**": true
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/map/dungeon.rs:
--------------------------------------------------------------------------------
1 | use super::Map;
2 | use serde::{Deserialize, Serialize};
3 | use std::collections::HashMap;
4 |
5 | #[derive(Default, Serialize, Deserialize, Clone)]
6 | pub struct MasterDungeonMap {
7 | maps: HashMap,
8 | }
9 |
10 | impl MasterDungeonMap {
11 | pub fn new() -> Self {
12 | MasterDungeonMap {
13 | maps: HashMap::new(),
14 | }
15 | }
16 |
17 | pub fn store_map(&mut self, map: &Map) {
18 | self.maps.insert(map.depth, map.clone());
19 | }
20 |
21 | pub fn get_map(&self, depth: i32) -> Option