Added map module and when run, the program shows an empty map

This commit is contained in:
2022-04-26 13:39:46 +02:00
parent ecc3630cae
commit 814ca0214a
6 changed files with 1871 additions and 4 deletions

1775
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,8 @@
name = "rusty_dungeon"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
author = "Rohmer Maxime <maxluligames@gmail.com>"
date = "27/04/2022"
[dependencies]
bracket-lib = "~0.8.1"

4
doc/progress.md Normal file
View File

@@ -0,0 +1,4 @@
# Devloppement Progress with screenshots
First running programm with an empty map
<img src="./screenshots/EmptyMap.png" width="80%">

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -1,3 +1,41 @@
fn main() {
println!("Hello, world!");
/// file : main.rs
/// author : Maxime Rohmer (from Herbet Wolverson book)
/// version : 0.1.0
/// date : 26/04/2022
/// brief : Main game file
mod map;
mod prelude {
pub use bracket_lib::prelude::*;
pub const SCREEN_WIDTH: i32 = 80;
pub const SCREEN_HEIGHT: i32 = 50;
pub use crate::map::*;
}
use prelude::*;
const FPS_CAP : f32 = 30.0;
struct State {
map: Map,
}
impl State {
fn new() -> Self {
Self {map: Map::new()}
}
}
impl GameState for State{
fn tick(&mut self,ctx: &mut BTerm){
ctx.cls();
//ctx.print(1,1,"Hello, Bracket Terminal!");
self.map.render(ctx);
}
}
fn main() -> BError{
let context = BTermBuilder::simple80x50()
.with_title("RustyDungeon")
.with_fps_cap(FPS_CAP)
.build()?;
main_loop(context,State::new())
}

49
src/map.rs Normal file
View File

@@ -0,0 +1,49 @@
/// file : map.rs
/// author : Maxime Rohmer (from Herbet Wolverson book)
/// version : 0.1.0
/// date : 26/04/2022
/// brief : File that contains all the map related stuff
use crate::prelude::*;
const NUM_TILES: usize = (SCREEN_WIDTH * SCREEN_HEIGHT) as usize;
#[derive(Copy, Clone, PartialEq)]
pub enum TileType {
Wall,
Floor,
}
pub struct Map {
pub tiles: Vec<TileType>,
}
pub fn map_idx(x: i32, y: i32) -> usize {
((y * SCREEN_WIDTH) + x)as usize
}
impl Map {
pub fn new() -> Self{
Self {
tiles: vec![TileType::Floor; NUM_TILES],
}
}
/*
pub fn in_bounds(&self,point : Point) -> bool{
point.x >=
}
*/
pub fn render(&self, ctx: &mut BTerm){
for y in 0..SCREEN_HEIGHT{
for x in 0..SCREEN_WIDTH {
let idx = map_idx(x,y);
match self.tiles[idx] {
TileType::Floor =>{
ctx.set(x,y, YELLOW,BLACK,to_cp437('.'));
}
TileType::Wall =>{
ctx.set(x,y, GREEN, BLACK,to_cp437('#'));
}
}
}
}
}
}