From 803296fb80f8f4b717091ab133c4cddced8d3a9f Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 4 May 2020 01:23:02 -0400 Subject: [PATCH] tetris: curpiece is now a Visual, not a Plane #558 --- src/tetris/lock.h | 2 +- src/tetris/main.cpp | 4 ++-- src/tetris/movedown.h | 4 ++-- src/tetris/movelateral.h | 4 ++-- src/tetris/newpiece.h | 7 +++++-- src/tetris/stuck.h | 8 ++++---- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/tetris/lock.h b/src/tetris/lock.h index 97fc3af64..bc1c1041e 100644 --- a/src/tetris/lock.h +++ b/src/tetris/lock.h @@ -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 diff --git a/src/tetris/main.cpp b/src/tetris/main.cpp index 83ef3a672..d834ba14e 100644 --- a/src/tetris/main.cpp +++ b/src/tetris/main.cpp @@ -63,7 +63,7 @@ private: ncpp::NotCurses& nc_; uint64_t score_; std::mutex mtx_; // guards msdelay_ - std::unique_ptr curpiece_; + std::unique_ptr curpiece_; std::unique_ptr board_; std::unique_ptr 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; } diff --git a/src/tetris/movedown.h b/src/tetris/movedown.h index 8a4fcf060..905fa9f24 100644 --- a/src/tetris/movedown.h +++ b/src/tetris/movedown.h @@ -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){ diff --git a/src/tetris/movelateral.h b/src/tetris/movelateral.h index b2fc7e83b..d9a5ea203 100644 --- a/src/tetris/movelateral.h +++ b/src/tetris/movelateral.h @@ -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{ diff --git a/src/tetris/newpiece.h b/src/tetris/newpiece.h index ad1c7a97f..e846072d1 100644 --- a/src/tetris/newpiece.h +++ b/src/tetris/newpiece.h @@ -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 NewPiece() { +std::unique_ptr 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 NewPiece() { int y, x; stdplane_->get_dim(&y, &x); const int xoff = x / 2 - BOARD_WIDTH + 2 * (random() % (BOARD_WIDTH / 2)); - std::unique_ptr n = std::make_unique(2, cols, board_top_y_ - 1, xoff, nullptr); + /* FIXME + std::unique_ptr n = std::make_unique(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 NewPiece() { throw TetrisNotcursesErr("render()"); } return n; + */ + return nullptr; } diff --git a/src/tetris/stuck.h b/src/tetris/stuck.h index e11d92eac..79ceda653 100644 --- a/src/tetris/stuck.h +++ b/src/tetris/stuck.h @@ -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; }