terrr 0.1.0

a linux horror game
use ratatui::style::Color;
use rand::Rng;
use std::time::{Duration, Instant};

/// Represents the glitchy title animation
pub struct GlitchyTitle {
    text: String,
    glitch_chars: Vec<char>,
    last_update: Instant,
    glitch_interval: Duration,
    glitch_intensity: f32,
}

impl GlitchyTitle {
    pub fn new(text: &str) -> Self {
        Self {
            text: text.to_string(),
            glitch_chars: vec!['', '', 'ė', 'Ș', '', '', '', 'ē', '',
                             '̶', '̴', '̸', '̵', '̷', '', '҉', '$', '#', '%', '&'],
            last_update: Instant::now(),
            glitch_interval: Duration::from_millis(150),
            glitch_intensity: 0.2,
        }
    }

    /// Updates the title's glitch effect
    pub fn update(&mut self) {
        if self.last_update.elapsed() >= self.glitch_interval {
            self.last_update = Instant::now();
            // Randomize the glitch interval for more organic effect
            let mut rng = rand::thread_rng();
            self.glitch_interval = Duration::from_millis(rng.gen_range(50..200));
        }
    }

    /// Gets the current state of the title with glitch effects applied
    pub fn get_display_text(&self) -> Vec<(String, Option<Color>)> {
        let mut rng = rand::thread_rng();
        let mut result = Vec::new();
        
        for c in self.text.chars() {
            let glitch_chance = rng.gen::<f32>();
            
            if glitch_chance < self.glitch_intensity {
                // Apply a glitch effect
                let effect_type = rng.gen_range(0..4);
                
                match effect_type {
                    0 => {
                        // Replace with a glitch character
                        let glitch_char = self.glitch_chars[rng.gen_range(0..self.glitch_chars.len())];
                        result.push((glitch_char.to_string(), Some(Color::Red)));
                    }
                    1 => {
                        // Shift color
                        result.push((c.to_string(), Some(Color::LightRed)));
                    }
                    2 => {
                        // Duplicate character
                        result.push((c.to_string(), None));
                        result.push((c.to_string(), Some(Color::LightRed)));
                    }
                    _ => {
                        // Normal character but with color shift
                        result.push((c.to_string(), Some(Color::LightRed)));
                    }
                }
            } else {
                // Normal character
                result.push((c.to_string(), None));
            }
        }
        
        result
    }
    
    /// Increase the glitch intensity over time
    pub fn increase_intensity(&mut self, amount: f32) {
        self.glitch_intensity += amount;
        if self.glitch_intensity > 0.5 {
            self.glitch_intensity = 0.5; // Cap at 50% glitch chance
        }
    }
}