diff options
| -rw-r--r-- | docs/Proposal.md | 39 | ||||
| -rw-r--r-- | graphics/src/lib.rs | 20 | ||||
| -rw-r--r-- | graphics/src/render.rs | 19 |
3 files changed, 67 insertions, 11 deletions
diff --git a/docs/Proposal.md b/docs/Proposal.md index 9dc71a0..76e8bd6 100644 --- a/docs/Proposal.md +++ b/docs/Proposal.md @@ -15,16 +15,14 @@ Collapse algorithm. Battle through waves of enemies with real-time combat, collect powerful items, and push your limits to see how deep you can delve into the ever-changing depths. -## Additional Details +## Use Cases -### Use Cases - -#### Player Input +### Player Input - Directional Movement: The player can move up, down, left, or right across a tile-based dungeon map using WASD or arrow keys. - Combat Actions: On encountering an enemy, the player can choose to attack or use an item. - Item Interaction: The player can pick up items, manage inventory, and use consumables like potions. -#### Gameplay Loop +### Gameplay Loop - The player spawns on floor 1 of the dungeon. - The map is procedurally generated using the Wave Function Collapse algorithm. - Enemies and items are randomly spawned on valid tiles based on probabilities. @@ -38,14 +36,33 @@ One or more typical “use cases”. These might include “storyboards” expla how a user would interact with the program or some interesting “input/output” examples. -### Components +## Components + +### **Game Binary Crate** +- **[main](game\src\main.rs)** - Initializes the game state and handles the Model-View-Controller loop. + +### **Dungeon Library Crate** +Core functionality for interacting with a `Dungeon` data structure and its components. + - `Dungeon` - The game state of the dungeon crawler. +- **[Map Module](dungeon\src\map.rs)** - Structures for the dungeon game map including the current `Floor`, map `Tile`, and `Entity`. + - `Floor` - Current playing grid of the dungeon. It contains the tiles of the grid, and the starting position of the player. + - `Tile` - Enum that represents what is (or is not) at any given spot in the dungeon grid. + - `Entity` - The main player, or any other ai autonomous character that can move freely across the dungeon. +- **[Position Module](dungeon\src\pos.rs)** - Structures for representation an entity or objects position and facing direction inside the dungeon grid. + - `Direction` - Enum that representa the direction an entity or any position object is facing inside the dungeon map. Since the dungeon lives on a grid, there are only four possible directions. + - `Pos` - 2D position inside the dungeon grid. + +### **Graphics Library Crate** +Core functionality for rendering using the `raylib` library. Independent from game logic. +- **[Render Module](graphics\src\render.rs)** - The `render` module contains the structures for displaying the game, with each frame represented by a `Renderer` and frame specific information in `FrameInfo`. + - -**Dungeon** -- A sketch of intended components (key functions, key data structures, separate - modules). -### Testing + +- A sketch of intended components (key functions, key data structures, separate modules). + +## Testing - Thoughts on testing. These might include critical functions or data structures that will be given `#[test]` functions. Also consider using the [`insta`](https://crates.io/crates/insta) crate, @@ -54,6 +71,8 @@ One or more typical “use cases”. These might include “storyboards” expla [`quickcheck`](https://crates.io/crates/quickcheck) crate, [`test_case`](https://crates.io/crates/test-case) crate, or [`cargo fuzz`](https://rust-fuzz.github.io/book/cargo-fuzz.html) tool. + + - Thoughts on a “minimal viable product” and “stretch goals”. Be sure to review the final project grading rubric and consider organizing the project around a core deliverable that will almost certainly be achieved and then a number of diff --git a/graphics/src/lib.rs b/graphics/src/lib.rs index 5f44e41..4f55388 100644 --- a/graphics/src/lib.rs +++ b/graphics/src/lib.rs @@ -1,9 +1,14 @@ +//! The `graphics` crate contains the core functionality for +//! rendering using the `raylib` library. + use raylib::prelude::*; use crate::render::{FrameInfo, Renderer}; pub mod render; +/// The `Window` type represents the game window +#[derive(Debug)] pub struct Window { handle: RaylibHandle, thread: RaylibThread, @@ -12,6 +17,13 @@ pub struct Window { impl Window { /// Instantiates a new window provided with the default /// window `width`, `height`, and `title`. + /// + /// # Examples + /// ```no_run + /// use graphics::Window; + /// + /// let window = Window::new(800, 600, "Dungeon Crawl"); + /// ``` pub fn new(width: i32, height: i32, title: &str) -> Self { let (handle, thread) = raylib::init() .size(width, height) @@ -30,6 +42,14 @@ impl Window { } /// Returns the renderer for the game + /// + /// # Examples + /// ```no_run + /// use graphics::Window; + /// + /// let mut window = Window::new(800, 600, "Dungeon Crawl"); + /// let mut renderer = window.renderer(); + /// ``` pub fn renderer(&mut self) -> Renderer<'_> { let info = FrameInfo::new(&self.handle); let handle = self.handle.begin_drawing(&self.thread); diff --git a/graphics/src/render.rs b/graphics/src/render.rs index add19ab..68a7b68 100644 --- a/graphics/src/render.rs +++ b/graphics/src/render.rs @@ -1,10 +1,15 @@ +//! The `render` module contains the structures for displaying +//! the game, with each frame represented by a `Renderer` and +//! frame specific information in `FrameInfo`. + use dungeon::{Dungeon, Entity}; use raylib::{ color::Color, prelude::{RaylibDraw, RaylibDrawHandle, RaylibHandle}, }; -/// Information used each frame +/// The `FrameInfo` struct contains information about +/// the current frame being rendered. pub struct FrameInfo { /// Time in seconds since last frame drawn pub delta: f32, @@ -12,6 +17,8 @@ pub struct FrameInfo { pub fps: u32, } impl FrameInfo { + /// Creates a new `FrameInfo` from the provided + /// `RaylibHandle`. pub fn new(handle: &RaylibHandle) -> Self { Self { delta: handle.get_frame_time(), @@ -58,6 +65,16 @@ impl<'a> Renderer<'a> { } /// Draws an entire frame + /// + /// # Examples + /// ```no_run + /// use dungeon::Dungeon; + /// use graphics::Window; + /// let mut window = Window::new(800, 600, "Dungeon Crawl"); + /// let mut renderer = window.renderer(); + /// let dungeon = Dungeon::new(); + /// renderer.draw_frame(&dungeon); + /// ``` pub fn draw_frame(&mut self, dungeon: &Dungeon) { // Clear the background to black self.clear(); |