tetris: curpiece is now a Visual, not a Plane #558

pull/587/head
nick black 4 years ago committed by Nick Black
parent a2888f2c75
commit 803296fb80

@ -1,5 +1,5 @@
bool LockPiece(){ // returns true if game has ended by reaching level 16
curpiece_->mergedown(*board_);
curpiece_->get_plane()->mergedown(*board_);
int bdimy, bdimx;
board_->get_dim(&bdimy, &bdimx);
int cleared; // how many contiguous lines were cleared

@ -63,7 +63,7 @@ private:
ncpp::NotCurses& nc_;
uint64_t score_;
std::mutex mtx_; // guards msdelay_
std::unique_ptr<ncpp::Plane> curpiece_;
std::unique_ptr<ncpp::Visual> curpiece_;
std::unique_ptr<ncpp::Plane> board_;
std::unique_ptr<ncpp::Visual> backg_;
ncpp::Plane* stdplane_;
@ -79,7 +79,7 @@ private:
if(!curpiece_){
return false;
}
curpiece_->get_yx(y, x);
curpiece_->get_plane()->get_yx(y, x);
return true;
}

@ -1,11 +1,11 @@
bool MoveDown() { // returns true if the game has ended as a result of this move
int y, x;
if(PrepForMove(&y, &x)){
if(!curpiece_->move(y + 1, x)){
if(!curpiece_->get_plane()->move(y + 1, x)){
throw TetrisNotcursesErr("move()");
}
if(InvalidMove()){
if(!curpiece_->move(y, x)){
if(!curpiece_->get_plane()->move(y, x)){
throw TetrisNotcursesErr("move()");
}
if(y <= board_top_y_ - 1){

@ -2,11 +2,11 @@ void MoveLateral(int direction) { // pass in -1 for left, 1 for right
int shift = 2 * direction;
int y, x;
if(PrepForMove(&y, &x)){
if(!curpiece_->move(y, x + shift)){
if(!curpiece_->get_plane()->move(y, x + shift)){
throw TetrisNotcursesErr("move()");
}
if(InvalidMove()){
if(!curpiece_->move(y, x)){
if(!curpiece_->get_plane()->move(y, x)){
throw TetrisNotcursesErr("move()");
}
}else{

@ -1,6 +1,6 @@
// tidx is an index into tetriminos. yoff and xoff are relative to the
// terminal's origin. returns colored north-facing tetrimino on a plane.
std::unique_ptr<ncpp::Plane> NewPiece() {
std::unique_ptr<ncpp::Visual> NewPiece() {
// "North-facing" tetrimino forms (form in which they are released from the top) are expressed in terms of
// two rows having between 2 and 4 columns. We map each game column to four columns and each game row to two
// rows. Each byte of the texture maps to one 4x4 component block (and wastes 7 bits).
@ -16,7 +16,8 @@ std::unique_ptr<ncpp::Plane> NewPiece() {
int y, x;
stdplane_->get_dim(&y, &x);
const int xoff = x / 2 - BOARD_WIDTH + 2 * (random() % (BOARD_WIDTH / 2));
std::unique_ptr<ncpp::Plane> n = std::make_unique<ncpp::Plane>(2, cols, board_top_y_ - 1, xoff, nullptr);
/* FIXME
std::unique_ptr<ncpp::Visual> n = std::make_unique<ncpp::Visual>(2, cols, board_top_y_ - 1, xoff, nullptr);
if(n){
uint64_t channels = 0;
channels_set_bg_alpha(&channels, CELL_ALPHA_TRANSPARENT);
@ -38,4 +39,6 @@ std::unique_ptr<ncpp::Plane> NewPiece() {
throw TetrisNotcursesErr("render()");
}
return n;
*/
return nullptr;
}

@ -1,19 +1,19 @@
bool InvalidMove() { // a bit wasteful, but piece are tiny
int dy, dx;
curpiece_->get_dim(&dy, &dx);
curpiece_->get_plane()->get_dim(&dy, &dx);
while(dy--){
int x = dx;
while(x--){
ncpp::Cell c, b;
if(curpiece_->get_at(dy, x, &c) < 0){
if(curpiece_->get_plane()->get_at(dy, x, &c) < 0){
throw TetrisNotcursesErr("get_at()");
}
if(c.is_simple()){
continue;
}
curpiece_->release(c);
curpiece_->get_plane()->release(c);
int transy = dy, transx = x; // need game area coordinates via translation
curpiece_->translate(*board_, &transy, &transx);
curpiece_->get_plane()->translate(*board_, &transy, &transx);
if(transy < 0 || transy >= board_->get_dim_y() || transx < 0 || transx >= board_->get_dim_x()){
return true;
}

Loading…
Cancel
Save