Tetris: always move in chunks of two columns #421

This commit is contained in:
nick black 2020-03-25 22:09:51 -04:00
parent 642741f2c9
commit b7c9746cf0
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
2 changed files with 17 additions and 12 deletions

View File

@ -20,16 +20,19 @@ void MoveLeft() {
}
if(lx < curpiece_->get_dim_x()){ // otherwise, nothing on this row
ncpp::Cell b;
int cmpy = ly, cmpx = lx - 1;
curpiece_->translate(*board_, &cmpy, &cmpx);
if(board_->get_at(cmpy, cmpx, &b)){
if(b.get().gcluster && b.get().gcluster != ' '){
return; // move is blocked
for(int xdelt = 1 ; xdelt < 3 ; ++xdelt){
int cmpy = ly, cmpx = lx - xdelt;
curpiece_->translate(*board_, &cmpy, &cmpx);
if(board_->get_at(cmpy, cmpx, &b)){
// FIXME deal with e.g. lower half sliding under upper half
if(b.get().gcluster && b.get().gcluster != ' '){
return; // move is blocked
}
}
}
}
}
--x;
x -= 2;
if(!curpiece_->move(y, x) || !nc_.render()){ // FIXME needs y?
throw TetrisNotcursesErr("move() or render()");
}

View File

@ -20,16 +20,18 @@ void MoveRight() {
}
if(lx >= 0){ // otherwise, nothing on this row
ncpp::Cell b;
int cmpy = ly, cmpx = lx + 1;
curpiece_->translate(*board_, &cmpy, &cmpx);
if(board_->get_at(cmpy, cmpx, &b)){
if(b.get().gcluster && b.get().gcluster != ' '){
return; // move is blocked
for(int xdelt = 1 ; xdelt < 3 ; ++xdelt){
int cmpy = ly, cmpx = lx + xdelt;
curpiece_->translate(*board_, &cmpy, &cmpx);
if(board_->get_at(cmpy, cmpx, &b)){
if(b.get().gcluster && b.get().gcluster != ' '){
return; // move is blocked
}
}
}
}
}
++x;
x += 2;
if(!curpiece_->move(y, x) || !nc_.render()){ // FIXME needs y?
throw TetrisNotcursesErr("move() or render()");
}