Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help in coding Tetris!
New Posts  All Forums:Forum Nav:

Help in coding Tetris! - Page 2

post #11 of 13
Thread Starter 
how would you detect if theres a piece below it?
how would you delete a row after a tetris?

thats all the problems i have right now.
segfault
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i5-750 @ 4Ghz Gigabyte P55A-UD4P MSI GTX 770 Kingston HyperX 2x4GB 1600MHz CL9 
Hard DriveOptical DriveCoolingOS
WD Caviar Black 500GB LG 24x Corsair H50 Windows 7 Ultimate x64 
MonitorKeyboardPowerCase
Samsung SyncMaster P2270 Steelseries 6Gv2 Corsair TX750 Thermaltake V9 Black Edition 
MouseMouse Pad
Razer Deathadder 2013 Edition Steelseries QcK 
  hide details  
Reply
segfault
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i5-750 @ 4Ghz Gigabyte P55A-UD4P MSI GTX 770 Kingston HyperX 2x4GB 1600MHz CL9 
Hard DriveOptical DriveCoolingOS
WD Caviar Black 500GB LG 24x Corsair H50 Windows 7 Ultimate x64 
MonitorKeyboardPowerCase
Samsung SyncMaster P2270 Steelseries 6Gv2 Corsair TX750 Thermaltake V9 Black Edition 
MouseMouse Pad
Razer Deathadder 2013 Edition Steelseries QcK 
  hide details  
Reply
post #12 of 13
the simplest way to delete a row if you are using a boolean array to represent the board is to move all the values above that line down by a line. hope that makes sense.

to detect if there is a piece below it, you simply check for every item in your piece array if it's not 0 (let's say 0 represents empty) and then you check if when you place that piece in the board if that item is colliding with a non-empty value. If it collides, then there is a piece below it, if it's empty, then there is no piece. You have to check for each item in your piece array (i'm supposing you're using a 2D array to define your piece; i.e. int piece[4][4]

I did a Tetris game when I was learning C++ and here is how I deleted a row back then:

Code:
void CBoard::removeLine( int lineIndex )
{
  for( int y = lineIndex-1; y >= 0; y-- )
  {
    for( int x = 0; x < getWidth(); x++ )
    {
      setCell( y+1, x, getCell( y, x ) );
    }
  }
}

Edited by mrwalker - 3/28/11 at 12:00pm
post #13 of 13
Thread Starter 
Quote:
Originally Posted by mrwalker View Post
the simplest way to delete a row if you are using a boolean array to represent the board is to move all the values above that line down by a line. hope that makes sense.

to detect if there is a piece below it, you simply check for every item in your piece array if it's not 0 (let's say 0 represents empty) and then you check if when you place that piece in the board if that item is colliding with a non-empty value. If it collides, then there is a piece below it, if it's empty, then there is no piece. You have to check for each item in your piece array (i'm supposing you're using a 2D array to define your piece; i.e. int piece[4][4]

I did a Tetris game when I was learning C++ and here is how I deleted a row back then:

Code:
void CBoard::removeLine( int lineIndex )
{
  for( int y = lineIndex-1; y >= 0; y-- )
  {
    for( int x = 0; x < getWidth(); x++ )
    {
      setCell( y+1, x, getCell( y, x ) );
    }
  }
}
i solved everything yesterday. now im trying to add some additional features.
thanks anyways.
segfault
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i5-750 @ 4Ghz Gigabyte P55A-UD4P MSI GTX 770 Kingston HyperX 2x4GB 1600MHz CL9 
Hard DriveOptical DriveCoolingOS
WD Caviar Black 500GB LG 24x Corsair H50 Windows 7 Ultimate x64 
MonitorKeyboardPowerCase
Samsung SyncMaster P2270 Steelseries 6Gv2 Corsair TX750 Thermaltake V9 Black Edition 
MouseMouse Pad
Razer Deathadder 2013 Edition Steelseries QcK 
  hide details  
Reply
segfault
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i5-750 @ 4Ghz Gigabyte P55A-UD4P MSI GTX 770 Kingston HyperX 2x4GB 1600MHz CL9 
Hard DriveOptical DriveCoolingOS
WD Caviar Black 500GB LG 24x Corsair H50 Windows 7 Ultimate x64 
MonitorKeyboardPowerCase
Samsung SyncMaster P2270 Steelseries 6Gv2 Corsair TX750 Thermaltake V9 Black Edition 
MouseMouse Pad
Razer Deathadder 2013 Edition Steelseries QcK 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Help in coding Tetris!