您的位置:首页 > 其它

魔塔 游戏开发1

2013-01-16 19:04 197 查看
这个小游戏主要利用的是win32 API,中间的技术有 双缓冲防止闪屏,卷页等 有兴趣的朋友可以看下,由于这个很久前写的,中间有很多地方不足,望大家见谅。

-----------------------------------------------------------game.h---------------------------------------------------------

#include <windows.h>
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) &0x8000)? 1:0)
#define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) &0x8000)? 0:1)

extern bool bGameOver;
extern HBITMAP bmpStart,bmpEnd,bmpSuccess;
extern HBITMAP bmpMan,bmpBtnStart,bmpBtnEnd;
extern HBITMAP bmpMaps[15];
extern HDC mdc;
extern int nBtnStart_y,nBtnEnd_y;
extern int nStartToMap;
extern bool bStartToMapScroll;
extern int nMapToEnd,nMapToSuccess;
extern bool bIsStartScreen,bIsMapScreen,bIsEndScreen,bIsSuccessScreen;

bool Game_Init(HDC& hdc);
void Game_Run(HDC hdc);
void Game_ShutDown();

extern bool bIsBtnS,bIsBtnE;
extern bool bBtnSHave,bBtnEHave;
extern HWND hWnd;

----------------------------------game.cpp----------------------------------------------------
#include "Game.h"
#include "Role.h"
#include <stdio.h>
#include "MySound.h"
#define MAPSNUM 16*14
//=======================================================================
bool bGameOver=false;
int nBtnStart_y=0,nBtnEnd_y=0;
HBITMAP bmpStart,bmpEnd,bmpSuccess;
HBITMAP bmpMan,bmpBtnStart,bmpBtnEnd;
HBITMAP bmpMaps[15];
HDC mdc;
HDC dc_Start,dc_Map,dc_End,dc_Success;
HDC bufdc;
int nStartToMap=0;
bool bStartToMapScroll=false;
int nMapToEnd=0,nMapToSuccess=0;
bool bIsStartScreen=true,bIsMapScreen=false,bIsEndScreen=false,bIsSuccessScreen=false;

float nBulletMove=0.1;//up bullet
float cxBullet=500,cyBullet=100;

float xBullet=350,yBullet=600;//down bullet
float nBulletMoved=0.1;

int xNeedleU=550,yNeedleU=150;
bool bIsNeedleU=false;

int xNeedle=650,yNeedle=650;//down needle
int nNeedleNumd=0;
bool bIsNeedle=false;
//====================================================
//informations
int nManDamageMon=0,nMonDamageMan=0;//damage
int nMonsterLV=0,nMonsterHP=0,nMonsterA=0,nMonsterD=0;//monster
//=========================Roles=======================
MAN man; //man ' object
bool bIsManPath[MAPSNUM]; //weather man' path
POS posManPath[MAPSNUM]; //man ' pos
int nNowIndex=0; //man' pos Index
bool bGoU=false,bGoD=false,bGoL=false,bGoR=false;
int nManDir=MAN_D;
bool bFlag=true;
//=========================Monsters====================

MONSTER monster[MAPSNUM];

//====================================================
// Index Num
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// tile monsters shiled arrow1 diamon arrow2 needle bullet hourse

int nMapsIndex[MAPSNUM]={
15, 0 ,0, 1 ,1,15, 15, 15, 15, 1, 7, 15, 15, 15, 14, 1,
3 ,15, 2,15, 1,15, 0, 0, 7, 0, 15, 0, 0, 1, 1, 1,
15,15, 15,2, 0,15, 1 ,15, 15, 1, 15, 15, 15, 15, 15, 0,
0, 0, 1,15, 1,15, 1, 1, 15, 0, 0, 15, 15, 15, 15, 0,
0, 3,15,15, 4,15, 1, 15, 15, 5, 15, 15, 15, 7, 15, 1,
1, 1,15, 0, 0,15, 0, 4, 1, 1, 15, 15, 0 ,0, 0 ,1,
1, 15, 2, 8, 1,15, 5, 15, 15,15, 1, 15, 15, 6, 15 ,0,
0, 3, 15,15, 1, 1, 0, 15, 15,15, 0, 0, 0, 15, 15, 0,
0, 0 ,3, 0, 0,15, 1, 15, 4, 15 ,0, 5, 5, 15, 15, 0,
1, 15 ,15, 2 ,1,15, 1 ,1, 15, 0, 0, 15, 0, 15, 15 ,1,
0, 0, 4, 0 ,0,15 ,15, 15, 15,15, 15, 15, 1, 15, 15, 1,
0, 3,15,15,15,15, 1, 15 , 0, 0, 1, 5, 15, 15, 15 ,0,
1 ,9, 0, 0,15,4, 1, 15, 15,15, 1, 0, 0, 0, 15 ,1,
1, 1, 1, 1,1, 0, 0, 15, 10,15, 0, 11, 15, 15, 15, 0
};
//=======================================================================
//Informations

