⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 np_unit.cpp

📁 需要clanlib 库 这个改进版的 在linux 很好玩 但是一定要有clanlib
💻 CPP
字号:
#include "NP_core.h"NP_unit::NP_unit() {    face = blank;    state = normal;}NP_unit::NP_unit(CL_ResourceManager *resources, NP_unit_face _face, int _x, int _y) : face(_face), x(_x), y(_y) {    sprite_normal = CL_Sprite("Game/Graphics/" + NP_unit_face_string[face] + "/normal", resources);    sprite_dying = CL_Sprite("Game/Graphics/" + NP_unit_face_string[face] + "/dying", resources);    sample_dying = CL_SoundBuffer("Game/Sound/" + NP_unit_face_string[face], resources);    set_state(normal);}NP_unit::~NP_unit() {}NP_unit_face NP_unit::get_face() {    return face;}NP_unit_state NP_unit::get_state() {    return state;}void NP_unit::set_state(NP_unit_state _state) {    state = _state;    if (state == normal)        sprite.set_image_data(sprite_normal);    else if (state == dying) {        sprite.set_image_data(sprite_dying);        sample_dying.play();    }}void NP_unit::update(NP_board &b) {    int DELTA_X = 10;    sprite.update();    if (state == dying && sprite.is_finished()) {        set_state(dead);        face = blank;    }    if (state == dropping) {        real_x += DELTA_X;        if (real_x >= dest_x) {            real_x = dest_x;            set_state(normal);        }    }    else {        real_x = b.base_x + x * UNIT_HEIGHT;        real_y = b.base_y + y * UNIT_WIDTH;     }}void NP_unit::draw(NP_board &b) {    if (state == dying)        sprite.draw(real_y - 3, real_x - 3);    else        sprite.draw(real_y, real_x);}void NP_unit::draw(int x, int y) {    if (state == dying)        sprite.draw(y - 3, x - 3);    else        sprite.draw(y, x);}int NP_unit::get_x() {    return x;}int NP_unit::get_y() {    return y;}bool NP_unit::can_move(NP_board &b, int dx, int dy) {    int _x = x + dx, _y = y + dy;    if (_x >= 0 && _x < BOARD_HEIGHT && _y >= 0 && _y < BOARD_WIDTH && b.board[_x][_y] == blank)        return true;    return false;}bool NP_unit::move(NP_board &b, int dx, int dy) {    if (can_move(b, dx, dy)) {        x += dx, y += dy;        return true;    }    return false;}bool NP_unit::move_to(NP_board &b, int _x, int _y) {    int dx = _x - x, dy = _y - y;    if (can_move(b, dx, dy)) {        x += dx, y += dy;        return true;    }    return false;}bool NP_unit::drop(NP_board &b) {    if (can_move(b, 1, 0)) {        dest_x = real_x + UNIT_HEIGHT;        dest_y = real_y;        x++;        set_state(dropping);        return true;    }    return false;    }void NP_unit::stick_to(NP_board &b) {    b.board[x][y] = face;    b.unit_board[x][y] = *this;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -