Sign in to follow this  

Unity The Quest for Tetris... Part 2

This topic is 3824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello all, Continuing from part 1, I have even more problems with my code. (Ok, so only one right now, but I'm pretty sure that it's messing everything else up) PROBLEM 3: My line-removing code doesn't work correctly. It funks out and makes weird patterns. So I'm placing the brick and then it cleared all the lines on top. Then I placed it again and it made weird lines which went away when my brick hit it. Many thanks in advance for the help. adam_o UPDATED CODE EDIT 1: Updated code, updated Problem 3. [Edited by - adam_o on June 9, 2007 9:02:31 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by Ravuya
Sounds like an off-by-one error. Remember that C++ arrays start at 0 and go to n-1.


I don't think it's off-by-one, because that kicks up the debugger... I had that happen between Problem 2 and Problem 3, but I was able to get the help on that one... nice try...

Share this post


Link to post
Share on other sites
Quote:
Original post by adam_o
Quote:
Original post by Ravuya
Sounds like an off-by-one error. Remember that C++ arrays start at 0 and go to n-1.


I don't think it's off-by-one, because that kicks up the debugger... I had that happen between Problem 2 and Problem 3, but I was able to get the help on that one... nice try...


Not quite. Off-by-one errors are simply miscalculations of location by one, because you forgot to compensate for a starting point or such. First, this is not guaranteed to cause an error, if you overrun an array, so it may or may not crash/invoke debugging. This is not something you can rely on. Second, the off-by-one error may not even be causing you to overrun the array, which would not even generate a potential for an overrun, so a crash/debug wouldn't even happen. It is merely a logic off-by-one.

If you're code is removing a line above the one you want to remove, you probably do, in fact, have an off-by-one error. Check you're code for calculating which row to remove. In a C++ array, the second item is index 1.

Share this post


Link to post
Share on other sites
I looked at your code and I'm not sure where the problem is, but I wanted to say 3 things:

1) You should create helper functions that operate on a whole row (check if it's full, clear it, ...). This will make functions like check_clear_row() much cleaner (and less error-prone!).

2) In the loop, why is the first index of the array always 0 on the right?

3) Why did you choose to have the the array as -
arr_tetris_screen[Width][Height]? Arrays are row major so switching between the width and the height will make the code more intuitive.

These are just quick suggestions, sorry if I misunderstood your code (regarding 2 and 3).

Share this post


Link to post
Share on other sites
Quote:
Original post by Daishim
Not quite. Off-by-one errors are simply miscalculations of location by one, because you forgot to compensate for a starting point or such. First, this is not guaranteed to cause an error, if you overrun an array, so it may or may not crash/invoke debugging. This is not something you can rely on. Second, the off-by-one error may not even be causing you to overrun the array, which would not even generate a potential for an overrun, so a crash/debug wouldn't even happen. It is merely a logic off-by-one.

If you're code is removing a line above the one you want to remove, you probably do, in fact, have an off-by-one error. Check you're code for calculating which row to remove. In a C++ array, the second item is index 1.

I understand this. It doesn't just remove the line above though, it removes every line.
Quote:
Original post by Gage64
I looked at your code and I'm not sure where the problem is, but I wanted to say 3 things:

1) You should create helper functions that operate on a whole row (check if it's full, clear it, ...). This will make functions like check_clear_row() much cleaner (and less error-prone!).

That sounds good. I'll add that to the code.
Quote:

2) In the loop, why is the first index of the array always 0 on the right?

The first one of the set is always 0, because that's the first one I decided to remove. I didn't really decide to do it in any particular order, just that it's easier if I just do it from low to high to remember. I didn't entirely understand the question, so that's what I hope you're asking.
Quote:

3) Why did you choose to have the the array as -
arr_tetris_screen[Width][Height]? Arrays are row major so switching between the width and the height will make the code more intuitive.

I didn't know! Interesting... I guess width by height is just easier for me, because that way it goes along with the (x,y) coordinate system. It's just the way I tought myself, I guess.

Share this post


Link to post
Share on other sites
I'm not sure if this will work, but try it anyways.

void check_clear_row()
{
int row;
// Scan through all the rows
for(row = 0; row < SCREENH - 1; row++)
{
int i;
BOOL isFull = TRUE;
// Does this row need to be cleared?
for(i = 0; i < 8; i++)
{
if(arr_tetris_screen[i][row] == NO_TILE) isFull = FALSE;
}

// Clear row
if(isFull)
{
int currow;
// Scan through all rows above this one, starting from this one.
for(currow = row; currow > 0; currow--)
{
// Replace this row by the one right above it
for(i = 0; i < 8; i++)
{
arr_tetris_screen[i][currow] = arr_tetris_screen[i][currow - 1];
}
}
}
}

translate();
}

Share this post


Link to post
Share on other sites
Quote:
Original post by AcePilot
I'm not sure if this will work, but try it anyways.
*** Source Snippet Removed ***


It didn't work, thanks for trying. I located the spot in the code where the code whas wrong- and it was an off by one code error. WHOOPS! LOL New code attached, looking for new problems.

Share this post


Link to post
Share on other sites
After a much needed break from my project, I have come back afresh, ready to try and re-tackle this problem. I have noticed that if I drop the brick that is above the layer(s) being cleared on the very left, then it clears it differently than the others... hopefully you will understand what I mean by the pictures... I was thinking of doing something where I create a new array for storing all of the values except for those of lines that need to be cleared, then moving the lines down after the fact. Does that sound like it would work?
left before, left after, left after-after
not left before, not left after

Share this post


Link to post
Share on other sites

This topic is 3824 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      628728
    • Total Posts
      2984418
  • Similar Content

    • By INTwindwolf
      THE PROJECT

      INT is a 3D Sci-fi RPG with a strong emphasis on story, role playing, and innovative RPG features such as randomized companions. The focus is on the journey through a war-torn world with fast-paced combat against hordes of enemies. The player must accomplish quests like a traditional RPG, complete objectives, and meet lively crew members who will aid in the player's survival. Throughout the game you can side and complete missions through criminal cartels, and the two major combatants, the UCE and ACP, of the Interstellar Civil War.
      Please note that all of our current positions are remote work. You will not be required to travel.
      Talent Needed
       
      Unity Engine Programmer
      Website Administrator
      3D Animator
      We have made great strides in the year 2017! INT has received a comprehensive face-lift compared to the start of the year. We look forward to a productive, fruitful year 2018!
      Revenue-Share
      This is the perfect opportunity to get into the game development industry. Being an Indie team we do not have the creative restrictions often imposed by publishers or other third parties. We are extremely conscientious of our work and continuously uphold a high level of quality throughout our project.
      We are unable to offer wages or per-item payments at this time. However revenue-sharing from crowd-funding is offered to team members who contribute 15-20 hours per week to company projects, as well as maintain constant communication and adhere to deadlines. Currently the crowd-funding campaign is scheduled for the year 2018. Your understanding is dearly appreciated.
       
      Thank you for your time! We look forward to hearing from you!
       
      John Shen
      HR Lead
      Starboard Games LLC
    • By Apollo Cabrera
      Energy particles being harnessed by collection multi-hedron energy matrix. Whuuuttt?
      Love it :)
    • By AndySv
        Total Music Collection (http://u3d.as/Pxo)   THE COLLECTION CONTAINS:   Mega Game Music Collection   Universal Music Collection   Huge library of high quality music for any project! All at an incredibly low price!   - 2,5GB of high quality audio - 100+ different music tracks - Loop and short versions   Action, fantasy, casual, horror, puzzle, epic, dramatic, romantic, positive, inspiring, motivational and more!
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064

      View full story
    • By Dafu
      FES Retro Game Framework is now available on the Unity Asset Store for your kind consideration!
      FES was born when I set out to start a retro pixel game project. I was looking around for an engine to try next. I tried a number of things, from GameMaker, to Fantasy Consoles, to MonoGame and Godot and then ended up back at Unity. Unity is just unbeatable in it's cross-platform support, and ease of deployment, but it sure as heck gets in the way of proper retro pixel games!
      So I poured over the Unity pipeline and found the lowest levels I could tie into and bring up a new retro game engine inside of Unity, but with a completely different source-code-only, classic game-loop retro blitting and bleeping API. Months of polishing and tweaking later I ended up with FES.
      Some FES features:
      Pixel perfect rendering RGB and Indexed color mode, with palette swapping support Primitive shape rendering, lines, rectangles, ellipses, pixels Multi-layered tilemaps with TMX file support Offscreen rendering Text rendering, with text alignment, overflow settings, and custom pixel font support Clipping Sound and Music APIs Simplified Input handling Wide pixel support (think Atari 2600) Post processing and transition effects, such as scanlines, screen wipes, screen shake, fade, pixelate and more Deploy to all Unity supported platforms I've put in lots of hours into a very detail documentation, you can flip through it here to get an better glimpse at the features and general overview: http://www.pixeltrollgames.com/fes/docs/index.html
      FES is carefully designed and well optimized (see live stress test demo below). Internally it uses batching, it chunks tilemaps, is careful about memory allocations, and tries to be smart about any heavy operations.
      Please have a quick look at the screenshots and live demos below and let me know what you think! I'd love to hear some opinions, feedback and questions!
      I hope I've tickled your retro feels!



      More images at: https://imgur.com/a/LFMAc
      Live demo feature reel: https://simmer.io/@Dafu/fes
      Live blitting stress test: https://simmer.io/@Dafu/fes-drawstress
      Unity Asset Store: https://www.assetstore.unity3d.com/#!/content/102064
  • Popular Now