超级玛丽增强版源代码
//bitmaptool.h
#ifndef __BITMAPTOOL
#define __BITMAPTOOL
#include "filereport.h"
#define BM_BOTTOM_RIGHT 0
#define BM_BOTTOM_CENTER 1
#define BM_CENTER 2
#define BM_USER 3
//
class MYBITMAP
{
public:
MYBITMAP();
~MYBITMAP();
//初始化
void Init(HINSTANCE hInstance,int iResource,int row,int col);
void SetDevice(HDC hdest,HDC hsrc,int wwin,int hwin);
//
void SetPos(int istyle,int x,int y);
//显示
void Draw(DWORD dwRop);
void Stretch(int x,int y);
void Stretch(int x,int y,int id);
void Show(int x,int y);
void ShowCenter(int y);
void ShowLoop(int left,int top,int right,int bottom,int iframe);
void ShowNoBack(int x,int y,int iFrame);
void ShowNoBackLoop(int x,int y,int iFrame,int iNum);
//动画播放
void ShowAni();
void SetAni(int x,int y);
// FILEREPORT f;
HBITMAP hBm;
public:
//按照行列平均分成几个
int inum;
int jnum;
int width;
int height;
int screenwidth;
int screenheight;
HDC hdcdest;
HDC hdcsrc;
//当前位置
int xpos;
int ypos;
int iStartAni;
};
class MYBKSKY:public MYBITMAP
{
public:
MYBKSKY();
~MYBKSKY();
//show
void DrawRoll(); //循环补空
void DrawRollStretch(int x,int y);
void DrawRollStretch(int x,int y,int id);
void MoveTo(int x,int y);
void MoveRoll(int x);
//data
int xseparate;
};
#define BM_SQUARE 1
class MY ANIOBJ:public MYBITMAP
{
public:
MY ANIOBJ();
~MY ANIOBJ();
//init list
void InitAniList(int *pw,int *ph,int inum,int ismask);
void InitAniList(int style,int a,int b);
//show
void DrawItem(int x,int y,int id,int iframe);
void DrawItemNoMask(int x,int y,int id,int iframe);
//指定宽度
void DrawItemNoMaskWidth(int x,int y,int id,int w,int iframe);
//自动播放
void PlayItem(int x,int y,int id);
//
int wlist[20];
int hlist[20];
int ylist[20];
int iframeplay;
};
class MY ANIMAGIC:public MYBITMAP
{
public:
MY ANIMAGIC();
~MY ANIMAGIC();
//init list
void InitAniList(int *pw,int *ph,int inum);
void SetDevice(HDC hdest,HDC hsrc,HDC htemp);
//show
void DrawItem(int x,int y,int id,int iframe);
//
int wlist[20];
int hlist[20];
int ylist[20];
HDC hdctemp;
};
class MYROLE:public MYBITMAP
{
public:
MYROLE();
~MYROLE();
//init
void InitRole(int xleft, int xright);
void SetLimit(int xleft, int xright);
//show
void Draw();
void Draw(int x,int y,int iframe);
void ChangeFrame();
void SetState(int i);
void Move();
void Jump();
//ANI
void MoveTo(int x,int y);
void MoveOffset(int x,int y);
void MoveStepTo(int x,int y);//向目的地移动单位距离
void PlayAni();//播放一段动画
void SetAni(int istyle);
int IsInAni();//是否正在播放动画
//data
int iState;
int iFrame;
int minx;
int maxx;
//move
int movex;
int movey;
// jump
int jumpheight;
int jumpx;
//方向
int idirec;
//动画
int iAniBegin;
int iparam1;
int iAniStyle;
};
#endif
// bitmaptool.cpp
// Finishing https://www.360docs.net/doc/9c1076293.html,
#include "stdafx.h"
#include "bitmaptool.h"
#include "gamemap.h"
extern GAMEMAP gamemap;
extern FILEREPORT f1;
MYBITMAP::MYBITMAP()
{}
MYBITMAP::~MYBITMAP()
{
DeleteObject(hBm);
}
void MYBITMAP::Init(HINSTANCE hInstance,int iResource,int row,int col)
{
BITMAP bm;
inum=row;
jnum=col;
hBm=LoadBitmap(hInstance,MAKEINTRESOURCE(iResour ce));
GetObject(hBm,sizeof(BITMAP),&bm);
width=bm.bmWidth/inum;
height=bm.bmHeight/jnum;
}
void MYBITMAP::SetDevice(HDC hdest,HDC hsrc,int wwin,int hwin)
{
hdcdest=hdest;
hdcsrc=hsrc;
screenwidth=wwin;
screenheight=hwin;
}
void MYBITMAP::Show(int x,int y)
{
xpos=x;
ypos=y;
SelectObject(hdcsrc,hBm);
BitBlt(hdcdest,xpos,ypos,width,height,hdcsrc,0,0,SRCCOPY); }
void MYBITMAP::ShowCenter(int y)
{
xpos=(screenwidth-width)/2;
ypos=y;
SelectObject(hdcsrc,hBm);
BitBlt(hdcdest,xpos,ypos,width,height,hdcsrc,0,0,SRCCOPY); }
void MYBITMAP::ShowLoop(int left,int top,int right,int bottom,int iframe)
{
int i,j;
SelectObject(hdcsrc,hBm);
for(j=top;j { for(i=left;i { BitBlt(hdcdest,i,j,width,height,hdcsrc,iframe*width,0,SRCCO PY); } } } void MYBITMAP::ShowNoBack(int x,int y,int iFrame) { xpos=x; ypos=y; SelectObject(hdcsrc,hBm); BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,iFrame*width, height/2,SRCAND); BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,iFrame*width, 0,SRCPAINT); } void MYBITMAP::ShowNoBackLoop(int x,int y,int iFrame,int iNum) { int i; xpos=x; ypos=y; SelectObject(hdcsrc,hBm); for(i=0;i { BitBlt(hdcdest,xpos+i*width,ypos,width,height/2,hdcsrc,iFram e*width,height/2,SRCAND); BitBlt(hdcdest,xpos+i*width,ypos,width,height/2,hdcsrc,iFram e*width,0,SRCPAINT); } } void MYBITMAP::ShowAni() { /* if(!iStartAni) return; SelectObject(hdcsrc,hBm); BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,framenow*wid th,height/2,SRCAND); BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,framenow*wid th,0,SRCPAINT); framenow++; //播放结束 if(framenow>=inum) iStartAni=0; */ } void MYBITMAP::SetAni(int x,int y) { xpos=x; ypos=y; /* framenow=0; iStartAni=1; */ } void MYBITMAP::SetPos(int istyle,int x,int y) { switch(istyle) { case BM_CENTER: xpos=(screenwidth-width)/2; ypos=y; break; case BM_USER: xpos=x; ypos=y; break; } } void MYBITMAP::Draw(DWORD dwRop) { SelectObject(hdcsrc,hBm); BitBlt(hdcdest,xpos,ypos,width,height,hdcsrc,0,0,dwRop); } void MYBITMAP::Stretch(int x,int y) { SelectObject(hdcsrc,hBm); StretchBlt(hdcdest,xpos,ypos,width*x,height*y, hdcsrc,0,0,width,height, SRCCOPY); } void MYBITMAP::Stretch(int x,int y,int id) { SelectObject(hdcsrc,hBm); StretchBlt(hdcdest,xpos,ypos,width*x,height*y, hdcsrc,0,id*height, width,height, SRCCOPY); } ///////////////////////// bitmap object animation////////////////// MYBKSKY::MYBKSKY() { xseparate=0; } MYBKSKY::~MYBKSKY() {} void MYBKSKY::MoveTo(int x,int y) { xpos=x; ypos=y; } void MYBKSKY::MoveRoll(int x) { xseparate+=x; xseparate%=width; if(xseparate<0) { xseparate=width; } } void MYBKSKY::DrawRoll() { SelectObject(hdcsrc,hBm); BitBlt(hdcdest,xpos,ypos, width-xseparate,height, hdcsrc,xseparate,0,SRCCOPY); BitBlt(hdcdest,xpos+width-xseparate,ypos, xseparate,height, hdcsrc,0,0,SRCCOPY); } void MYBKSKY::DrawRollStretch(int x,int y) { SelectObject(hdcsrc,hBm); StretchBlt(hdcdest,xpos,ypos, (width-xseparate)*x,height*y, hdcsrc,xseparate,0, width-xseparate,height, SRCCOPY); StretchBlt(hdcdest,xpos+(width-xseparate)*x,ypos, xseparate*x,height*y, hdcsrc,0,0, xseparate,height, SRCCOPY); } void MYBKSKY::DrawRollStretch(int x,int y, int id) { SelectObject(hdcsrc,hBm); StretchBlt(hdcdest,xpos,ypos, (width-xseparate)*x,height*y, hdcsrc,xseparate,id*height, width-xseparate,height, SRCCOPY); StretchBlt(hdcdest,xpos+(width-xseparate)*x,ypos, xseparate*x,height*y, hdcsrc,0,id*height, xseparate,height, SRCCOPY); } ///////////////////////// bitmap role////////////////// MYROLE::MYROLE() {} MYROLE::~MYROLE() {} void MYROLE::MoveTo(int x,int y) { xpos=x; ypos=y; } void MYROLE::MoveOffset(int x,int y) { if(x==0 && y==0) return; if(!gamemap.RoleCanMove(x,y)) return; xpos+=x; ypos+=y;