My tetris clone colision sisten does not work 100% of the time. Why?

AI_level_4AI_level_4 Posts: 8Member

Hi, I've trying to make a tetris clone, but the colision sistem not always works. It fails in like 1% of the time and i can't understand why.

Some times they go down one more block than what they should. Only one time the piece ignored the the button of the "screen" for on block. The never failled at sideways moviment as far I noticed.

This is the colision function:

 func colision(piece):
    var block = piece.get_children()
    for bloco in blocos:
        var rel_position = block.global_position -screen.global_position
        if rel_position.y > screen_length:
            return true

        if rel_position.x < 0 or rel_position.x > largura_tela:
            return true

        for fallen_piece in screen.get_children():
            if fallen_piece != piece:
                for fallen_blc in fallen_piece.get_children():
                    if  fallen_piece.global_position == block.global_position:
                        return true

The 'piece' is the one currently falling. Every piece is builded with blocks. The pieces are children of the screen.

The function is called every time the piece moves. If it returns true the moviment is applied inverted. The pieces only move "one block" down or sideway at time.

Does any one have a answer for why this is happening?

The 'piece' is the one currently falling. Every piece is builded with blocks. The pieces are children of the screen.

The function is called every time the piece moves. If it returns true the moviment is applied inverted. The pieces only move "one block" down or sideway at time.

Does any one have a answer for why this is may be happening?


Tags :

Answers

  • AI_level_4AI_level_4 Posts: 8Member

    I forgot to mention that the files of the project is on the first post, if it helps. The code use portuguese terms though. Anyway the only script running is the one on the main node of main scene.

  • sent44sent44 Posts: 74Member

    I don't know. Do you move the piece first then check, it check fail (return true) will revert to pervious position?
    And your function check if it is moveable in sideway and down right?
    Your main function detect if it is sideway collision, then it will continue fall, else it will stop and spawn new piece.
    That is my guess why. I download your project and read source code but I give up after I don't know what are those words mean. And when I play test, I can't deprecate the bug. Can you record when it is happen?

  • AI_level_4AI_level_4 Posts: 8Member

    Thanks for the reply!

    Do you move the piece first then check, it check fail (return true) will revert to pervious position?

    Yes!

    And your function check if it is moveable in sideway and down right?

    It check if its in the same position of other block or out of the screen when rotatin, sliding or falling.

    Your main function detect if it is sideway collision, then it will continue fall, else it will stop and spawn new piece.

    Not sure if i understood You here but, I don't thiks this is right. Its basicle what it does that in order:

    if player wants to rotate and player can rotate: rotate
    if player wants to slide and player can slide: slide
    if all blocks of the piece can fall: fall

    Can you record when it is happen?

    Yes! https://youtube.com/watch?v=5nSXaxiJis4
    I shoud have done this before by now. I had a theory of maybe the blocks could be missplacing for some reason, but it does not seens to be the case when i print their position when touching the ground. Also with the recording i notice a more weird behavior: A single block desapairing in a line at the 3:08. I put the times on description of some bugs i notice.

    Another problem with the lines cleanning are that some times they are not cleared, has you can see in the video. The lines deleting thing is separeted of the colision problem, they ocuors at diferent states. But if one block is a pixel off than this block would be invisible for colision detection and if this happens at y axle it would be invible for the line check too. But why would pieces be movied wrongly and not showing when I did the print test? I don't know.

    I can translate the script if you or someone else is willing to see. Maybe a video explaining the code? I'm not confident about my codes been clean enought, iven thoug I'm proud of this one, about the organization at least.

  • sent44sent44 Posts: 74Member

    I think it is fast fall might make be cause of this bug.
    I recommend you to try to start this project again. You might find problem when you rewrite code.

    I also many time found unsolvable bugs, but when I completely rewrote that section of code, the bug was gone. Well sometime I found why those bugs happen, sometime it is still mystery till this day. :s

  • AI_level_4AI_level_4 Posts: 8Member

    Yea, this is the second time that i wrote. Not becouse of bugs but for organization. Now I'm to tired of it and frustated to rewrite again but i will probably do it in a near future. Any way it was quite a learning for me! Thanks!

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file