| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 571 人关注过本帖
标题:求救 泡泡堂
只看楼主 加入收藏
灬xiaoning
Rank: 2
等 级:论坛游民
帖 子:27
专家分:10
注 册:2010-7-24
结帖率:75%
收藏
已结贴  问题点数:13 回复次数:1 
求救 泡泡堂
本人写了一款泡泡堂  但是AI和地图绘制那里有点问题 请求帮助 如果需要我可以发到邮箱

主类
#include "CManage.h"

Manage::Manage()
{
    m_Sprite = new Sprite;
    m_BKSprite = new Sprite;
    m_Sprite1 = new Sprite;
    m_BKsprite = new Sprite;
    m_IsUp = m_IsDown = m_IsLeft = m_IsRight = 0;
    m_Speed = 4;
}

Manage::~Manage()
{

}

void Manage::InitManage(HDC hdc,HINSTANCE hInst,char * filename,char *filename1,char *filename2)
{

    m_Sprite->SetIsFlash(true);
    m_Sprite->SetDir(1);
    m_Sprite->SetMaskColor(RGB(204,0,255));
    m_Sprite->SetTime(10);  
    m_Sprite->SetFrame(0);
    m_Sprite->CreateSpriteDc(hdc);
    m_Sprite->SetSize(250,360);   
    m_Sprite->SetClipSize(50,60);
    m_Sprite->LoadSprite(hInst,filename);

    m_BKSprite->SetIsFlash(false);
    m_BKSprite->CreateSpriteDc(hdc);
    m_BKSprite->SetSize(800,600);
    m_BKSprite->SetClipSize(800,600);
    m_BKSprite->LoadSprite(hInst,filename1);

    m_Sprite1->SetIsFlash(true);
    m_Sprite1->SetDir(1);
    m_Sprite1->SetMaskColor(RGB(204,0,255));
    m_Sprite1->SetTime(10);  
    m_Sprite1->SetFrame(0);
    m_Sprite1->CreateSpriteDc(hdc);
    m_Sprite1->SetSize(250,360);   
    m_Sprite1->SetClipSize(50,60);
    m_Sprite1->LoadSprite(hInst,filename2);

   


}

void Manage::UpdataManage()
{
    HeroMove();
}

void Manage::DrawManage(HDC hdc)
{
    m_BKSprite->DrawSprite(hdc);
    m_Sprite1->DrawSprite(hdc);
    m_Sprite->DrawSprite(hdc);
    m_Sprite1->SetPos(50,60);
   
}

void Manage::HandleMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch(message)
    {
    case WM_KEYDOWN:
        {
            switch(wParam)
            {
            case 'A':
            case VK_LEFT:
                SetHeroIsLeft(1);
                break;
            case 'W':
                SetHeroIsUp(1);
                break;
            case 'S':
                SetHeroIsDown(1);
                break;
            case 'D':
                SetHeroIsRight(1);
                break;
            }
        }
        break;
    case WM_KEYUP:
        {
            switch(wParam)
            {
            case 'A':
            case VK_LEFT:
                SetHeroIsLeft(0);
                break;
            case 'W':
                SetHeroIsUp(0);
                break;
            case 'S':
                SetHeroIsDown(0);
                break;
            case 'D':
                SetHeroIsRight(0);
                break;
            }
        }
        break;
    }
}

void Manage::HeroMove()
{
    int tempX,tempY;
    tempX = m_Sprite->GetX();
    tempY = m_Sprite->GetY();


    if(m_IsUp)
    {
        m_Sprite->SetDir(0);
        if(tempY - m_Speed >= 0)
            m_Sprite->SetPos(tempX,tempY - m_Speed);
    }
    else if(m_IsDown)
    {
        m_Sprite->SetDir(1);
        if(tempY + m_Speed <= 500)
            m_Sprite->SetPos(tempX,tempY + m_Speed);
    }
    else if(m_IsLeft)
    {
        m_Sprite->SetDir(2);
        if(tempX -m_Speed >= 0)
            m_Sprite->SetPos(tempX - m_Speed,tempY);
    }
    else if(m_IsRight)
    {
        m_Sprite->SetDir(3);
        if(tempX + m_Speed <= 580)
            m_Sprite->SetPos(tempX + m_Speed,tempY);
    }
}

void Manage::SetHeroIsUp(bool isup)
{
    m_IsUp = isup;
}

void Manage::SetHeroIsDown(bool isdown)
{
    m_IsDown = isdown;
}

void Manage::SetHeroIsLeft(bool isleft)
{
    m_IsLeft = isleft;
}

void Manage::SetHeroIsRight(bool isright)
{
    m_IsRight = isright;
}

#pragma once
#include "stdafx.h"


class Sprite;

