版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、/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 MYBITMAPpublic:MYBITMAP();MYBITMAP();/初始化void Init(HINSTANCE hInstance,int iResource,int row,int col);void SetDevice(HDC h
2、dest,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 iFr
3、ame);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
4、MYBITMAPpublic:MYBKSKY();MYBKSKY();/showvoid DrawRoll(); /循環(huán)補空void DrawRollStretch(int x,int y);void DrawRollStretch(int x,int y,int id);void MoveTo(int x,int y);void MoveRoll(int x);/dataint xseparate;#define BM_SQUARE 1class MYANIOBJ:public MYBITMAPpublic:MYANIOBJ();MYANIOBJ();/init listvoid InitA
5、niList(int *pw,int *ph,int inum,int ismask);void InitAniList(int style,int a,int b);/showvoid 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 wlis
6、t20;int hlist20;int ylist20;int iframeplay;class MYANIMAGIC:public MYBITMAPpublic:MYANIMAGIC();MYANIMAGIC();/init listvoid InitAniList(int *pw,int *ph,int inum);void SetDevice(HDC hdest,HDC hsrc,HDC htemp);/showvoid DrawItem(int x,int y,int id,int iframe);/int wlist20;int hlist20;int ylist20;HDC hdc
7、temp;class MYROLE:public MYBITMAPpublic:MYROLE();MYROLE();/initvoid InitRole(int xleft, int xright);void SetLimit(int xleft, int xright);/showvoid Draw();void Draw(int x,int y,int iframe);void ChangeFrame();void SetState(int i);void Move();void Jump();/ANIvoid MoveTo(int x,int y);void MoveOffset(int
8、 x,int y);void MoveStepTo(int x,int y);/向目的地移動單位距離void PlayAni();/播放一段動畫void SetAni(int istyle);int IsInAni();/是否正在播放動畫/dataint iState;int iFrame;int minx;int maxx;/moveint movex;int movey;/ jumpint jumpheight;int jumpx;/方向int idirec;/動畫int iAniBegin;int iparam1;int iAniStyle;#endif/ bitmaptool.cpp/
9、 Finishing #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;
10、hBm=LoadBitmap(hInstance,MAKEINTRESOURCE(iResource);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
11、=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 i
12、frame)int i,j;SelectObject(hdcsrc,hBm);for(j=top;j<bottom;j+=height)for(i=left;i<right;i+=width)BitBlt(hdcdest,i,j,width,height,hdcsrc,iframe*width,0,SRCCOPY);void MYBITMAP:ShowNoBack(int x,int y,int iFrame)xpos=x;ypos=y;SelectObject(hdcsrc,hBm);BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,i
13、Frame*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<iNum;i+)BitBlt(hdcdest,xpos+i*width,ypos,width,height/2,hdcsrc,iFrame*width,heig
14、ht/2,SRCAND);BitBlt(hdcdest,xpos+i*width,ypos,width,height/2,hdcsrc,iFrame*width,0,SRCPAINT);void MYBITMAP:ShowAni()/*if(!iStartAni)return;SelectObject(hdcsrc,hBm);BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,framenow*width,height/2,SRCAND);BitBlt(hdcdest,xpos,ypos,width,height/2,hdcsrc,framenow*w
15、idth,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
16、: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,hB
17、m);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;
18、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,(wi
19、dth-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-xsepar
20、ate)*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:MoveOffse
21、t(int x,int y)if(x=0 && y=0)return;if(!gamemap.RoleCanMove(x,y)return;xpos+=x;ypos+=y;if(xpos<minx)xpos=minx;if(xpos>maxx)xpos=maxx;void MYROLE:MoveStepTo(int x,int y)if(xpos<x)xpos+=ROLE_STEP;if(ypos<y)ypos+=8;if(ypos>y)ypos=y;/ 去背顯示void MYROLE:Draw()if(iAniBegin)PlayAni();el
22、seSelectObject(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 MYROLE:Draw(int x,int y,int frame)SelectObject(hdcsrc,hBm);BitBlt(hdcdest,x,y,width,height/2,hdcsrc,frame*width,height/
23、2,SRCAND);BitBlt(hdcdest,x,y,width,height/2,hdcsrc,frame*width,0,SRCPAINT);void MYROLE:InitRole(int xleft,int xright)iFrame=0;iState=0;maxx=xright;minx=xleft;jumpheight=0;movex=0;movey=0;jumpx=0;idirec=0;iAniBegin=0;void MYROLE:SetLimit(int xleft,int xright)maxx=xright;minx=xleft;void MYROLE:Move()i
24、f(0 = movey)/水平移動MoveOffset(movex, 0);else/跳動MoveOffset(jumpx, 0);MoveOffset(0, movey);/幀控制if(movex<0 && iFrame<3)iFrame=3;if(movex>0 && iFrame>=3)iFrame=0;if(movex!=0)if(0=idirec)iFrame=1-iFrame;elseiFrame=7-iFrame;if(movey!=0)iFrame=idirec*3;if(movey<0)/upjumpheight+
25、=(-movey);/根據重力影響,加速度減慢if(movey<-1)movey+;/到達頂點后向下落if(jumpheight >= JUMP_HEIGHT * 32)jumpheight = JUMP_HEIGHT * 32;movey=4;else if(movey>0)jumpheight -= movey;/根據重力影響,加速度增大movey+;void MYROLE:Jump()/上升過程MoveOffset(0, -4);void MYROLE:ChangeFrame()void MYROLE:SetState(int i)iState=i;void MYROL
26、E:SetAni(int istyle)iAniStyle=istyle;iparam1=0;iAniBegin=1;/是否正在播放動畫int MYROLE:IsInAni()return iAniBegin;void MYROLE:PlayAni()switch(iAniStyle)case ROLE_ANI_DOWN:if(iparam1>31)break;/人物下降動畫SelectObject(hdcsrc,hBm);BitBlt(hdcdest,xpos,ypos+iparam1,width,height/2-iparam1,hdcsrc,iFrame*width,height/
27、2,SRCAND); BitBlt(hdcdest,xpos,ypos+iparam1,width,height/2-iparam1,hdcsrc,iFrame*width,0,SRCPAINT);iparam1+;break;case ROLE_ANI_UP:if(iparam1>31)break;/人物上升動畫SelectObject(hdcsrc,hBm);BitBlt(hdcdest,xpos,ypos+32-iparam1,width,iparam1,hdcsrc,iFrame*width,height/2,SRCAND);BitBlt(hdcdest,xpos,ypos+32
28、-iparam1,width,iparam1,hdcsrc,iFrame*width,0,SRCPAINT);iparam1+;if(iparam1>31)iAniBegin=0;/動畫結束default:break;/ my animation /MYANIOBJ:MYANIOBJ()memset(wlist, 0, sizeof(wlist);memset(hlist, 0, sizeof(hlist);memset(ylist, 0, sizeof(ylist);iframeplay=0;MYANIOBJ:MYANIOBJ()void MYANIOBJ:DrawItem(int x
29、,int y,int id,int iframe)SelectObject(hdcsrc,hBm);BitBlt(hdcdest,x,y,wlistid,hlistid,hdcsrc,iframe*wlistid,ylistid+hlistid,SRCAND);BitBlt(hdcdest,x,y,wlistid,hlistid,hdcsrc,iframe*wlistid,ylistid,SRCPAINT);void MYANIOBJ:DrawItemNoMask(int x,int y,int id,int iframe)SelectObject(hdcsrc,hBm);BitBlt(hdc
30、dest,x,y,wlistid,hlistid,hdcsrc,iframe*wlistid,ylistid,SRCCOPY);void MYANIOBJ:DrawItemNoMaskWidth(int x,int y,int id,int w,int iframe)SelectObject(hdcsrc,hBm);BitBlt(hdcdest,x,y,w,hlistid,hdcsrc,iframe*wlistid,ylistid,SRCCOPY);void MYANIOBJ:PlayItem(int x,int y,int id)SelectObject(hdcsrc,hBm);BitBlt
31、(hdcdest,x,y,wlistid,hlistid,hdcsrc,iframeplay*wlistid,ylistid+hlistid,SRCAND);BitBlt(hdcdest,x,y,wlistid,hlistid,hdcsrc,iframeplay*wlistid,ylistid,SRCPAINT);iframeplay=(iframeplay+1)%2;void MYANIOBJ:InitAniList(int *pw,int *ph,int inum,int ismask)int i;memcpy(wlist, pw, inum*sizeof(int);memcpy(hlis
32、t, ph, inum*sizeof(int);ylist0=0;for(i=1;i<inum;i+)/如果是mask,兩張圖片的間隔高度要乘以2ylisti=ylisti-1+hlisti-1*(ismask+1);void MYANIOBJ:InitAniList(int style,int a, int b)int i;switch(style)case BM_SQUARE:/ a : 數量, b: 邊長for(i=0;i<a;i+)wlisti=b;hlisti=b;ylisti=i*b;break;default:break;/ my animation magic/MY
33、ANIMAGIC:MYANIMAGIC()memset(wlist, 0, sizeof(wlist);memset(hlist, 0, sizeof(hlist);memset(ylist, 0, sizeof(ylist);MYANIMAGIC:MYANIMAGIC()void MYANIMAGIC:DrawItem(int x,int y,int id,int iframe)SelectObject(hdcsrc,hBm);BitBlt(hdcdest,x,y,wlistid,hlistid,hdcsrc,iframe*wlistid,ylistid+hlistid,SRCAND);Bi
34、tBlt(hdcdest,x,y,wlistid,hlistid,hdcsrc,iframe*wlistid,ylistid,SRCPAINT);/*/先在臨時DC上畫出效果總圖BitBlt(hdctemp,0,0,wlistid,hlistid,hdcsrc,0,ylistid,SRCCOPY);/用MASK圖作裁剪BitBlt(hdctemp,0,0,wlistid,hlistid,hdcsrc,iframe*wlistid,ylistid,SRCPAINT);/最后畫到屏幕上BitBlt(hdcdest,x,y,wlistid,hlistid,hdctemp,0,0,SRCPAINT);
35、*/帶MASKvoid MYANIMAGIC:InitAniList(int *pw,int *ph,int inum)int i;memcpy(wlist, pw, inum*sizeof(int);memcpy(hlist, ph, inum*sizeof(int);ylist0=0;for(i=1;i<inum;i+)ylisti=ylisti-1+hlisti-1*2;void MYANIMAGIC:SetDevice(HDC hdest, HDC hsrc, HDC htemp)hdcdest=hdest;hdcsrc=hsrc;hdctemp=htemp;/filerepor
36、t.h#ifndef _FILEREPORT#define _FILEREPORTclass FILEREPORTpublic:FILEREPORT();FILEREPORT(char *p);FILEREPORT();void put(char *p);void put(char *p,int a,int b);void putnum(int i,char *p);/void CheckDC(HDC h,char *p);/showvoid SetDevice(HDC h,int x,int y);void Output(char *p,int a,int b);void Show();pr
37、ivate:FILE *fp;/計數器組int num5;/showHDC hshow;int xpos;int ypos;char info50;#endif/filereport.cpp#include "stdafx.h"#include "filereport.h"#include "stdio.h"#include "stdlib.h"FILEREPORT:FILEREPORT()fp=fopen("trace.txt","w");memset(num,0,size
38、of(num);FILEREPORT:FILEREPORT(char *p)fp=fopen(p,"w");memset(num,0,sizeof(num);FILEREPORT:FILEREPORT()fclose(fp);void FILEREPORT:put(char *p)fwrite(p,sizeof(char),strlen(p),fp);fwrite("n",1,1,fp);/帶計數器的跟蹤void FILEREPORT:putnum(int i,char *p)char temp50;sprintf(temp,"(%d) &qu
39、ot;,numi);fwrite(temp,sizeof(char),strlen(temp),fp);numi+;fwrite(p,sizeof(char),strlen(p),fp);fwrite("n",1,1,fp);void FILEREPORT:put(char *p,int a,int b)char temp50;sprintf(temp,"%s : %d , %d",p,a,b);fwrite(temp,sizeof(char),strlen(temp),fp);fwrite("n",1,1,fp);void FILE
40、REPORT:CheckDC(HDC h,char *p)if(h=NULL)fwrite(p,sizeof(char),strlen(p),fp);fwrite("n",1,1,fp);void FILEREPORT:SetDevice(HDC h,int x,int y)hshow=h;xpos=x;ypos=y;void FILEREPORT:Output(char *p,int a,int b)sprintf(info,"%s:%d,%d",p,a,b);void FILEREPORT:Show()TextOut(hshow,xpos,ypos,
41、info,strlen(info);/gamemap.h#ifndef _GAMEMAP#define _GAMEMAP#include "bitmaptool.h"struct MapObjectint x;int y;int w;int h;int id;int iframe;int iframemax;/最大幀數int show;/是否顯示;struct ROLEint x;int y;int w;int h;int id;int iframe;int iframemax;/最大幀數/移動部分int xleft;/左界限int xright;/右界限int movex
42、;/人物屬性int health;int show;/是否顯示;struct MAPINFOint iNextMap;int iSubMap;int xReturnPoint;int yReturnPoint;int iBackBmp;int viewmax;class GAMEMAPpublic:int LoadMap();void Init();void InitMatch();/入參,物體索引圖void Show(MYANIOBJ & bmobj);/入參,背景物體索引圖void ShowBkObj(MYANIOBJ & bmobj);/入參,動畫物體索引圖void Sh
43、owAniObj(MYANIOBJ & bmobj);void ShowInfo(HDC h);void ShowOther(HDC h);/鍵盤處理int KeyProc(int iKey);void KeyUpProc(int iKey);void MoveView();/設置視圖起始坐標void SetView(int x);void SetViewState(int i);void SetGameState(int i);/hittestint RoleCanMove(int xoff, int yoff);int CheckRole();int CheckAni(int it
44、imeclip);void ClearEnemy(int i);void ClearCoin(int i);/動畫幀控制void ChangeFrame(int itimeclip);/入參,時間片/邏輯檢測int IsWin();void Fail();void Fail_Wait();/地圖切換void ChangeMap();/錯誤檢查void CodeErr(int i);/菜單控制void ShowMenu(MYANIOBJ & bmobj);GAMEMAP();GAMEMAP();/dataint iMatch;int iLife;int iGameState;struct
45、 MapObject MapArrayMAX_MAP_OBJECT;int iMapObjNum;struct MapObject MapBkArrayMAX_MAP_OBJECT;int iMapBkObjNum;struct ROLE MapEnemyArrayMAX_MAP_OBJECT;int iMapEnemyCursor;struct MapObject MapCoinArrayMAX_MAP_OBJECT;int iCoinNum;/MAP DATAint iNextMap;/ role dataint iMoney;int iAttack;/攻擊方式/viewint viewx
46、;int viewy;int iViewState;/地圖數據struct MAPINFO mapinfo;/frame controlint ienemyframe;int ibkobjframe;/FIREstruct ROLE FireArrayMAX_MAP_OBJECT;int iFireNum;int iTimeFire;/兩個子彈的時間間隔int iBeginFire;/bombstruct MapObject BombArrayMAX_MAP_OBJECT;int iBombNum;/攻擊對象提示char AttackName20;int iAttackLife;int iAt
47、tackMaxLife;/菜單部分int iMenu;/屏幕縮放int iScreenScale;#endif/gamemap.cpp/ Finishing #include "stdafx.h"#include "gamemap.h"#include "myclock.h"#include "tool01.h"#include "texttool.h"extern int wwin,hwin;extern HWND hWndMain;/基本圖像extern MYANIOBJ bmMap;/天空
48、背景extern MYBKSKY bmSky;/角色extern MYROLE rmain;/計時器extern MYCLOCK c1;extern MYANIMAGIC bmMagic;extern struct MAPINFO allmapinfo;extern struct ROLE gl_enemy_normal;/extern FILEREPORT f1;GAMEMAP:GAMEMAP()iScreenScale=0;Init();GAMEMAP:GAMEMAP()int GAMEMAP:LoadMap()FILE *fp;char temp50=0;int find=0;int i;memset(MapArray,0,sizeof(MapArray);iMapObjNum=0;memset(MapBkArray,0,sizeof(MapBkArray);iMapBkObjNum=0;memset(MapEnemyArray,0,sizeof(MapEnemyArray);memset(MapCoinArray,0,sizeof(MapCoinArray);iCoinNum=0;fp=fopen(PATH
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度某旅游度假區(qū)水電暖系統(tǒng)設計與安裝合同2篇
- 2025版五星級酒店客房服務員勞動合同9篇
- 2025版企業(yè)食堂管理承包合同模板3篇
- 二零二五版多場景物聯網技術應用合同3篇
- 醫(yī)院醫(yī)療設備管理與發(fā)展規(guī)劃知識考核試卷
- 土地利用規(guī)劃中的城鄉(xiāng)水源地保護考核試卷
- 2025年合資協(xié)議書參考樣本
- 2025年勞動仲裁裁決和解協(xié)議
- 2025年加盟商業(yè)合同
- 2025年大數據智能分析合作協(xié)議
- 物業(yè)民法典知識培訓課件
- 2023年初中畢業(yè)生信息技術中考知識點詳解
- 2024-2025學年八年級數學人教版上冊寒假作業(yè)(綜合復習能力提升篇)(含答案)
- 《萬方數據資源介紹》課件
- 醫(yī)生定期考核簡易程序述職報告范文(10篇)
- 第一章-地震工程學概論
- 《中國糖尿病防治指南(2024版)》更新要點解讀
- 交通運輸類專業(yè)生涯發(fā)展展示
- 2024年山東省公務員錄用考試《行測》試題及答案解析
- 老年護理學-老年人與人口老齡化-課件
- 元代文學緒論
評論
0/150
提交評論