This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 15k traffic Daily!!!

Tetris Development #5 – The HOLD Piece


On this put up, I’ll discuss in regards to the implementation of the HOLD piece in our Tetris sport.

First, what’s a HOLD piece? In Tetris, there’s a HOLD slot, which is empty at the beginning of the sport, and the participant can press a button to place the at the moment managed piece into the HOLD slot for use later. The sport then continues as if the maintain piece vanished. When the participant thinks it’s time to use the HOLD piece, they will press the identical button once more to swap the HOLD piece with the at the moment managed piece and proceed the sport.

This enables for strategic planning and setup, the place gamers can HOLD a helpful piece for use later within the sport.

“Okay however how will we implement it?”



Logic

I began by including a brand new variable for HOLD piece, and it’s empty at the beginning of the sport.

When the HOLD button (spacebar) is pressed, the sport logic will examine if there exists a bit being held. If there is not, the HOLD piece will clone the present lively piece, and the lively piece can be changed by the following piece in line.

If there may be already a bit being held, then urgent the HOLD button will swap the held piece with the lively piece.



Particulars

There are two essential particulars within the HOLD implementation.
Firstly, when the lively piece is changed by the HOLD piece, the drop indicator might want to change as nicely. With out it, the drop indicator will nonetheless present the place the unique block (now in HOLD) will drop, as an alternative of the newly swapped piece. Due to this fact, additional logic on the drop indicator piece was carried out to right the conduct.

Subsequent, to make sure consistency, I made it in order that when a bit is put into HOLD, its orientation (i.e. rotation) is reverted again to upright. Because of this each time the participant swap a bit out of HOLD, the piece can be in an upright place, as an alternative of no matter place it was when the participant pressed HOLD. Since there are 4 potential orientations, if the participant has to recollect which orientation the HOLD piece was in, it’s a enormous burden particularly if the participant is swapping between completely different HOLD items. Thus, by reverting to all the time being upright, it provides extra consistency to the result when utilizing the HOLD performance.



UI updates

However the HOLD piece will not work if the participant cannot see it!
Thus, the HUD should now have house for the HOLD slot, and the participant ought to have the ability to see what piece is being held proper now. I up to date the UI to unencumber some house on the top-right as a way to present the HOLD slot.

Image description

That’s the finish of the HOLD piece implementation. Personally, I really feel that just like the Subsequent Piece Indicators, the HOLD piece provides one other degree of depth to the sport and extra rewards to fastidiously deliberate gameplay by strategic gamers. This additionally makes the coaching of an AI to play the sport later extra attention-grabbing.

The Article was Inspired from tech community site.
Contact us if this is inspired from your article and we will give you credit for it for serving the community.

This Banner is For Sale !!
Get your ad here for a week in 20$ only and get upto 10k Tech related traffic daily !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Want to Contribute to us or want to have 15k+ Audience read your Article ? Or Just want to make a strong Backlink?