D2D RPG游戏开发日记(二)--角色/队伍

角色图片类似于这种的四向图每次只绘制其中一个

初始的player类属性


class
Player { public: //队伍中角色数目 int length = 3; //是否激活--角色是否在队伍中 int is_active = 0; //window上坐标 int x = 0; int y = 0; //位置修正参数--角色图像的大小 int x_offset = 46; int y_offset = 92; //角色在地图上的坐标 int x_map = 0; int y_map = 0; //方向移动的朝向 int face = 1; //行走参数 long walk_interval = 100; //动画帧切换的速度(ms) int speed = 10; //速度 ID2D1Bitmap *bitmap; //角色的图像接口

 画角色方法

void Player::DrawPlayer(HWND hWnd, Player player, int face, int animation_ctrl, ID2D1RenderTarget *pRenderTarget)
{
    D2D1_SIZE_F size = player.bitmap->GetSize();

    // Draw bitmap
    pRenderTarget->DrawBitmap(
        player.bitmap,
        D2D1::RectF(
            player.x,
            player.y - player.y_offset,
            player.x + size.width / 4,
            player.y - player.y_offset + size.height / 4),   //D2D::RectF 要在屏幕上绘制的区域
        1.0f,
        D2D1_BITMAP_INTERPOLATION_MODE_LINEAR,
        D2D1::RectF(
        (animation_ctrl % 4)*(size.width / 4),
            size.height / 4 * (face - 1),
            (animation_ctrl % 4)*(size.width / 4) + size.width / 4,
            size.height / 4 * (face - 1) + size.height / 4)  //角色图片上的区域
    );

}

队伍角色切换方法

//player 成员之间传递属性
void set_player(Player player[], int oldindex, int newindex, int *current_player)
{
    player[newindex].x_map = player[oldindex].x_map;
    player[newindex].y_map = player[oldindex].y_map;
    player[newindex].face = player[oldindex].face;

    *current_player = newindex;
}


//TAB--队伍切换
VOID change_player(Player player[], int *current_player)
{
    for (int i = *current_player + 1; i < player[*current_player].length; i++)
    {
        if (player[i].is_active == 1)
        {
            set_player(player, *current_player, i, current_player);
            return;
        }
    }
    for (int i = 0; i < *current_player; i++)
    {
        if (player[i].is_active == 1)
        {
            set_player(player, *current_player, i, current_player);
            return;
        }
    }
}

 

posted @ 2017-02-25 18:15  evazore  阅读(378)  评论(0编辑  收藏  举报