#Tetris point scoring
1 messages · Page 1 of 1 (latest)
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
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).
idk the movement already works and i dont really wanna change it since it works fine right now i just need the scoring to work
Why is points++ inside the for loop?
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
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.
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?
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?
what blockof code?
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);
}
}
wdym?
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?
yea
So if you soft drop at 1 line per frame, shouldn't your points also be going up at 1 per frame?
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
https://harddrop.com/wiki/Drop
This might help for some background info on how soft vs hard drops work
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.
Have this open right now also lol
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
Does godot by default have any framerate cap?
It looks like you are adding points every time MoveBlock sees that the block can move, I think you only want to add points every time UpdateBlockPos actually changes the block position
yeah
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
wdym
Can you post the contents of UpdateBlockPos?
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;
}
}
^
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?
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.