diff --git a/falling/Cargo.toml b/falling/Cargo.toml index d2925dc..fef3abb 100644 --- a/falling/Cargo.toml +++ b/falling/Cargo.toml @@ -7,3 +7,4 @@ edition = "2024" rand = "0.8.5" console = "0.15.10" termion = "4.0.3" +colored = "2.2.0" diff --git a/falling/src/main.rs b/falling/src/main.rs index e928b76..5c2d086 100644 --- a/falling/src/main.rs +++ b/falling/src/main.rs @@ -1,12 +1,13 @@ use rand::Rng; // Allows you to generate random numbers use console::Term; // Allows reading key bind input 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 // 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 // -2 is a slanted wall "/" -fn generate_output(starting_level: u64, ending_level: u64, character_x_coord: u16, character_icon: char, levels: &Vec>, debug_mode: bool) -> String { +fn generate_output(starting_level: u64, ending_level: u64, character_x_coord: u16, character_icon: char, levels: &Vec>, debug_mode: bool, boots_mode: bool) -> String { let mut output: String = "".to_string(); if debug_mode { 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 if i == starting_level && j == character_x_coord as usize { 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 { - -3 => output+="|", // Specific case for -3 - 0 => output+="■", // Specific case for 0 - -1 => output+="\\", // Specific case for -1 - -2 => output+="/", // Specific case for -2 + -3 => output.push_str(&"|".to_string()), // Specific case for -3 + 0 => output.push_str(&"|".on_truecolor(255,255,255).strikethrough().to_string()), // Specific case for 0 + -1 => output.push_str(&"\\".to_string()), // Specific case for -1 + -2 => output.push_str(&"/".to_string()), // Specific case for -2 _ => output+=" " // Default, no print for other cases } } @@ -132,8 +137,8 @@ fn debug_mode_modify_variables(current_level: &mut u64) -> u8 { return 1; } -fn check_if_alive(levels: &Vec>, level: usize, x_coord: usize) -> bool { - if levels[level][x_coord] <= 0 { +fn check_if_alive(levels: &Vec>, level: usize, x_coord: usize, boots_mode: bool) -> bool { + if levels[level][x_coord] <= 0 || levels[level+2][x_coord] <= 0 { return false; } else { @@ -158,6 +163,9 @@ fn main() { let debug_mode = false; // Enable or disable debugging mode, it will print some useful stats and // let you modify stats midgame with e 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::new(); // Define variables for level @@ -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 preference: f32 = rand::thread_rng().gen_range(-2.0..3.0); let mut alive: bool = true; - let mut difficulty: i8 = 2; + let mut difficulty: i8 = 5; 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); 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(); 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 @@ -231,22 +239,26 @@ fn main() { current_level+=1; 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 { 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!(" -__"); println!(" / \\"); println!(" | -___"); - println!(" | / ________________________"); - println!(" | / | |"); - println!(" ‾ |‾ / _ | Where is the princess? |"); - println!(" / | \\ / | \\ |________________________|"); - println!(" / ‾‾‾‾‾‾‾ \\ / /"); + println!(" | / ________________________"); + println!(" | / | |"); + println!(" ‾ |‾ / _ | Where is the princess? |"); + println!(" / | \\ / | \\ |________________________|"); + println!(" / ‾‾‾‾‾‾‾ \\ / /"); println!(" __ / / \\• •/ _|"); println!(" / \\ _/‾|‾\\ / |"); println!("_ / / \\ / / |");