class Manage
{
public:
    Manage();
    ~Manage();
    void InitManage(HDC hdc,HINSTANCE hInst,char * filename,char *filename1,char *filename2);
    void UpdataManage();
    void DrawManage(HDC hdc);
    void HandleMessage(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
public:
    void SetHeroIsUp(bool isup);
    void SetHeroIsDown(bool isdown);
    void SetHeroIsLeft(bool isleft);
    void SetHeroIsRight(bool isright);
private:
    void HeroMove();
private:
    Sprite * m_Sprite;
    Sprite * m_Sprite1;
    Sprite * m_BKSprite;
    Sprite * m_BKsprite;

    bool m_IsUp,m_IsDown,m_IsLeft,m_IsRight;
    int m_Speed;
};

//精灵类
#include "CSprite.h"


Sprite::Sprite()
{
    m_IsFlash = false;
    m_Time = 0;
    m_SX = m_SY = 0;
    m_LeftPos = m_TopPos = 0;
    m_Dir = m_Frame = 0;
    m_Width = m_Height = 0;
    m_MaskColor = 0x000000;
}

Sprite::~Sprite()
{

}

void Sprite::SetIsFlash(bool isflash)  //动画
{
    m_IsFlash = isflash;
}

void Sprite::SetTime(int time)  //时间延迟
{
    m_Time = time;
}

void Sprite::SetDir(int dir)  //目录
{
    m_Dir = dir;
}

void Sprite::SetFrame(int frame)  //帧
{
    m_Frame = frame;
}

void Sprite::SetSize(int tw,int th)   //尺寸
{
    m_Width = tw;
    m_Height = th;
}

void Sprite::SetClipSize(int tw,int th)    //消减尺寸
{
    m_ClipWidth = tw;
    m_ClipHeight = th;
}

void Sprite::SetPos(int nx,int ny)   //位置
{
    m_SX = nx;
    m_SY = ny;
}

void Sprite::SetStaticPos(int nx,int ny)  //静态位置
{
    m_LeftPos = nx;
    m_TopPos = ny;
}

void Sprite::CreateSpriteDc(HDC hdc)   //创建精灵DC
{
    m_Dc = CreateCompatibleDC(hdc);
    m_MaskDc = CreateCompatibleDC(hdc);
}

void Sprite::LoadSprite(HINSTANCE hinst,char * filename)          //加载精灵
{
    m_Bitmap = (HBITMAP)LoadImage(hinst,filename,IMAGE_BITMAP,m_Width,m_Height,LR_LOADFROMFILE);
    m_MaskBitmap = CreateBitmap(m_ClipWidth,m_ClipHeight,1,1,0);
    SelectObject(m_Dc,m_Bitmap);
    SelectObject(m_MaskDc,m_MaskBitmap);
}
void Sprite::SetMaskColor(COLORREF color)  //透明颜色
{
    m_MaskColor = color;
}

void Sprite::DrawSprite(HDC hdc)  //画
{
    SetBkColor(m_Dc,m_MaskColor);

    if(m_IsFlash)
    {
        int temp = m_Width / m_ClipWidth;

        BitBlt(m_MaskDc,0,0,m_ClipWidth,m_ClipHeight,m_Dc,m_Frame / m_Time * m_ClipWidth,m_Dir * m_ClipHeight,SRCCOPY);
        BitBlt(hdc,m_SX,m_SY,m_ClipWidth,m_ClipHeight,m_Dc,m_Frame / m_Time * m_ClipWidth,m_Dir * m_ClipHeight,SRCINVERT);
        //BitBlt(hdc,0,0,m_Width,m_Height,m_MaskDc,m_LeftPos,m_TopPos,SRCCOPY);

        BitBlt(hdc,m_SX,m_SY,m_ClipWidth,m_ClipHeight,m_MaskDc,0,0,SRCAND);
        BitBlt(hdc,m_SX,m_SY,m_ClipWidth,m_ClipHeight,m_Dc,m_Frame / m_Time * m_ClipWidth,m_Dir * m_ClipHeight,SRCINVERT);

        m_Frame++;
        if(m_Frame >= (m_Time * temp))
            m_Frame = 0;
    }
    else
    {
        BitBlt(m_MaskDc,0,0,m_Width,m_Height,m_Dc,m_LeftPos,m_TopPos,SRCCOPY);
        //BitBlt(hdc,0,0,m_Width,m_Height,m_MaskDc,m_LeftPos,m_TopPos,SRCCOPY);

        BitBlt(hdc,m_SX,m_SY,m_Width,m_Height,m_Dc,m_LeftPos,m_TopPos,SRCINVERT);
        BitBlt(hdc,m_SX,m_SY,m_Width,m_Height,m_MaskDc,0,0,SRCAND);
        BitBlt(hdc,m_SX,m_SY,m_Width,m_Height,m_Dc,m_LeftPos,m_TopPos,SRCINVERT);
    }
}

#pragma once
#include "stdafx.h"

class Sprite
{
public:
    Sprite();
    ~Sprite();
    void SetIsFlash(bool isflash);
    void SetTime(int time);
    void SetDir(int dir);
    void SetFrame(int frame);
    void SetSize(int tw,int th);
    void SetClipSize(int tw,int th);
    void SetPos(int nx,int ny);
    void SetStaticPos(int nx,int ny);
public:
    void CreateSpriteDc(HDC hdc);
    void LoadSprite(HINSTANCE hinst,char * filename);
    void SetMaskColor(COLORREF color);
    void DrawSprite(HDC hdc);
public:
    int GetDir() {return m_Dir;};
    int GetFrame() {return m_Frame;};
    int GetX() {return  m_SX;};
    int GetY() {return m_SY;};
    int GetWidth() {return m_Width;};
    int GetHeight() {return m_Height;};
private:
    bool m_IsFlash;            //是否是动画
    int m_Time;                //延时
    int m_SX,m_SY;            //X,Y坐标
    int m_LeftPos,m_TopPos;    //左上点X,Y坐标
    int m_Dir;                //方向
    int m_Frame;            //帧
    int m_Width,m_Height;    //宽,高
    int m_ClipWidth,m_ClipHeight;    //裁剪宽,高
    HBITMAP m_Bitmap;        //位图句柄
    HBITMAP m_MaskBitmap;    //遮罩位图句柄
    HDC m_Dc;                //设备环境句柄
    HDC m_MaskDc;            //遮罩设备环境句柄
    COLORREF m_MaskColor;    //遮罩颜色
};
搜索更多相关主题的帖子: 泡泡堂 
2010-08-29 07:59
赵本山
Rank: 2
等 级:论坛游民
帖 子:34
专家分:47
注 册:2010-7-4
收藏
得分:13 
真麻烦 。
2010-08-29 09:49
快速回复:求救 泡泡堂
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.040674 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved