MinecraftU / 2021-computer-adventures

Repository for our 2021 Computer Adventures Ruby project!
0 stars 0 forks source link

Collision detection for rotation #35

Closed jamespeilunli closed 3 years ago

jamespeilunli commented 3 years ago

will close #34

Currently works-ish, but the tick right after when rotation happens is broken; only part of the tetromino is shown.

jamespeilunli commented 3 years ago

Found the bug! I didn't replace all occurrences of piece_data, the instance variable, with _piece_data, the local variable, inside put_tetromino. Diff: Before:

  def put_tetromino(_gameboard=gameboard, _pos=pos, _width=width, _height=height, _piece_data=piece_data, clear=false)
    [stuff]
    (0..._width).each do |i|
      (0..._height).each do |j|
        [stuff]
            new_gameboard[_pos[0]+j, _pos[1]+i] = piece_data[j, i] # this is where the change is
  [stuff]
  end

After:

  def put_tetromino(_gameboard=gameboard, _pos=pos, _width=width, _height=height, _piece_data=piece_data, clear=false)
    [stuff]
    (0..._width).each do |i|
      (0..._height).each do |j|
        [stuff]
            new_gameboard[_pos[0]+j, _pos[1]+i] = _piece_data[j, i] # this is where the change is
  [stuff]
  end
jamespeilunli commented 3 years ago

I did a final test run, and another bug has occurred. When I rotate a lot, the tetromino becomes dead (ie. it floats in mid air). I will commit my changes, but keep it as a draft

jamespeilunli commented 3 years ago

Never mind, it doesn't just happen when I rotate a lot, it happens when I just press the up arrow once even.

jamespeilunli commented 3 years ago

This might be because of the actual position of the tetromino changing when the pos variable isn't.