locked
Why doesn't this work? RRS feed

  • Question

  • I am working on a tetris program but I don't know why when the timer is called the shapes won't move?
    Import:RQG965
    Sunday, February 21, 2010 12:48 AM

Answers

  • Hacker,

    Looking good so far. To get your shapes to move, you need to remove the inverted commas around your SQ1, SQ2, SQ3, SQ4 definitions in each of your Shape checks in your Piece subroutine.

    So, instead of SQ1 = "TLS", SQ2 = "TRS" etc. change them all to SQ1 = TLS, SQ2 = TRS etc.

    Look forward to seeing the finished thing.

    It's worth mentioning too that the 'chaining' programming method you are using (calling one Sub from another) is probably going to give you grief as the code gets more complex.  Think about structuring it differently - search this forum for 'game' or 'coding' etc.  One such is here, and another one here
    • Marked as answer by The Hacker2 Monday, February 22, 2010 7:51 AM
    Sunday, February 21, 2010 1:37 AM

All replies

  • Hacker,

    Looking good so far. To get your shapes to move, you need to remove the inverted commas around your SQ1, SQ2, SQ3, SQ4 definitions in each of your Shape checks in your Piece subroutine.

    So, instead of SQ1 = "TLS", SQ2 = "TRS" etc. change them all to SQ1 = TLS, SQ2 = TRS etc.

    Look forward to seeing the finished thing.

    It's worth mentioning too that the 'chaining' programming method you are using (calling one Sub from another) is probably going to give you grief as the code gets more complex.  Think about structuring it differently - search this forum for 'game' or 'coding' etc.  One such is here, and another one here
    • Marked as answer by The Hacker2 Monday, February 22, 2010 7:51 AM
    Sunday, February 21, 2010 1:37 AM
  • I got that working. Now why is this not working?
    Import:DPT886

    Why isn't it updating the bottom of the grid?
    Monday, February 22, 2010 7:51 AM
  • Hacker,

    2 Points

    1] You are restarting the timer event repeatedly in Piece - may cause problems with conflicting events - not sure this will be a problem, but best to register this only once - I moved it to the Play sub.  May be better to register it once at the start of the program and Timer.Pause and Timer.Resume it as required.

    2] More importantly, you have:

    Bottom[SQ1X] = Bottom[SQ1X] + 20
    etc.

    These should be:

    Bottom[SQ1X] = Bottom[SQ1X] - 20
    etc.

    Since Y is positive down.

    Modified code - import DPT886-0
    Monday, February 22, 2010 7:50 PM
  • Thanks, I figured that out and felt really stupid afterwards! Now I know a few ways I could do it but what would be the best way for doing the rotation of the shapes? I know could use a variable and store what rotation the shape is at at the current time and have it check and then move the shapes accordingly, but, is there an easier way?
    Monday, February 22, 2010 11:37 PM
  • Never feel stupid about asking questions!  That is the only way we learn!
    Tuesday, February 23, 2010 2:42 AM
  • Hacker,

    I think you need some arrays that locate the connected blocks for each shape and each orientation .

    So if the shapes are labelled by i , the orientation by j (1-4) and the connected blocks by k (1-4), then the arrays, say nbrsX[i][j][k] and nbrsY[i][j][k] would need to be set initially to hold the relative position of all blocks in all orientations.

    These would need to be relative to a 'master block' for the shape.

    Consider an L shape (say shape [i])

        X
    XX X

    If the 'master block' is the BOLD one, then:

        X
    XX X

    nbrsX[i][1][1] = -1
    nbrsX[i][1][2] = 0
    nbrsX[i][1][3] = 1
    nbrsX[i][1][4] = 1

    nbrsY[i][1][1] = 0
    nbrsY[i][1][2] = 0
    nbrsY[i][1][3] = 0
    nbrsY[i][1][4] = -1

    X
    X
    XX

    nbrsX[i][2][1] = 0
    nbrsX[i][2][2] = 0
    nbrsX[i][2][3] = 0
    nbrsX[i][2][4] = 1

    nbrsY[i][2][1] = -1
    nbrsY[i][2][2] = 0
    nbrsY[i][2][3] = 1
    nbrsY[i][2][4] = 1

    XX X
    X

    nbrsX[i][3][1] = -1
    nbrsX[i][3][2] = -1
    nbrsX[i][3][3] = 0
    nbrsX[i][3][4] = 1

    nbrsY[i][3][1] = 1
    nbrsY[i][3][2] = 0
    nbrsY[i][3][3] = 0
    nbrsY[i][3][4] = 0

    XX
      X
      X

    nbrsX[i][4][1] = -1
    nbrsX[i][4][2] = 0
    nbrsX[i][4][3] = 0
    nbrsX[i][4][4] = 0

    nbrsY[i][4][1] = -1
    nbrsY[i][4][2] = -1
    nbrsY[i][4][3] = 0
    nbrsY[i][4][4] = -1

    Then if the master block is at (X,Y) and has orientation [j], then each of the 4 neighbour blocks [k] have coordinates (assuming gridding of 20 pixels)

    (X + 20*nbrsX[i][j][k],Y + 20*nbrsY[i][j][k])


    A bit hard to explain what I mean, but you need to store all the geometry combinations initially in arrays relative to a master block for each shape in each orientation.

    Wednesday, February 24, 2010 12:09 AM