update project name

This commit is contained in:
2025-08-15 13:41:21 +02:00
parent 1c5af08585
commit ecde6f4b4a
3 changed files with 37 additions and 29 deletions

View File

@@ -1,5 +1,5 @@
[package]
name = "term_tetris"
name = "term-tetris"
version = "0.1.0"
edition = "2021"

View File

@@ -19,9 +19,7 @@ mod tetromino;
fn main() {
let game_mode = args();
let mut game = Game::new();
let mut lock_timer = Instant::now();
let mut lock_count = 0;
let mut lock_override = false;
let total_time = Instant::now();
terminal::enable_raw_mode().unwrap();
@@ -36,36 +34,45 @@ fn main() {
while expr {
let frame_time = frame_time_for_level(game.score.level());
let frame_dur = Instant::now();
let mut frame_dur = Instant::now();
let mut speed_time = frame_time;
let mut lock_override = false;
game.tetromino.move_tetromino((0, -1), &game.block_grid);
render(&game, &current, &game_mode, &total_time.elapsed());
let mut should_lock = if !game.tetromino.move_tetromino((0, -1), &game.block_grid) {
speed_time = LOCK_DELAY;
true
} else {
game.tetromino.move_tetromino((0, 1), &game.block_grid);
false
};
while speed_time > frame_dur.elapsed() && !lock_override {
if let Some(input) = input(&frame_dur, speed_time) {
handle_action(
&input,
&mut game,
&mut speed_time,
&mut lock_timer,
&mut lock_override,
);
let r = handle_action(&input, &mut game, &mut speed_time, &mut lock_override);
render(&game, &current, &game_mode, &total_time.elapsed());
if lock_count < LOCK_RESET {
lock_timer = Instant::now();
if lock_override {
should_lock = true;
break;
}
if !game.tetromino.move_tetromino((0, -1), &game.block_grid)
&& r
&& lock_count < LOCK_RESET
{
frame_dur = Instant::now();
speed_time = LOCK_DELAY;
lock_count += 1;
} else {
game.tetromino.move_tetromino((0, 1), &game.block_grid);
should_lock = false;
}
}
}
let should_lock = if !game.tetromino.move_tetromino((0, -1), &game.block_grid) {
true
} else {
game.last_rotation = None;
lock_timer = Instant::now();
false
};
if should_lock && (lock_timer.elapsed() > LOCK_DELAY || lock_override) {
if should_lock {
if game.tetromino.pos.1 == 17 {
exit();
}
@@ -89,7 +96,6 @@ fn main() {
game.score.points += current.points;
}
render(&game, &current, &game_mode, &total_time.elapsed());
lock_override = false;
}
}
@@ -411,22 +417,22 @@ fn handle_action(
action: &Action,
game: &mut Game,
speed_time: &mut Duration,
lock_timer: &mut Instant,
lock_override: &mut bool,
) {
) -> bool {
let tetromino = &mut game.tetromino;
let block_grid = &game.block_grid;
match action {
Action::MoveRight => {
tetromino.move_tetromino((1, 0), block_grid);
return tetromino.move_tetromino((1, 0), block_grid);
}
Action::MoveLeft => {
tetromino.move_tetromino((-1, 0), block_grid);
return tetromino.move_tetromino((-1, 0), block_grid);
}
Action::Rotate(r) => {
if let Some(i) = tetromino.rotate(r, block_grid) {
game.last_rotation = Some((r.clone(), i));
return true;
}
}
Action::SoftDrop => {
@@ -443,11 +449,13 @@ fn handle_action(
*lock_override = true;
}
Action::SonicDrop => {
while tetromino.move_tetromino((0, -1), block_grid) {}
*lock_timer = Instant::now();
while tetromino.move_tetromino((0, -1), block_grid) {
*speed_time = LOCK_DELAY;
}
}
Action::Hold => game.hold(),
}
false
}
fn input(now: &Instant, frame_time: Duration) -> Option<Action> {

Binary file not shown.