📄 np_block.cpp
字号:
#include "NP_core.h"const int dx[2][2] = {{0, 1}, {0, 0}};const int dy[2][2] = {{0, 0}, {0, 1}};NP_block::NP_block() { enable();}NP_block::NP_block(CL_ResourceManager *resources, int _style, NP_unit_face face[2], int _x, int _y) : style(_style), x(_x), y(_y) { enable(); for (int i = 0; i < 2; i++) unit[i] = NP_unit(resources, face[i], x + dx[_style][i], y + dy[_style][i]);}NP_block::~NP_block() {}void NP_block::enable() { enabled = true;}void NP_block::disable() { enabled = false;}void NP_block::rotate(NP_board &b) { const int dx[4] = {-1, 0, 1, 0}; const int dy[4] = {0, -1, 0, 1}; int tx = unit[1].get_x() - unit[0].get_x(); int ty = unit[1].get_y() - unit[0].get_y(); int i; for (i = 0; i < 4; i++) if (dx[i] == tx && dy[i] == ty) break; int j = (i + 1) % 4; unit[1].move_to(b, unit[0].get_x() + dx[j], unit[0].get_y() + dy[j]); /* swap the two units for (int i = 0; i < 2; i++) { int j = (i + 1) % 2; unit[i].move_to(b, x + dx[style][j], y + dy[style][j]); } NP_unit tmp = unit[0]; unit[0] = unit[1]; unit[1] = tmp; */}bool NP_block::can_move(NP_board &b, int dx, int dy) { for (int i = 0; i < 2; i++) if (!unit[i].can_move(b, dx, dy)) return false; return true;}bool NP_block::move(NP_board &b, int dx, int dy) { if (can_move(b, dx, dy)) { x += dx, y += dy; for (int i = 0; i < 2; i++) unit[i].move(b, dx, dy); return true; } return false;}void NP_block::stick_to(NP_board &b) { for (int i = 0; i < 2; i++) unit[i].stick_to(b);}void NP_block::update(NP_board &b) { if (enabled) for (int i = 0; i < 2; i++) unit[i].update(b);}void NP_block::draw(NP_board &b) { if (enabled) { for (int i = 0; i < 2; i++) { if (unit[i].get_x() >= 2) unit[i].draw(b); } }}void NP_block::draw(int x, int y) { unit[0].draw(x, y); unit[1].draw(x + UNIT_HEIGHT, y);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -