commit 3dbc3f3400d3e413a8ddd8328e9a1c5ba3c9bc20 Author: deadvey Date: Sun Feb 9 15:04:43 2025 +0000 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..cee61fe --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +Cargo.lock +target +*.swp diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..75dba9a --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "wraithfate" +version = "0.1.0" +edition = "2021" + +[dependencies] +colored = "2.2.0" +termion = "4.0.3" diff --git a/data/ground_map.data b/data/ground_map.data new file mode 100644 index 0000000..6171c68 --- /dev/null +++ b/data/ground_map.data @@ -0,0 +1,71 @@ +'''''''';;;;;;'''''''''''''''''''''';;;;;''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ +'''''''';;;;;;'''''''''''''''''''''';;;;;'''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ +'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[ +'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[ +'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[i[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''''[[[[D[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[CC[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[ +'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''';;;;;;'''''''''''''''[[[[[CCC[[[[[[[[[ +'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''';;;;'''';;;;''''''''''''[[[[[[[[[[[[[[[[[ +'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''';;;;;'''''''''';;;;;''''''''''[[[[[[[[[[[[[[[ +'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''';;;'''''''''''''''''';;''''''''''[[[[[[[[[[[[[[ +'''''''';;;;;'''''''''''';;;;;;''''';;;;;''''''''';;;;;''''''''''''''''''''';;;;'''''''[[[[[[[[[[[[[[ +'''''''';;;;;''''''''''''';;;;'''''';;;;;''''''';;;'''''''''''''''''''''''''''';;;'''''[[[[[[[[[[[[[[ +''''''''''''''''''''''''';;;;;''''''''''''';;;;;'''''''''''''''''''''''''''''''';;;;;'''[[[[[[[[[[[[[ +''''''''''''''''''''''''''';;;;;;''''''';;;;;'''''''''''''''''''''''''''''''''''''''';;;;;[[[[[[[[[[[ +'''''''''''''''''''''''''''';;;;;;;''';;;''''''''''''''''''''''''''''''''''''''''''''';;;;;[[[[[[[[[[ +'''''''''''''''''''''''''''''''';;;;;;;;''''''''''''''''''''''''''''''''''''''''''''''''';;[[[[[[[[[[ +''''''''''''''''''''''''''''''''';;;;;'''''''''''''''''''''''''''''''''''''''''''''''''''';''[[[[[[[[ +'''''''''''''''''''''''''''''''''';;;;;;;''''''''''''''''''''''''''''''''''''''''''''''''';;''[[[[[[[ +'''''''''''''''''''''''''''''''''''''';;;;;'''''''''''''''''''''''''''''''''''''''''''''''';''''''[[[ +''''''''''''''''''''''''''''''''''''''''';;;''''''''''''''''''''''''''''''''''''''''''''''';''''''''[ +'''''''''''''''''''''''''''''''''''''''~'';;;;''''''~''''''''''''''''''''''''''''''''''''';'''''''''' +'''''''''''''''''''''''''''''''''''''''~'''';;''''''~'''''''''''''''''''''''''''''''''''';''''''''''' +''''''''~''''''''''''''''''''''''''''''~''''';''''~~'''''''''''''''''''''''''''''''''''';;''''''''''' +''''''''~~~~~~~~~~''''''''''''''''''''~~''''';;''~~'''''''''''''''''''''''''''''''''''';;'''''''''''' +'''''''''''''''''~~~~'''''''''''''''''~''''''';'~~'''''''''''''''''''''''''''''''''''';'''''''''''''' +''''''''''''''''''''~~'''''''''''''''~~''''''';'~~''''''''''''''''''''''''''''''''''';''''''''''''''' +'''''''''''''''''''''~''''''''''''''~~~~~~~~~~%~~'''''''''''''''''''''''''''''''''''';''''''''''''''' +'''''''''''''''''''''~'''''''''''''~~~~~~~~~~~%~''''''''''''''''''''''''''''''''''''';;'''''''''''''' +'''''''''''''''''''''~''''~~~'''''~~~~'''''''';'''''''''''''''''''''''''''''''''''''';;;''''''''''''' +'''''''''''''''''''''~~'''~~~~'''~~~''''''''''';'''''''''''''''''''''''''''''''''''';;'';;;;;;''''''' +''''''''''''''''''''''~~~~~~~~~~~~~'''''''''''';''''''''''''''''''''''''''''''''''';;'''''''';;;''''' +''''''''''''''''''''''~~~'''~~~'''''''''''''''';'''''''''''''''''''''''''''''''''';;''''''''''';;'''' +''''''''''''''''''''''~~''''''''''''''''''''''';;''''''''''''''''''''''''''''''';;;''''''''''''';;;;; +''''''''''''''''''''''~~'''''''''''''''''''''''';;;''''''''''''''''''''''''''';;;'''''''''''''''''''' +'''''''''''''''''''''~~''''''''''''''''''''''''''';;;;;;;''''''''''''''''';;;;;'''''''''''''''''''''' +'''''''''''''''''''~~~'''''''''''''''''''''''''''''''''';;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''~ +''''''''''''''''''~~~'''''''''''''''''''''''''''''''''''';;'''''''''''''''''''''''''''''''''''''''''~ +'''''''''''''''::~~~~''''''''''''''''''''''''''''''''''';;''''''''''''''''''''''''''''''''''''''''''~ +''''''''''''':::~~~~~:'''''''''''''''''''''''''''''''';;;;''''''''''''''''''''''''''''''''''''''''''~ +:'''''''''''::::~~~~~~::'''''''''''''''''''''''''';;;;;;''''''''''''''''''''''''''''''''''''''''''''' +::::'''::::::~~~~;~~~~::::::'''''''''''''''';;;;;;;'''''''''''''''''''''''''''''''''''''''''''''''''' +:::::::::~~~~~~~~~~~~:::::::::::::::''';;;;;;'''''''''''''''''''''''''''''''''''''''''''''''''''''''' +:::~~~~~~~~~~~~~~~~~~~~:::::::::::::::;;;:::''''''''''''''''''''''''''''''''''''''''''''''~~~~~~~~~~~ +:~~~~~~~~~~~~;;~~~~~~~~~~~:::::::::::;;:::::::::::::::::''''''''''''''''''''''~~~~~~~~~~~~~~~~~~''''' +~~~~~~~~~~~~~~;~~~~~~~~~~~~~~~~~~:::::;;:::::::::::::::::::::::::::::::~~~~~~~~~~:::::::::''''''''''' +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:::;:::::::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::::::::::::::::::::'' +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:;:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::::::::::::::::::::::::::::: +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::::::::::::~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~;;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::;:~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::;;:::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~:::::::::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::::::::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::::::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/data/test.data b/data/test.data new file mode 100644 index 0000000..8caace7 --- /dev/null +++ b/data/test.data @@ -0,0 +1,49 @@ +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' diff --git a/images/fullmap.png b/images/fullmap.png new file mode 100644 index 0000000..96f55c7 Binary files /dev/null and b/images/fullmap.png differ diff --git a/images/wraithfate.png b/images/wraithfate.png new file mode 100644 index 0000000..979926a Binary files /dev/null and b/images/wraithfate.png differ diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..c263d63 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,108 @@ +use std::fs; // For reading the map and save files +use colored::Colorize; // For coloring the output +use std::collections::HashMap; + +struct Coordinates { + x: i16, + y: i16, + z: i16, +} + +// This function reads the map file and puts it into a 2d vector of integers, each integer +// Refers to a block (see top comment) and the function returns this vector +fn parse_map() -> Vec> { + let mut ground_map: Vec> = Vec::new(); // Initialises the map vector + + // Read the ground map file + let file_contents: String = fs::read_to_string("data/ground_map.data").unwrap(); // Reads the file + let ground_rows = file_contents.split("\n").collect::>(); // Split the file contents into rows + + // Loop over each row to parse each column of it + for row in 0..ground_rows.len() { + // Turn each column into an integer and collect it into a row vector + let current_row = ground_rows[row].chars().collect(); + ground_map.push(current_row); // Then push this vector to the full map vector + } + + return ground_map +} + +// Output the map based on map vector +fn output_map(ground_map: Vec>, player_coordinates: Coordinates, distance_you_can_see: [i16; 2]) { + print!("{}[2J", 27 as char); // Clear screen + + let blocks: HashMap = [ + ('X', [255,0, 0]), // Null + ('\'', [0, 255,0]), // Grass + (';', [128,128,128]), // Cobbles + ('~', [0, 0, 255]), // Water/sea + ('D', [0, 128,128]), // Diamond + ('C', [0, 0, 0]), // Coal + ('i', [138,74 ,24]), // Iron + ('%', [195,162,103]), // Wood planks + (':', [195,162,103]), // Sand + ('[', [196,196,196]), // Stone + ] + .iter().cloned().collect(); + + // Loop over array and print each block + for i in player_coordinates.z - distance_you_can_see[1]..player_coordinates.z + distance_you_can_see[1] { + if i >= 0 && i < ground_map.len() as i16 { + for j in player_coordinates.x - distance_you_can_see[0]..player_coordinates.x+distance_you_can_see[0] { + if j >= 0 && j < ground_map[i as usize].len() as i16 { + let character: char = ground_map[i as usize][j as usize]; + if i == player_coordinates.z && j == player_coordinates.x { + print!("{}"," " + .on_truecolor(40,235,181) + .truecolor(0,0,0) + ) + } + else if blocks.contains_key(&character) { + print!("{}",character // Output's the current block + .to_string() + .truecolor( + blocks.get(&character).unwrap()[0], + blocks.get(&character).unwrap()[1], + blocks.get(&character).unwrap()[2] + ) + ) + } + else { + print!("{}","X" + .to_string() + .truecolor( + blocks.get(&'X').unwrap()[0], + blocks.get(&'X').unwrap()[1], + blocks.get(&'X').unwrap()[2] + ) + ) + } + } + } + println!(""); + } + } +} + +fn main() { + let debug_mode = true; + + let player_coordinates: Coordinates = Coordinates { + x: 30, + y: 1, + z: 30, + }; + let (screen_width, screen_height) = termion::terminal_size().unwrap(); + + if debug_mode { + println!("Screen Width: {}, Screen Height: {}", screen_width, screen_height); + } + + let distance_you_can_see: [i16; 2] = [ + (screen_width as f32 / 2.0) as i16, + (screen_height as f32 / 2.0) as i16 + ]; + + let ground_map: Vec> = parse_map(); // Parse the map file into a vector + output_map(ground_map, player_coordinates, distance_you_can_see); // Output the map +}