//======================Music===========================================
CDSoundInit sound_Laugh,sound_Btn;//Start Screen
CDSoundInit sound_Attack,sound_MapMusic,sound_KillMon;//Map Screen
CDSoundInit sound_Success,sound_End;

bool bIsBtnS=false,bIsBtnE=false;
bool bBtnSHave=false,bBtnEHave=false;
//=======================================================================
bool Game_Init(HDC& hdc)
{
bmpStart=(HBITMAP)LoadImage(NULL,L"pictures\\start.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);// start bitmap
bmpEnd=(HBITMAP)LoadImage(NULL,L"pictures\\over.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);// game over bitmap
bmpSuccess=(HBITMAP)LoadImage(NULL,L"pictures\\successed.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

bmpMan=(HBITMAP)LoadImage(NULL,L"pictures\\man.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
bmpBtnStart=(HBITMAP)LoadImage(NULL,L"pictures\\btnstart.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);
bmpBtnEnd=(HBITMAP)LoadImage(NULL,L"pictures\\btnend.bmp",
IMAGE_BITMAP,0,0,LR_LOADFROMFILE);

bmpMaps[0]=(HBITMAP)LoadImage(NULL,L"pictures\\tile1.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[1]=(HBITMAP)LoadImage(NULL,L"pictures\\tile2.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[2]=(HBITMAP)LoadImage(NULL,L"pictures\\monster1.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[3]=(HBITMAP)LoadImage(NULL,L"pictures\\monster11.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[4]=(HBITMAP)LoadImage(NULL,L"pictures\\monster2.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[5]=(HBITMAP)LoadImage(NULL,L"pictures\\monster3.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[6]=(HBITMAP)LoadImage(NULL,L"pictures\\monster4.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[7]=(HBITMAP)LoadImage(NULL,L"pictures\\bigmonster.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[8]=(HBITMAP)LoadImage(NULL,L"pictures\\shield.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[9]=(HBITMAP)LoadImage(NULL,L"pictures\\arrow1.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[10]=(HBITMAP)LoadImage(NULL,L"pictures\\diamond.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[11]=(HBITMAP)LoadImage(NULL,L"pictures\\arrow2.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[12]=(HBITMAP)LoadImage(NULL,L"pictures\\needle.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[13]=(HBITMAP)LoadImage(NULL,L"pictures\\bullet.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);
bmpMaps[14]=(HBITMAP)LoadImage(NULL,L"pictures\\hourse.bmp",IMAGE_BITMAP,100,50,LR_LOADFROMFILE);

bufdc=CreateCompatibleDC(hdc);

mdc=CreateCompatibleDC(hdc);
HBITMAP bmp;
bmp=CreateCompatibleBitmap(hdc,1000,700);
SelectObject(mdc,bmp);//CreateCompatibleBitmap

dc_Start=CreateCompatibleDC(hdc);
HBITMAP bmp1;
bmp1=CreateCompatibleBitmap(hdc,1000,700);
SelectObject(dc_Start,bmp1);//CreateCompatibleBitmap

dc_Map=CreateCompatibleDC(hdc);
HBITMAP bmp2;
bmp2=CreateCompatibleBitmap(hdc,1000,700);
SelectObject(dc_Map,bmp2);//CreateCompatibleBitmap

dc_End=CreateCompatibleDC(hdc);
SelectObject(dc_End,bmpEnd);//CreateCompatibleBitmap

dc_Success=CreateCompatibleDC(hdc);
SelectObject(dc_Success,bmpSuccess);//CreateCompatibleBitmap

//======================Start=========================
SelectObject(bufdc,bmpStart);
BitBlt(dc_Start,0,0,1000,700,bufdc,0,0,SRCCOPY);

//=======================Maps ' static objects=========================
int x,y;
for(int i=0;i<MAPSNUM;i++)
{
x=(i%16)*50;
y=(i/16)*50;

if(nMapsIndex[i]==0||nMapsIndex[i]==1)
{

SelectObject(bufdc,bmpMaps[nMapsIndex[i]]);
BitBlt(dc_Map,x,y,50,50,bufdc,50,0,SRCAND);
BitBlt(dc_Map,x,y,50,50,bufdc,0,0,SRCPAINT);
}
posManPath[i].xPos=x;
posManPath[i].yPos=y;

if(nMapsIndex[i]==2||nMapsIndex[i]==3)
{
monster[i].SetMonster(50,1,1,0);
}
else if(nMapsIndex[i]==4)
{
monster[i].SetMonster(100,2,3,0);
}
else if(nMapsIndex[i]==5)
{
monster[i].SetMonster(50,3,10,0);
}
else if(nMapsIndex[i]==6||nMapsIndex[i]==7)
{
monster[i].SetMonster(100,4,20,5);
}

}
//===============Init sound===================
if(!sound_Laugh.InitDSound(hWnd)) return false;
if(!sound_Laugh.LoadSound(L"sound\\laugh.wav"))return false;

if(!sound_Btn.InitDSound(hWnd)) return false;
if(!sound_Btn.LoadSound(L"sound\\buttonsound.wav")) return false;//Start Screen

if(!sound_Attack.InitDSound(hWnd)) return false;
if(!sound_Attack.LoadSound(L"sound\\attact.wav"))return false;

if(!sound_MapMusic.InitDSound(hWnd)) return false;
if(!sound_MapMusic.LoadSound(L"sound\\bgmusic.WAV")) return false;

if(!sound_KillMon.InitDSound(hWnd)) return false;
if(! sound_KillMon.LoadSound(L"sound\\kill.wav"))return false;//Map Screen

if(!sound_Success.InitDSound(hWnd)) return false;
if(!sound_Success.LoadSound(L"sound\\successed.wav"))return false;

if(!sound_End.InitDSound(hWnd)) return false;
if(! sound_End.LoadSound(L"sound\\failed.wav"))return false;

sound_Laugh.PlayMySoundOnce();
return true;
}

//==========================================================Game Run======================================
void Game_Run(HDC hdc)
{

//=============Informations=================

TextOut(dc_Map,850,0*30,L"Informations",strlen("Informations"));
//man

TextOut(dc_Map,850,1*30,L"Man HP",strlen("Man HP"));

TextOut(dc_Map,850,3*30,L"Man Attack",strlen("Man Attack"));

TextOut(dc_Map,850,5*30,L"Man Defense",strlen("Man Defense"));
//monster

TextOut(dc_Map,850,7*30,L"Monster LV",strlen("Monster LV"));

TextOut(dc_Map,850,9*30,L"Monater HP",strlen("Monater Hp"));

TextOut(dc_Map,850,11*30,L"Monater Attack",strlen("Monater Attack"));

TextOut(dc_Map,850,13*30,L"Monater Defense",strlen("Monater Defense"));
//damage

TextOut(dc_Map,840,15*30,L"Monster Damage Man",strlen("Monster Damage Man"));

TextOut(dc_Map,840,17*30,L"Man Damage Monster",strlen("Man Damage Monster"));

TextOut(dc_Map,820,20*30,L" 你需要一定策略才能通过 ",strlen(" 你需要一定策略才能通过 "));

TextOut(dc_Map,860,21*30,L" 作者 : 小松 ",strlen(" 作者 : 小松")-5);

TextOut(dc_Map,840,22*30,L" 小松 QQ 474805681",strlen(" 小松 QQ 474805681")-2);

//man Informations
char man_hp[10]={0};
sprintf(man_hp,"%d ",man.nHP);
TextOutA(dc_Map,870,2*30,(LPCSTR)man_hp,3);

char man_at[10]={0};
sprintf(man_at,"%d ",man.nAttact);
TextOutA(dc_Map,870,4*30,(LPCSTR)man_at,2);

char man_df[10]={0};
sprintf(man_df,"%d ",man.nDefense);
TextOutA(dc_Map,870,6*30,(LPCSTR)man_df,2);
//monster Informations

char monlv[10]={0};
sprintf(monlv,"%d ",nMonsterLV);
TextOutA(dc_Map,870,8*30,(LPCSTR)monlv,2);

char monhp[10]={0};
sprintf(monhp,"%d ",nMonsterHP);
TextOutA(dc_Map,870,10*30,(LPCSTR)monhp,3);

char mona[10]={0};
sprintf(mona,"%d ",nMonsterA);
TextOutA(dc_Map,870,12*30,(LPCSTR)mona,2);

char mond[10]={0};
sprintf(mond,"%d ",nMonsterD);
TextOutA(dc_Map,870,14*30,(LPCSTR)mond,2);

//attack Informations
char monDman[10]={0};
sprintf(monDman,"%d ",nMonDamageMan);
TextOutA(dc_Map,870,16*30,(LPCSTR)monDman,2);

char manDmon[10]={0};
sprintf(manDmon,"%d ",nManDamageMon);
TextOutA(dc_Map,870,18*30,(LPCSTR)manDmon,2);

//===========================================================
//whether push Key Esc
if(KEY_DOWN(VK_ESCAPE))
{
bGameOver=true;
PostQuitMessage(0);

}

//===============Control Man Pos===============================================
//================================================Up=================================================================================
if(KEY_DOWN(VK_UP)&&bGoU)
{
nManDamageMon=0,nMonDamageMan=0;
nMonsterLV=0;
nMonsterHP=0;
nMonsterA=0;
nMonsterD=0;
if(man.nPosy>0)
{
if(nMapsIndex[nNowIndex-16]!=0&&nMapsIndex[nNowIndex-16]!=1
&&bIsManPath[nNowIndex-16]&&!posManPath[nNowIndex-16].bIsMonster)//防止穿墙

{
man.SetPosY(posManPath[nNowIndex-16].yPos);
bGoU=false;
nNowIndex-=16;

}

if(posManPath[nNowIndex-16].bIsMonster&&bGoU)//monsters
{
man.SetPosY(posManPath[nNowIndex].yPos);
bGoU=false;
if((man.bKilled==false)&&(false==monster[nNowIndex-16].bKilled)&&(nNowIndex-16)>=0)
{

sound_Attack.PlayMySoundOnce();

man.nHP=man.nHP+man.nDefense-monster[nNowIndex-16].nAttact;
monster[nNowIndex-16].nHP=monster[nNowIndex-16].nHP+monster[nNowIndex-16].nDefense-man.nAttact;
nMonDamageMan=monster[nNowIndex-16].nAttact-man.nDefense;
nManDamageMon=man.nAttact-monster[nNowIndex-16].nDefense;

nMonsterLV=monster[nNowIndex-16].nLevel;
nMonsterHP=monster[nNowIndex-16].nHP;
nMonsterA=monster[nNowIndex-16].nAttact;
nMonsterD=monster[nNowIndex-16].nDefense;

if(monster[nNowIndex-16].IsKilled())
monster[nNowIndex-16].bKilled=true;
if(man.IsKilled())
man.bKilled=true;
}

if(man.bKilled)
{
man.bKilled=true;
// bGameOver=true;

bIsMapScreen=false;
bIsEndScreen=true;

}

if(monster[nNowIndex-16].bKilled)
{
sound_KillMon.PlayMySoundOnce();
BitBlt(dc_Map,posManPath[nNowIndex-16].xPos,posManPath[nNowIndex-16].yPos,50,50,
bufdc,0,0,BLACKNESS);
bIsManPath[nNowIndex-16]=true;
posManPath[nNowIndex-16].bIsMonster=false;
if(nNowIndex>=16)
nMapsIndex[nNowIndex-16]=15;

}

nNowIndex-=0;
}

//=======================Check Weapon===================
if(nMapsIndex[nNowIndex-16]==8)
{
man.nDefense+=1;

BitBlt(dc_Map,posManPath[nNowIndex-16].xPos,posManPath[nNowIndex-16].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-16]=15;
bIsManPath[nNowIndex-16]=true;

}
if(nMapsIndex[nNowIndex-16]==9)
{
man.nAttact+=5;

BitBlt(dc_Map,posManPath[nNowIndex-16].xPos,posManPath[nNowIndex-16].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-16]=15;
bIsManPath[nNowIndex-16]=true;

}
if(nMapsIndex[nNowIndex-16]==10)
{
man.nAttact+=5;
man.nDefense+=4;

BitBlt(dc_Map,posManPath[nNowIndex-16].xPos,posManPath[nNowIndex-16].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-16]=15;
bIsManPath[nNowIndex-16]=true;

}
if(nMapsIndex[nNowIndex-16]==11)
{
man.nAttact+=10;
man.nDefense+=10;

BitBlt(dc_Map,posManPath[nNowIndex-16].xPos,posManPath[nNowIndex-16].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-16]=15;
bIsManPath[nNowIndex-16]=true;

}
if(nMapsIndex[nNowIndex-16]==8||nMapsIndex[nNowIndex-16]==9
||nMapsIndex[nNowIndex-16]==10||nMapsIndex[nNowIndex-16]==11)
{
nNowIndex-=16;
}
}
nManDir=MAN_U;

}
//================================================Down===============================================================================
if(KEY_DOWN(VK_DOWN)&&bGoD)
{
nManDamageMon=0,nMonDamageMan=0;
nMonsterLV=0;
nMonsterHP=0;
nMonsterA=0;
nMonsterD=0;
if(man.nPosy<650)
{
//Check path
if(nMapsIndex[nNowIndex+16]!=0&&nMapsIndex[nNowIndex+16]!=1&&bIsManPath[nNowIndex+16]
&&!posManPath[nNowIndex+16].bIsMonster)
{
man.SetPosY(posManPath[nNowIndex+16].yPos);
bGoD=false;
nNowIndex+=16;
}

//Check Monsters
if(posManPath[nNowIndex+16].bIsMonster&&bGoD)//monsters
{
man.SetPosX(posManPath[nNowIndex].xPos);
bGoD=false;
if((false==man.bKilled)&&(false==monster[nNowIndex+16].bKilled))
{

//==========sound===========
sound_Attack.PlayMySoundOnce();

man.nHP=man.nHP+man.nDefense-monster[nNowIndex+16].nAttact;
monster[nNowIndex+16].nHP=monster[nNowIndex+16].nHP+monster[nNowIndex+16].nDefense-man.nAttact;
nMonDamageMan=monster[nNowIndex+16].nAttact-man.nDefense;
nManDamageMon=man.nAttact-monster[nNowIndex+16].nDefense;

nMonsterLV=monster[nNowIndex+16].nLevel;
nMonsterHP=monster[nNowIndex+16].nHP;
nMonsterA=monster[nNowIndex+16].nAttact;
nMonsterD=monster[nNowIndex+16].nDefense;
if(monster[nNowIndex+16].IsKilled()) monster[nNowIndex+16].bKilled=true;
if(man.IsKilled()) man.bKilled=true;
}
if(man.bKilled)
{
man.bKilled=true;
//bGameOver=true;

bIsMapScreen=false;
bIsEndScreen=true;
}

if(monster[nNowIndex+16].bKilled)
{
sound_KillMon.PlayMySoundOnce();
BitBlt(dc_Map,posManPath[nNowIndex+16].xPos,posManPath[nNowIndex+16].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex+16]=15;
bIsManPath[nNowIndex+16]=true;
posManPath[nNowIndex+16].bIsMonster=false;
}

nNowIndex+=0;
}
//=======================Check Weapon===================
if(posManPath[nNowIndex+16].bIsWeapon&&(nMapsIndex[nNowIndex+16]==8||nMapsIndex[nNowIndex+16]==9
||nMapsIndex[nNowIndex+16]==10||nMapsIndex[nNowIndex+16]==11))
{
if(nMapsIndex[nNowIndex+16]==8)
{
man.nDefense+=1;
}
if(nMapsIndex[nNowIndex+16]==9)
{
man.nAttact+=5;
}
if(nMapsIndex[nNowIndex+16]==10)
{
man.nAttact+=5;
man.nDefense+=4;
}

if(nMapsIndex[nNowIndex+16]==11)
{
man.nAttact+=10;
man.nDefense+=10;
}

nMapsIndex[nNowIndex+16]=15;
BitBlt(dc_Map,posManPath[nNowIndex+16].xPos,posManPath[nNowIndex+16].yPos,50,50,
bufdc,0,0,BLACKNESS);
bIsManPath[nNowIndex+16]=true;
posManPath[nNowIndex+16].bIsWeapon=false;
}
}
if(nMapsIndex[nNowIndex+16]==8||nMapsIndex[nNowIndex+16]==9||
nMapsIndex[nNowIndex+16]==10||nMapsIndex[nNowIndex+16]==11)
{
nNowIndex+=16;
}

nManDir=MAN_D;
}
//================================================Left==================================================================================
if(KEY_DOWN(VK_LEFT)&&bGoL)
{
nManDamageMon=0,nMonDamageMan=0;
nMonsterLV=0;
nMonsterHP=0;

nMonsterA=0;
nMonsterD=0;

if(man.nPosx>0)
{
if(nMapsIndex[nNowIndex-1]!=0&&nMapsIndex[nNowIndex-1]!=1
&&bIsManPath[nNowIndex-1]&&!posManPath[nNowIndex-1].bIsMonster)
{

man.SetPosX(posManPath[nNowIndex-1].xPos);
nNowIndex-=1;
bGoL=false;
}

if(posManPath[nNowIndex-1].bIsMonster&&bGoL)//monsters
{
man.SetPosX(posManPath[nNowIndex].xPos);
bGoL=false;

if((false==man.bKilled)&&(false==monster[nNowIndex-1].bKilled))
{
sound_Attack.PlayMySoundOnce();

man.nHP=man.nHP+man.nDefense-monster[nNowIndex-1].nAttact;
monster[nNowIndex-1].nHP=monster[nNowIndex-1].nHP+monster[nNowIndex-1].nDefense-man.nAttact;
nMonDamageMan=monster[nNowIndex-1].nAttact-man.nDefense;
nManDamageMon=man.nAttact-monster[nNowIndex-1].nDefense;

nMonsterLV=monster[nNowIndex-1].nLevel;
nMonsterHP=monster[nNowIndex-1].nHP;
nMonsterA=monster[nNowIndex-1].nAttact;
nMonsterD=monster[nNowIndex-1].nDefense;
if(monster[nNowIndex-1].IsKilled()) monster[nNowIndex-1].bKilled=true;
if(man.IsKilled()) man.bKilled=true;
}

if(man.bKilled)
{
man.bKilled=true;
//bGameOver=true;

bIsMapScreen=false;
bIsEndScreen=true;
}

if(monster[nNowIndex-1].bKilled)
{
sound_KillMon.PlayMySoundOnce();
BitBlt(dc_Map,posManPath[nNowIndex-1].xPos,posManPath[nNowIndex-1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-1]=15;
bIsManPath[nNowIndex-1]=true;
posManPath[nNowIndex-1].bIsMonster=false;
}
nNowIndex-=0;
}
//=======================Check Weapon===================
if(nMapsIndex[nNowIndex-1]==8)
{
man.nDefense+=1;

BitBlt(dc_Map,posManPath[nNowIndex-1].xPos,posManPath[nNowIndex-1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-1]=15;
bIsManPath[nNowIndex-1]=true;

}
if(nMapsIndex[nNowIndex-1]==9)
{
man.nAttact+=5;

BitBlt(dc_Map,posManPath[nNowIndex-1].xPos,posManPath[nNowIndex-1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-1]=15;
bIsManPath[nNowIndex-1]=true;

}
if(nMapsIndex[nNowIndex-1]==10)
{
man.nAttact+=5;
man.nDefense+=4;

BitBlt(dc_Map,posManPath[nNowIndex-1].xPos,posManPath[nNowIndex-1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-1]=15;
bIsManPath[nNowIndex-1]=true;

}
if(nMapsIndex[nNowIndex-1]==11)
{
man.nAttact+=10;
man.nDefense+=10;

BitBlt(dc_Map,posManPath[nNowIndex-1].xPos,posManPath[nNowIndex-1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex-1]=15;
bIsManPath[nNowIndex-1]=true;

}
if(nMapsIndex[nNowIndex-1]==8||nMapsIndex[nNowIndex-1]==9||nMapsIndex[nNowIndex-1]==10||nMapsIndex[nNowIndex-1]==11)
{
nNowIndex-=1;
}
}

nManDir=MAN_L;
}
//================================================Right==============================================================================
if(KEY_DOWN(VK_RIGHT)&&bGoR)
{
nManDamageMon=0,nMonDamageMan=0;
nMonsterLV=0;
nMonsterHP=0;
nMonsterA=0;
nMonsterD=0;
if(man.nPosx<750)
{
if(nMapsIndex[nNowIndex+1]!=0&&nMapsIndex[nNowIndex+1]!=1
&&bIsManPath[nNowIndex+1]&&!posManPath[nNowIndex+1].bIsMonster)//not tiles an not monsters
{

man.SetPosX(posManPath[nNowIndex+1].xPos);
nNowIndex+=1;
bGoR=false;
}

if(posManPath[nNowIndex+1].bIsMonster&&bGoR)//monsters
{
man.SetPosX(posManPath[nNowIndex].xPos);
bGoR=false;

if((false==man.bKilled)&&(false==monster[nNowIndex+1].bKilled))
{

sound_Attack.PlayMySoundOnce();
man.nHP=man.nHP+man.nDefense-monster[nNowIndex+1].nAttact;
monster[nNowIndex+1].nHP=monster[nNowIndex+1].nHP+monster[nNowIndex+1].nDefense-man.nAttact;
nMonDamageMan=monster[nNowIndex+1].nAttact-man.nDefense;
nManDamageMon=man.nAttact-monster[nNowIndex+1].nDefense;
nMonsterLV=monster[nNowIndex+1].nLevel;
nMonsterHP=monster[nNowIndex+1].nHP;
nMonsterA=monster[nNowIndex+1].nAttact;
nMonsterD=monster[nNowIndex+1].nDefense;
if(monster[nNowIndex+1].IsKilled()) monster[nNowIndex+1].bKilled=true;
if(man.IsKilled()) man.bKilled=true;
}

if(man.bKilled)
{
man.bKilled=true;
//bGameOver=true;

bIsMapScreen=false;
bIsEndScreen=true;
}

if(monster[nNowIndex+1].bKilled)
{
sound_KillMon.PlayMySoundOnce();
BitBlt(dc_Map,posManPath[nNowIndex+1].xPos,posManPath[nNowIndex+1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex+1]=15;
bIsManPath[nNowIndex+1]=true;
posManPath[nNowIndex+1].bIsMonster=false;
}

nNowIndex+=0;
}
//=======================Check Weapon===================
if(nMapsIndex[nNowIndex+1]==8)
{
man.nDefense+=1;

BitBlt(dc_Map,posManPath[nNowIndex+1].xPos,posManPath[nNowIndex+1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex+1]=15;
bIsManPath[nNowIndex+1]=true;
}
if(nMapsIndex[nNowIndex+1]==9)
{
man.nAttact+=5;

BitBlt(dc_Map,posManPath[nNowIndex+1].xPos,posManPath[nNowIndex+1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex+1]=15;
bIsManPath[nNowIndex+1]=true;
}
if(nMapsIndex[nNowIndex+1]==10)
{
man.nAttact+=5;
man.nDefense+=4;

BitBlt(dc_Map,posManPath[nNowIndex+1].xPos,posManPath[nNowIndex+1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex+1]=15;
bIsManPath[nNowIndex+1]=true;
}
if(nMapsIndex[nNowIndex+1]==11)
{
man.nAttact+=10;
man.nDefense+=10;

BitBlt(dc_Map,posManPath[nNowIndex+1].xPos,posManPath[nNowIndex+1].yPos,50,50,
bufdc,0,0,BLACKNESS);
nMapsIndex[nNowIndex+1]=15;
bIsManPath[nNowIndex+1]=true;
}
if(nMapsIndex[nNowIndex+1]==8||nMapsIndex[nNowIndex+1]==9||nMapsIndex[nNowIndex+1]==10||nMapsIndex[nNowIndex+1]==11)
{
nNowIndex+=1;
}

}

nManDir=MAN_R;
}
if(KEY_UP(VK_UP))
{
bGoU=true;
}
if(KEY_UP(VK_DOWN))
{
bGoD=true;
}
if(KEY_UP(VK_LEFT))
{
bGoL=true;
}
if(KEY_UP(VK_RIGHT))
{
bGoR=true;
}
//===============Check successed===================
if(nNowIndex==13&&bFlag)
{
bIsSuccessScreen=true;
bIsMapScreen=false;
}
//=================================Show Informations====================

//======================Start screen ' Buttons==========
SelectObject(bufdc,bmpBtnStart);
BitBlt(dc_Start,20,600,100,50,bufdc,100,nBtnStart_y,SRCAND);
BitBlt(dc_Start,20,600,100,50,bufdc,0,nBtnStart_y,SRCPAINT);//Start Button

SelectObject(bufdc,bmpBtnEnd);
BitBlt(dc_Start,150,600,100,50,bufdc,100,nBtnEnd_y,SRCAND);
BitBlt(dc_Start,150,600,100,50,bufdc,0,nBtnEnd_y,SRCPAINT);//End Button

//============ Msps 'active objects================
int x,y;
for(int i=0;i<MAPSNUM;i++)
{
x=(i%16)*50;
y=(i/16)*50;
if(nMapsIndex[i]!=15&&nMapsIndex[i]!=0&&nMapsIndex[i]!=1)
{
SelectObject(bufdc,bmpMaps[nMapsIndex[i]]);
BitBlt(dc_Map,x,y,50,50,bufdc,50,0,SRCAND);
BitBlt(dc_Map,x,y,50,50,bufdc,0,0,SRCPAINT);
}

if(nMapsIndex[i]==15)
bIsManPath[i]=true;
else
bIsManPath[i]=false;

if(nMapsIndex[i]==2||nMapsIndex[i]==3||nMapsIndex[i]==4||nMapsIndex[i]==5
||nMapsIndex[i]==6||nMapsIndex[i]==7)
{
posManPath[i].bIsMonster=true;
}
else
{
posManPath[i].bIsMonster=false;
}

if(nMapsIndex[i]==8||nMapsIndex[i]==9||nMapsIndex[i]==10||nMapsIndex[i]==11)
{
posManPath[i].bIsWeapon=true;
}
else
{
posManPath[i].bIsWeapon=false;
}
//===========================================================

}

//=================Start Screen==========
if(!bStartToMapScroll&&bIsStartScreen)
{
if((bIsBtnS&&!bBtnSHave)||(bIsBtnE&&!bBtnEHave))
{
sound_Btn.PlayMySoundOnce();
bBtnSHave=true;
bBtnEHave=true;
}

BitBlt(mdc,0,0,1000,700,dc_Start,0,0,SRCCOPY);

}
//==================Start To Maps=========
if(bStartToMapScroll&&bIsStartScreen)
{
if(nStartToMap>1000)
{
bStartToMapScroll=false;
bIsStartScreen=false;
bIsMapScreen=true;
}
BitBlt(mdc,0,0,1000-nStartToMap,700,dc_Start,nStartToMap,0,SRCCOPY);//卷页
BitBlt(mdc,1000-nStartToMap,0,nStartToMap,700,dc_Map,0,0,SRCCOPY);
nStartToMap+=1;
}
//==================Map Screen======================
if(bIsMapScreen)
{
sound_MapMusic.PlayMySound();//map screen sound

BitBlt(mdc,0,0,1000,700,dc_Map,0,0,SRCCOPY);
//==================Man==============
x=man.nPosx;
y=man.nPosy;
SelectObject(bufdc,bmpMan);
BitBlt(mdc,x,y,50,50,bufdc,nManDir,50,SRCAND);
BitBlt(mdc,x,y,50,50,bufdc,nManDir,0,SRCPAINT);

//======================Move bullet========================

//bullet x>=500 x<= 750 y>=100 y<=150

SelectObject(bufdc,bmpMaps[13]);
BitBlt(mdc,cxBullet,cyBullet,50,50,bufdc,50,0,SRCAND);
BitBlt(mdc,cxBullet,cyBullet,50,50,bufdc,0,0,SRCPAINT);
cxBullet+=nBulletMove;
if(cxBullet<500||cxBullet>700)
nBulletMove=-nBulletMove;
if(man.nPosy==100)
if(
(man.nPosx<cxBullet && man.nPosx+50>cxBullet)//left
||(man.nPosx>cxBullet && cxBullet+50>man.nPosx)//right
)
{
man.nHP-=5;
//bGameOver=true;
if(man.IsKilled())
{
bIsMapScreen=false;
bIsEndScreen=true;
}
}

SelectObject(bufdc,bmpMaps[13]);
BitBlt(mdc,xBullet,yBullet,50,50,bufdc,50,0,SRCAND);
BitBlt(mdc,xBullet,yBullet,50,50,bufdc,0,0,SRCPAINT);
xBullet+=nBulletMoved;
if(xBullet<350||xBullet>450)
nBulletMoved=-nBulletMoved;
if(man.nPosy==600)
if(
(man.nPosx<xBullet && man.nPosx+50>xBullet)//left
||(man.nPosx>xBullet && xBullet+50>man.nPosx)//right
)
{
man.nHP-=5;
//bGameOver=true;
if(man.IsKilled())
{
bIsMapScreen=false;
bIsEndScreen=true;
}
}
//==============Move Needle========================
if(nNeedleNumd<=800)
bIsNeedle=true;
else
bIsNeedle=false;

nNeedleNumd++;

if(nNeedleNumd>2000)
nNeedleNumd=0;

if(bIsNeedle)
{
SelectObject(bufdc,bmpMaps[12]);
BitBlt(mdc,xNeedle,yNeedle,50,50,bufdc,50,0,SRCAND);
BitBlt(mdc,xNeedle,yNeedle,50,50,bufdc,0,0,SRCPAINT);

if(man.nPosy==650&&man.nPosx==650)
{
man.nHP-=5;
//bGameOver=true;
if(man.IsKilled())
{
bIsMapScreen=false;
bIsEndScreen=true;
}
}
}

if(man.nPosy==150&&man.nPosx==550)
bIsNeedleU=true;
if(bIsNeedleU)
{
SelectObject(bufdc,bmpMaps[12]);
BitBlt(mdc,xNeedleU,yNeedleU,50,50,bufdc,50,0,SRCAND);
BitBlt(mdc,xNeedleU,yNeedleU,50,50,bufdc,0,0,SRCPAINT);
if(man.nPosy==200&&man.nPosx==550)
{
man.nHP-=20;
//bGameOver=true;
if(man.IsKilled())
{
bIsMapScreen=false;
bIsEndScreen=true;
}
}
}

}
//===============End Screen===================================================================
if(bIsEndScreen)
{
//========================end sound======================
sound_MapMusic.Stop();
sound_End.PlayMySoundOnce();
//================================================
BitBlt(mdc,0,0,1000-nMapToEnd,700,dc_Map,nMapToEnd,0,SRCCOPY);//卷页
BitBlt(mdc,1000-nMapToEnd,0,nMapToEnd,700,dc_End,0,0,SRCCOPY);
nMapToEnd+=1;
if(nMapToEnd>1000)
{
bIsEndScreen=false;
}
}
//===============Success Screen============

if(bIsSuccessScreen&&bFlag)
{
//===============success sound==================================================
sound_MapMusic.Stop();
sound_Success.PlayMySoundOnce();
BitBlt(mdc,0,0,1000-nMapToSuccess,700,dc_Map,nMapToSuccess,0,SRCCOPY);//卷页
BitBlt(mdc,1000-nMapToSuccess,0,nMapToSuccess,700,dc_Success,0,0,SRCCOPY);
nMapToSuccess+=1;
if(nMapToSuccess>1000)
{
bIsSuccessScreen=false;
bFlag=false;
}
}
//=====================
BitBlt(hdc,0,0,1000,700,mdc,0,0,SRCCOPY);
}

void Game_ShutDown()
{
for(int i=0;i<15;i++)
DeleteObject(bmpMaps[i]);

DeleteObject(bmpBtnStart);
DeleteObject(bmpBtnEnd);
DeleteObject(bmpStart);
DeleteObject(bmpEnd);
DeleteObject(bmpSuccess);
DeleteObject(bmpMan);

DeleteDC(dc_Start);
DeleteDC(dc_Map);
DeleteDC(dc_End);
DeleteDC(dc_Success);
DeleteDC(mdc);
DeleteDC(bufdc);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  DirectX 游戏 魔塔