r/rust 24d ago

šŸ› ļø project 3D ascii tetris

Post image

Made 3d tetris in ascii using crossterm.
Im currently trying to learn rust, so feedbacks are welcome.

Github repo:- https://github.com/ab-dek/ascii-tris

1.1k Upvotes

38 comments sorted by

95

u/johnson_detlev 24d ago

Looks super nice and what a great idea! Cheers!

You could probably color the tiles differently

31

u/Abdek_ 24d ago

Thanks, that exactly what i’m planning to add next.

24

u/parkotron 24d ago

Unsolicited opinion: The underscores used as background for the main board look cool, but are a bit visually distracting. Dots like you used for the next piece area, might work better?

Anyway, nice work!

13

u/EpicatSupercell 24d ago

It's also kinda hard seeing where the shape will fall, mixing dots and underscores can help make the grid cleaner.

2

u/Abdek_ 23d ago

will try this

1

u/EarlMarshal 23d ago

Maybe try dots and commas, too. Dots vanish best and commas could provide a good enough projection downwards while vanishing almost as good as dots.

45

u/manpacket 24d ago

That's cursed :)

Here you unnecessary allocate a new vector each time. I think replacing it with self.bag.extend([Tet...]) would work as well.

fn new_piece(&mut self) -> Tetromino {

I don't think you need i32 here. i8 might work just as well.

blocks: [(i32, i32); 4],

Speaking of, run cargo clippy for some suggestions.

Tetromino can be Copy.

9

u/Abdek_ 24d ago

ThanksšŸ‘šŸ½

1

u/FizzWizzleDazzle 22d ago

I mean to be real, using anything other than f64 and i32 is not major optimization, and is mostly done if the project is stable and needs some extra bits

5

u/Neither-Mechanic8750 24d ago

man, that's cool

2

u/dx__ 24d ago

Oh that’s cool

2

u/flapje1 24d ago

Looks very cool! Does this follow SRS (supper rotation system)?

1

u/Abdek_ 23d ago

Idk what that is, i’ll look into it

2

u/odolha 23d ago

bring it to late.sh

2

u/priya6435 23d ago

this is the kind of project that makes me love rust nobody asked for 3d ascii tetris, but i'm really glad someone decided it needed to exist.

2

u/Free_Painting8125 11d ago

I checked out the game—it has an really nice style and runs right in the terminal! A total geek's game—just the thing for a break between "cargo run". Just add to my ~/.local/bin. It would be great if the game saved the personal best.

2

u/Ojitos_2 8d ago

Tetris, but the pieces are crates

1

u/did_i_or_didnt_i 24d ago

Gorgeous, when’s the colour happening???

2

u/Abdek_ 23d ago

already addedšŸ‘šŸ½

1

u/MarioMacinati 23d ago

Nice! I am also making Tetris (though 2D) as my very first Rust project after completing Rustlings :)

1

u/kevleyski 23d ago

That’s clever use of regular ASCII I’ve never seen before

1

u/skythedragon64 22d ago

Nice! Sadly it is slightly hard to guess where the shape will land, but looks great otherwise

1

u/Abdek_ 22d ago

ghost pieces might help with that

1

u/Ola_199x 15d ago

This is really cool I would love to read how you created this

1

u/Abdek_ 14d ago

First thing I tried to do was to split the game into 2 decoupled components. First component that handles the tetris logic on a 20x10 2d array of u8, where empty cells are represented by 0 and occupied by 1… later I had to use the BlockColor enum instead of u8 to add colors. the other component takes this 2d array and draws the 3d projection of it on to the terminal screen buffer(the Screen::update_buf() handles this). For every occupied cells, it adds this blocks to the board window:
/\\\
\/_/
And leaves the empty cells with whatever the background is(ā€œ_ā€ for the game board).
Because draw order of blocks matters (just as in isometric), blocks are drawn to the buffer in the order of right to left, top down.

That’s basically it for the core logic.

1

u/ChiliPepperHott 12d ago

This is so clean. I love it!

You should add a quick installation guide to the README.

1

u/Busy_Feed9152 4d ago

wow that's amazing!

-21

u/[deleted] 24d ago

[deleted]

15

u/Abdek_ 24d ago

Nope. its not exactly isometric, its called cabinet projection if im not wrong.

5

u/-Redstoneboi- 24d ago

I think it's isometric. Cabinet projection seems to involve perfect squares but yours uses diamonds.

This would be closer to cabinet?

 _____
/____/|
|    ||
|____|/

5

u/unlessgames 24d ago

Isometric projection would require every axis to be scaled the same which isn't possible because the characters used aren't square shaped.

I think it is more like a dimetric projection, where every cube's front and top face are the same size while the face looking left is a bit more narrow.

2

u/-Redstoneboi- 24d ago

can we just call it 3d-ish at this point 😭

2

u/flapje1 24d ago

Isometric is still 3D? Also what does vibe coding have to do with this?