From 728f2a3081e0d65e7cda83aa9208d41a9001c67a Mon Sep 17 00:00:00 2001 From: Azalea Gui Date: Wed, 8 Mar 2023 12:06:30 -0500 Subject: [PATCH] [+] Draw title --- tngame-rs/src/main.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tngame-rs/src/main.rs b/tngame-rs/src/main.rs index 0e3f151..8ecdf15 100644 --- a/tngame-rs/src/main.rs +++ b/tngame-rs/src/main.rs @@ -93,6 +93,7 @@ struct Consts { asc_cat: AsciiArt, asc_tree: AsciiArt, asc_house: AsciiArt, + asc_title: AsciiArt, } struct Mutes { @@ -142,10 +143,20 @@ impl Consts { | ,--, ,--, | ,| ,%| '--'._.'--' |,o%o .*%|_,%%_| |_%%,_|#%%%*"#, "Modified from hjw from ascii.co.uk/art/house"); + let asc_title = AsciiArt::new( + r#" + . * + _.__. _.| _ _. ' __ + (_] /_(_]|(/,(_] _) + . + __._ _ . , . |_ _ ._ _ _ +_) [ )(_) \/\/ \_| [ )(_)[ | )(/, + ._| "#, "Generated by patorjk.com/software/taag"); Self { asc_cat, asc_tree, asc_house, + asc_title, } } } @@ -303,6 +314,10 @@ fn draw_ascii_frame(mt: &mut Mutes, cn: &Consts) { mt.print_ascii(&cn.asc_house, (mt.w + cn.asc_house.w) / 2, mt.h - cn.asc_house.h, "\x1b[38;2;251;194;110m"); + // Draw title at the center of the screen + mt.print_ascii(&cn.asc_title, (mt.w - cn.asc_title.w) / 2, (mt.h - cn.asc_title.h) / 2, + "\x1b[38;2;255;231;151m"); + // Draw chat bubble let bubble = gen_bubble_ascii("I wish I could\nlive on that tree."); mt.print_ascii(&bubble, mt.x + 5, mt.h - cn.asc_cat.h - bubble.h, "\x1b[38;2;255;231;151m"); @@ -321,23 +336,20 @@ fn start_loop(mt: &mut Mutes, cn: &Consts) { // Calculate the delta time let dt = (now - mt.last_update).as_secs_f32(); mt.last_update = now; + let start = Instant::now(); // Update the snow mt.update_snow(dt); draw_ascii_frame(mt, cn); // Draw the buffer, time it, and print it - let start = Instant::now(); let txt = mt.draw_buf().unwrap(); let end = Instant::now(); + let draw_time = (end - start).as_secs_f32(); print!("\rDraw time: {:.2}ms", draw_time * 1000.0); print!("{}", txt); - - // Set cursor to the bottom of the screen - print!("\x1b[9999;9999H"); - // Sleep for 1/20th of a second thread::sleep(Duration::from_millis(1000 / 20)); }