Added map module and when run, the program shows an empty map
This commit is contained in:
Generated
+1775
File diff suppressed because it is too large
Load Diff
+3
-2
@@ -2,7 +2,8 @@
|
|||||||
name = "rusty_dungeon"
|
name = "rusty_dungeon"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
author = "Rohmer Maxime <maxluligames@gmail.com>"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
date = "27/04/2022"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
bracket-lib = "~0.8.1"
|
||||||
@@ -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 |
+40
-2
@@ -1,3 +1,41 @@
|
|||||||
fn main() {
|
/// file : main.rs
|
||||||
println!("Hello, world!");
|
/// 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
@@ -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('#'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user