solid obstacles and colours

This commit is contained in:
deadvey 2024-12-24 20:32:33 +00:00
parent 97ef9ef183
commit 7f6f4cfb41
2 changed files with 30 additions and 17 deletions

View File

@ -7,3 +7,4 @@ edition = "2024"
rand = "0.8.5" rand = "0.8.5"
console = "0.15.10" console = "0.15.10"
termion = "4.0.3" termion = "4.0.3"
colored = "2.2.0"

View File

@ -1,12 +1,13 @@
use rand::Rng; // Allows you to generate random numbers use rand::Rng; // Allows you to generate random numbers
use console::Term; // Allows reading key bind input use console::Term; // Allows reading key bind input
use std::io::{stdin,stdout,Write}; use std::io::{stdin,stdout,Write};
use colored::Colorize;
// This function is used to Generate the output out a range of levels to the console, it accepts starting and // This function is used to Generate the output out a range of levels to the console, it accepts starting and
// ending levls to print and then it uses a loop to print out each level in between these, each // ending levls to print and then it uses a loop to print out each level in between these, each
// level is comprised of numbers, each having a specific meaning for instance 0 is an obstacle and // level is comprised of numbers, each having a specific meaning for instance 0 is an obstacle and
// -2 is a slanted wall "/" // -2 is a slanted wall "/"
fn generate_output(starting_level: u64, ending_level: u64, character_x_coord: u16, character_icon: char, levels: &Vec<Vec<i8>>, debug_mode: bool) -> String { fn generate_output(starting_level: u64, ending_level: u64, character_x_coord: u16, character_icon: char, levels: &Vec<Vec<i8>>, debug_mode: bool, boots_mode: bool) -> String {
let mut output: String = "".to_string(); let mut output: String = "".to_string();
if debug_mode { if debug_mode {
let pattern = "0123456789"; let pattern = "0123456789";
@ -22,12 +23,16 @@ fn generate_output(starting_level: u64, ending_level: u64, character_x_coord: u1
// Directly check the player's position for rendering the icon // Directly check the player's position for rendering the icon
if i == starting_level && j == character_x_coord as usize { if i == starting_level && j == character_x_coord as usize {
output = output + &character_icon.to_string(); output = output + &character_icon.to_string();
} else { }
else if i == starting_level+2 && j == character_x_coord as usize {
output = output + &character_icon.to_string();
}
else {
match object { match object {
-3 => output+="|", // Specific case for -3 -3 => output.push_str(&"|".to_string()), // Specific case for -3
0 => output+="", // Specific case for 0 0 => output.push_str(&"|".on_truecolor(255,255,255).strikethrough().to_string()), // Specific case for 0
-1 => output+="\\", // Specific case for -1 -1 => output.push_str(&"\\".to_string()), // Specific case for -1
-2 => output+="/", // Specific case for -2 -2 => output.push_str(&"/".to_string()), // Specific case for -2
_ => output+=" " // Default, no print for other cases _ => output+=" " // Default, no print for other cases
} }
} }
@ -132,8 +137,8 @@ fn debug_mode_modify_variables(current_level: &mut u64) -> u8 {
return 1; return 1;
} }
fn check_if_alive(levels: &Vec<Vec<i8>>, level: usize, x_coord: usize) -> bool { fn check_if_alive(levels: &Vec<Vec<i8>>, level: usize, x_coord: usize, boots_mode: bool) -> bool {
if levels[level][x_coord] <= 0 { if levels[level][x_coord] <= 0 || levels[level+2][x_coord] <= 0 {
return false; return false;
} }
else { else {
@ -159,6 +164,9 @@ fn main() {
// let you modify stats midgame with e // let you modify stats midgame with e
let can_die = true; // I can't spell invinsiblitlity but this lets you not die... let can_die = true; // I can't spell invinsiblitlity but this lets you not die...
let boots_mode = true; // Boots mode means you're falling after your younger sister and have to
// prevent both of you dying •_•
let mut levels: Vec<Vec<i8>> = Vec::new(); // Define variables for level let mut levels: Vec<Vec<i8>> = Vec::new(); // Define variables for level
let (mut screen_width, mut screen_height) = termion::terminal_size().unwrap(); let (mut screen_width, mut screen_height) = termion::terminal_size().unwrap();
@ -180,7 +188,7 @@ fn main() {
let mut right_wall: i16 = rand::thread_rng().gen_range(((screen_width as f32 /2.0)+5.0) as i16..screen_width as i16) as i16; let mut right_wall: i16 = rand::thread_rng().gen_range(((screen_width as f32 /2.0)+5.0) as i16..screen_width as i16) as i16;
let mut preference: f32 = rand::thread_rng().gen_range(-2.0..3.0); let mut preference: f32 = rand::thread_rng().gen_range(-2.0..3.0);
let mut alive: bool = true; let mut alive: bool = true;
let mut difficulty: i8 = 2; let mut difficulty: i8 = 5;
for i in 0..screen_height { for i in 0..screen_height {
@ -191,7 +199,7 @@ fn main() {
generate_level(current_level + screen_height as u64, difficulty, &mut left_wall, &mut right_wall, screen_width, &mut preference, &mut levels); generate_level(current_level + screen_height as u64, difficulty, &mut left_wall, &mut right_wall, screen_width, &mut preference, &mut levels);
let end_gen = std::time::Instant::now(); let end_gen = std::time::Instant::now();
let output = generate_output(current_level, current_level + screen_height as u64, x_coord, character_icon, &levels, debug_mode); let output = generate_output(current_level, current_level + screen_height as u64, x_coord, character_icon, &levels, debug_mode, boots_mode);
let end_gen_output = std::time::Instant::now(); let end_gen_output = std::time::Instant::now();
if ! debug_mode { // We don't want to clear screen if debug mode is on as it lets us see if ! debug_mode { // We don't want to clear screen if debug mode is on as it lets us see
// old stats and see console warnings from rust and stuff // old stats and see console warnings from rust and stuff
@ -231,13 +239,17 @@ fn main() {
current_level+=1; current_level+=1;
if can_die { if can_die {
alive = check_if_alive(&levels, current_level as usize, x_coord as usize); alive = check_if_alive(&levels, current_level as usize, x_coord as usize, boots_mode);
} }
if alive == false { if alive == false {
break 'game_loop break 'game_loop
} }
} }
println!("GAME OVER"); if ! debug_mode { // We don't want to clear screen if debug mode is on as it lets us see
// old stats and see console warnings from rust and stuff
print!("{}[2J", 27 as char);
}
println!("{}","GAME OVER".red());
println!("You fell {:?}m before going SPLAT",current_level-1); println!("You fell {:?}m before going SPLAT",current_level-1);
println!(" -__"); println!(" -__");
println!(" / \\"); println!(" / \\");