add game speed

This commit is contained in:
mii8080
2021-10-02 02:01:13 +00:00
committed by GitHub
parent 53d133260f
commit e4e6bc9e24
3 changed files with 11 additions and 2 deletions

View File

@ -16,6 +16,7 @@ pub struct GameData {
pub show_ghost: bool, pub show_ghost: bool,
pub hold_mino: Option<Mino>, pub hold_mino: Option<Mino>,
pub score: i64, pub score: i64,
pub game_speed: f32,
} }
impl GameData { impl GameData {
@ -94,6 +95,7 @@ impl GameData {
show_ghost, show_ghost,
hold_mino: None, hold_mino: None,
score: 0, score: 0,
game_speed: 0.5,
} }
} }
} }

View File

@ -147,7 +147,12 @@ fn main() {
if *exit_flag_rc.lock().unwrap() { if *exit_flag_rc.lock().unwrap() {
break; break;
} }
thread::sleep(Duration::from_secs_f32(0.5)); let mut game_speed = 0.5f32;
{
let rustris_rc = rustris_rc.lock().unwrap();
game_speed = rustris_rc.game_data.game_speed;
}
thread::sleep(Duration::from_secs_f32(game_speed));
{ {
let mut rustris_rc = rustris_rc.lock().unwrap(); let mut rustris_rc = rustris_rc.lock().unwrap();
if !rustris_rc.move_mino(1, 0) { if !rustris_rc.move_mino(1, 0) {
@ -169,8 +174,9 @@ fn main() {
} }
} }
{ {
let mut rustris_rc = rustris_rc.lock().unwrap();
let mut stdout = stdout_rc.lock().unwrap(); let mut stdout = stdout_rc.lock().unwrap();
let buf = rustris_rc.lock().unwrap().show(); let buf = rustris_rc.show();
execute!(stdout, Print(buf)).unwrap() execute!(stdout, Print(buf)).unwrap()
} }
} }

View File

@ -43,6 +43,7 @@ impl Rustris {
} }
self.game_data.score += clear_lines * 100; self.game_data.score += clear_lines * 100;
self.game_data.game_speed += 0.01 * clear_lines as f32;
} }
pub fn get_next_mino(&mut self) -> Mino { pub fn get_next_mino(&mut self) -> Mino {