initial commit

This commit is contained in:
deadvey 2025-02-09 15:04:43 +00:00
commit 3dbc3f3400
7 changed files with 239 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
Cargo.lock
target
*.swp

8
Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "wraithfate"
version = "0.1.0"
edition = "2021"
[dependencies]
colored = "2.2.0"
termion = "4.0.3"

71
data/ground_map.data Normal file
View File

@ -0,0 +1,71 @@
'''''''';;;;;;'''''''''''''''''''''';;;;;''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
'''''''';;;;;;'''''''''''''''''''''';;;;;'''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[[[[[
'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[[[
'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[
'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[i[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''''[[[[D[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[CC[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''''''''''''''''''''''''''''[[[[[[[[[[[[[[[[[[
'''''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''';;;;;;'''''''''''''''[[[[[CCC[[[[[[[[[
'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''''''';;;;'''';;;;''''''''''''[[[[[[[[[[[[[[[[[
'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''''';;;;;'''''''''';;;;;''''''''''[[[[[[[[[[[[[[[
'''''''';;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;''''''''''''';;;'''''''''''''''''';;''''''''''[[[[[[[[[[[[[[
'''''''';;;;;'''''''''''';;;;;;''''';;;;;''''''''';;;;;''''''''''''''''''''';;;;'''''''[[[[[[[[[[[[[[
'''''''';;;;;''''''''''''';;;;'''''';;;;;''''''';;;'''''''''''''''''''''''''''';;;'''''[[[[[[[[[[[[[[
''''''''''''''''''''''''';;;;;''''''''''''';;;;;'''''''''''''''''''''''''''''''';;;;;'''[[[[[[[[[[[[[
''''''''''''''''''''''''''';;;;;;''''''';;;;;'''''''''''''''''''''''''''''''''''''''';;;;;[[[[[[[[[[[
'''''''''''''''''''''''''''';;;;;;;''';;;''''''''''''''''''''''''''''''''''''''''''''';;;;;[[[[[[[[[[
'''''''''''''''''''''''''''''''';;;;;;;;''''''''''''''''''''''''''''''''''''''''''''''''';;[[[[[[[[[[
''''''''''''''''''''''''''''''''';;;;;'''''''''''''''''''''''''''''''''''''''''''''''''''';''[[[[[[[[
'''''''''''''''''''''''''''''''''';;;;;;;''''''''''''''''''''''''''''''''''''''''''''''''';;''[[[[[[[
'''''''''''''''''''''''''''''''''''''';;;;;'''''''''''''''''''''''''''''''''''''''''''''''';''''''[[[
''''''''''''''''''''''''''''''''''''''''';;;''''''''''''''''''''''''''''''''''''''''''''''';''''''''[
'''''''''''''''''''''''''''''''''''''''~'';;;;''''''~''''''''''''''''''''''''''''''''''''';''''''''''
'''''''''''''''''''''''''''''''''''''''~'''';;''''''~'''''''''''''''''''''''''''''''''''';'''''''''''
''''''''~''''''''''''''''''''''''''''''~''''';''''~~'''''''''''''''''''''''''''''''''''';;'''''''''''
''''''''~~~~~~~~~~''''''''''''''''''''~~''''';;''~~'''''''''''''''''''''''''''''''''''';;''''''''''''
'''''''''''''''''~~~~'''''''''''''''''~''''''';'~~'''''''''''''''''''''''''''''''''''';''''''''''''''
''''''''''''''''''''~~'''''''''''''''~~''''''';'~~''''''''''''''''''''''''''''''''''';'''''''''''''''
'''''''''''''''''''''~''''''''''''''~~~~~~~~~~%~~'''''''''''''''''''''''''''''''''''';'''''''''''''''
'''''''''''''''''''''~'''''''''''''~~~~~~~~~~~%~''''''''''''''''''''''''''''''''''''';;''''''''''''''
'''''''''''''''''''''~''''~~~'''''~~~~'''''''';'''''''''''''''''''''''''''''''''''''';;;'''''''''''''
'''''''''''''''''''''~~'''~~~~'''~~~''''''''''';'''''''''''''''''''''''''''''''''''';;'';;;;;;'''''''
''''''''''''''''''''''~~~~~~~~~~~~~'''''''''''';''''''''''''''''''''''''''''''''''';;'''''''';;;'''''
''''''''''''''''''''''~~~'''~~~'''''''''''''''';'''''''''''''''''''''''''''''''''';;''''''''''';;''''
''''''''''''''''''''''~~''''''''''''''''''''''';;''''''''''''''''''''''''''''''';;;''''''''''''';;;;;
''''''''''''''''''''''~~'''''''''''''''''''''''';;;''''''''''''''''''''''''''';;;''''''''''''''''''''
'''''''''''''''''''''~~''''''''''''''''''''''''''';;;;;;;''''''''''''''''';;;;;''''''''''''''''''''''
'''''''''''''''''''~~~'''''''''''''''''''''''''''''''''';;;;;;;;;;;;;;;;;;;'''''''''''''''''''''''''~
''''''''''''''''''~~~'''''''''''''''''''''''''''''''''''';;'''''''''''''''''''''''''''''''''''''''''~
'''''''''''''''::~~~~''''''''''''''''''''''''''''''''''';;''''''''''''''''''''''''''''''''''''''''''~
''''''''''''':::~~~~~:'''''''''''''''''''''''''''''''';;;;''''''''''''''''''''''''''''''''''''''''''~
:'''''''''''::::~~~~~~::'''''''''''''''''''''''''';;;;;;'''''''''''''''''''''''''''''''''''''''''''''
::::'''::::::~~~~;~~~~::::::'''''''''''''''';;;;;;;''''''''''''''''''''''''''''''''''''''''''''''''''
:::::::::~~~~~~~~~~~~:::::::::::::::''';;;;;;''''''''''''''''''''''''''''''''''''''''''''''''''''''''
:::~~~~~~~~~~~~~~~~~~~~:::::::::::::::;;;:::''''''''''''''''''''''''''''''''''''''''''''''~~~~~~~~~~~
:~~~~~~~~~~~~;;~~~~~~~~~~~:::::::::::;;:::::::::::::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~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~::::~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

49
data/test.data Normal file
View File

@ -0,0 +1,49 @@
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

BIN
images/fullmap.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

BIN
images/wraithfate.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

108
src/main.rs Normal file
View File

@ -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<Vec<char>> {
let mut ground_map: Vec<Vec<char>> = 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::<Vec<_>>(); // 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<Vec<char>>, player_coordinates: Coordinates, distance_you_can_see: [i16; 2]) {
print!("{}[2J", 27 as char); // Clear screen
let blocks: HashMap<char, [u8; 3]> = [
('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<Vec<char>> = parse_map(); // Parse the map file into a vector
output_map(ground_map, player_coordinates, distance_you_can_see); // Output the map
}