#Tetris point scoring

1 messages · Page 1 of 1 (latest)

rose ginkgo
#

details in post

#

hi
i need some help wioth my project, im coding a tetris game, and right now im trying to get the points to go up for every line you move down while soft dropping(holding the down button) here is the code that correlates to it

            if(keyEvent.Pressed && keyEvent.Keycode == Key.S)
            {
                    MoveBlock(Vector2.Down);
                    addPoint = true;
            }else
            {
                addPoint = false;
            }

this code makes it so that when the user is pressing down, it runs the code to move the blocks down, and sets the addpoint boolean to true, and once they release or press another button, it makes the boolean addPoint false

private void MoveBlock(Vector2 direction)
    {
        if(CanMoveTo(currentBlockPos, direction))
        {
            for(int i = 0; i < currentBlockPos.Length; i++)
            {
                currentBlockPos[i] += direction;
                //points++;
            }
            UpdateBlockPos();
        }else if(direction == Vector2.Down)
        {
            PlaceBlock(currentBlockPos);
        }
    }

this is the move block function
if i put the code in if direction = Vector2 down it adds points even for the normal falling so i need a boolean
but i cant get it to add points one for each line it moves down, only one point each frame that the s button is held down
if you need any code tell me and ill send it to you, please give me ideas

stuck pagoda
#

Is there a need to use a vector for the movement direction? The way Tetris operates, there are only 3 directions a piece can move in (left, down, or right), and rotation systems are all already documented too (https://harddrop.com/wiki/SRS).

rose ginkgo
stuck pagoda
#

Why is points++ inside the for loop?

rose ginkgo
#

i was testing something it didnt work so i commented it out

#

i had it at the begining with if(addpoints == true)
but it adds every frame then

stuck pagoda
#

How are you implementing soft drop speed? You may need to tie that in to the code for score, since each soft drop "tick" is where you want the score to be added. You are calling MoveBlock every frame when the s key is held.

rose ginkgo
#

o

#

i mean right now it just drops fast while your holding the s button

stuck pagoda
#

You may want to implement a set soft drop speed, then. It sounds like your soft drop is currently just running as fast as the framerate will allow.
Could you post the second code block from above exactly as you had it, where it added each frame?

celest light
#

Instead of using an addPoint boolean, what if you define int softDropPoints = 0, increment it for each line the soft drop moves the block down, then have PlaceBlock add softDropPoints to the player's point total?

#

Resetting softDropPoints to 0 with each block's instantiation

#

Then if you have the incrementing of softDropPoints in it's own function, you have the option of expanding on the iteration logic, maybe adding a multiplier to how many softDropPoints get added per line based on the current game speed?

stuck pagoda
rose ginkgo
# stuck pagoda MoveBlock function
    private void MoveBlock(Vector2 direction)
    {
        if(CanMoveTo(currentBlockPos, direction))
        {
            if(addPoint)
            {
                points++;
            }
            for(int i = 0; i < currentBlockPos.Length; i++)
            {
                currentBlockPos[i] += direction;
            }
            UpdateBlockPos();
        }else if(direction == Vector2.Down)
        {
            PlaceBlock(currentBlockPos);
        }
    }
stuck pagoda
#

It seems like holding s should soft drop at 1 line per frame based on the code I see, which would appear extremely fast. Is that true for your game?

rose ginkgo
#

yea

stuck pagoda
#

So if you soft drop at 1 line per frame, shouldn't your points also be going up at 1 per frame?

rose ginkgo
#

maybe?

#

well i guess its not at one per frame

#

beacause linke each tiem the block moves down it goes up like 10-30 points

celest light
#

https://harddrop.com/wiki/Drop

This might help for some background info on how soft vs hard drops work

Hard Drop Tetris Wiki

Drop (also called soft drop) refers to downward motion of each tetromino in Tetris games and other games that use falling pieces.

Drop and slide L.

Block above visible 4x5.

Hard drop I.

stuck pagoda
rose ginkgo
#

cuz it can only move down 20 times before it drops, and it takes like 5-6 seconds to drop down, but it goes up to like 200 points for one block

celest light
#

Does godot by default have any framerate cap?

celest light
rose ginkgo
#

yeah

celest light
#

I'd add a bool parameter to UpdateBlockPos for isSoftDrop, then if that bool is true I would add the points in UpdateBlockPos if the new block position != the previous block position

rose ginkgo
#

wdym

celest light
#

Can you post the contents of UpdateBlockPos?

rose ginkgo
#
    private void UpdateBlockPos()
    {
        for(int i = 0; i < currentBlockPos.Length; i++)
        {
            int row = (int)currentBlockPos[i].Y;
            int column = (int)currentBlockPos[i].X;
            var cell = GetNode<Node2D>($"R{row}/C{column}");
            if(cell  == null) continue;
                Vector2 globalCellPos = cell.ToGlobal(Vector2.Zero);
                Node2D childBlock = Active.GetChild(i) as Node2D;
            if(childBlock == null) continue;
                childBlock.GlobalPosition = globalCellPos;
        }
    }
stuck pagoda
#

It's weird that MoveBlock is apparently being called so often, yet the block would take 5-6 seconds to actually move just 20 times. 1 call of MoveBlock is intended to move an entire piece (all 4 squares) 1 line down, yes?

rose ginkgo
#

yes

#

and the points go up way more then the blocks move

stuck pagoda
#

Either your game is running at an extremely low frame rate, or I think something is going wrong in that function, then. You may want to do some debugging to see how often MoveBlock is being called relative to how many times your piece actually moves.

rose ginkgo
#

uh

#

what does that mean

#

hat does that mean...

stuck pagoda
#

I'm confused as to why your block isn't moving faster, basically. It seems like it should move once per frame

#

The points are going up every frame because you are calling MoveBlock every frame. The question is why it isn't actually moving every frame