Manager.cpp
资源名称:LwGame2.0.rar [点击查看]
上传用户:semy2100
上传日期:2013-01-22
资源大小:3633k
文件大小:10k
源码类别:
射击游戏
开发平台:
Visual C++
- /********************************************************************
- * 空运爆发 *
- * Version 2.0 *
- * 本游戏全部代码由: *
- * 冲天实验室 梁锋 编写 *
- * 邮箱:lenwine@126.com *
- * bbs: http://free2.e-168.cn/lenwind (正在开发中...) *
- **********************************************************************/
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- const int Manager::Imglong=::GetSystemMetrics(SM_CXSCREEN);
- const int Manager::Imgtall=::GetSystemMetrics(SM_CYSCREEN);
- const int Manager::printtime=20;
- const double Manager::PI=3.1415926535897932;
- //////////////////////////////////////////////////////////////////////
- Manager::Manager(HWND mhwnd):MgrFace(mhwnd)
- {
- Time=GetTickCount();//毫秒
- ZeroMemory(&st,sizeof(st));
- st.EndTime=Time;
- ts=1.0;
- srand(time(0));
- OneKey=0;
- TwoKey=0;
- flat=1;
- flat2=1;
- oWindow=new OutScreen(this);
- oPeratorPlace=new OperatorPlace(this,Imglong/2-100,Imgtall-50,0);
- oPeratorPlace2=new OperatorPlace(this,Imglong/2+100,Imgtall-50,1);
- oPeratorbomb=new BombSet(this);
- oEnermybomb=new BombSet(this);
- oEnermyPlace=new EnermyPlace(this);
- oHit=new ObjectHit(this);
- oWindow->beginsp();
- //初始化DirectSound对象
- if(!InitializeDirectSound(MgrFace))
- {
- ::MessageBox(MgrFace,"Error!",NULL,MB_OK);
- }
- //创建声音缓冲区
- m_lPlay=new MusicPlace("disco.wav",TRUE,m_lpDS);
- ms_play=new MusicPlace("mpy.wav",TRUE,m_lpDS);//旋风音
- co_play=new MusicPlace("co.wav",TRUE,m_lpDS);
- cs_play=new MusicPlace("bom.wav",TRUE,m_lpDS);
- //播放背景音乐
- m_lPlay->ActionPlay();
- }
- Manager::~Manager()
- {
- ClearDSBuffer();
- delete oWindow;
- }
- //刷新游戏
- void Manager::Update()
- {
- int t=GetTickCount();
- //=============================================
- /** if(bActive)
- {
- //计算帧频率
- static int frame=0, nt, ot=0;
- nt=t;
- if (nt > ot+1000)
- {
- ot=nt;
- fps=frame;
- frame=0;
- }
- //画面延时
- static int NewCount, OldCount=0;
- NewCount=GetTickCount();
- if (NewCount > OldCount+speed)
- {
- frame++;
- OldCount=NewCount;
- UpdateFrame();//更新画面
- }
- }**/
- //=============================================
- if(t-Time<printtime)
- return;
- Time=t;
- //难度增加
- if(oPeratorPlace->result>=flat*200)
- {
- oEnermyPlace->AddStress();
- flat++;
- }
- switch(oPeratorPlace->bombStyle)
- {
- case 0:
- i=0;
- break;
- case 1:
- i=1;
- break;
- case 2:
- i=2;
- break;
- default:
- break;
- }
- oWindow->Refresh();//清屏
- oHit->Update();
- oEnermybomb->Update();
- oPeratorbomb->Update();
- oEnermyPlace->Update();
- oPeratorPlace->Update();
- oPeratorPlace2->Update2();
- //oWindow->paintsp();
- Updatest();
- OutStatus();
- oWindow->PmOutPut();//将所有角色输出
- }
- void Manager::Updatest()
- {
- st.ObjectValue++;
- if(Time-st.EndTime>=1000)
- {
- st.st=st.ObjectValue;
- st.ObjectValue=0;
- st.EndTime=Time;
- ts=(double)1000/(printtime*st.st);
- }
- }
- //显示信息
- void Manager::OutStatus()//在客户区TOP上列出所有信息
- {
- HDC hdc=oWindow->GetCloseDDC();
- ostringstream message;
- message<<"红蓝活: "<<oPeratorPlace->alive;
- message<<" 红蓝敌: "<<oPeratorPlace->decedent<<" 红蓝分 "<<oPeratorPlace->result;
- message<<" 红蓝级 "<<flat;
- message<<"<<空运爆发>>";
- SetBkMode(hdc,TRANSPARENT);
- SetTextColor(hdc,RGB(130,100,10));
- TextOut(hdc, 5, Imgtall-20, message.str().c_str(), message.str().length());
- }
- void Manager::EnermyShoot(Brock *bBrock)//敌方发射
- {
- oEnermybomb->Firing(bBrock->bombStyle,
- bBrock->GetX()+bBrock->Bitlong/2,
- bBrock->GetY()+bBrock->Bittall/2,
- bBrock->spx,bBrock->spy);
- }
- void Manager::OperatorShoot(OperatorPlace *oPeratorPlace,int rb)//我方发射
- {
- oPeratorbomb->Firing(oPeratorPlace->bombStyle,
- oPeratorPlace->GetX()+oPeratorPlace->Bitlong/2,
- oPeratorPlace->GetY()+oPeratorPlace->Bittall/2,
- oPeratorPlace->spx,oPeratorPlace->spy);
- }
- void Manager::OperatorShoot2(OperatorPlace *oPeratorPlace2,int rb)//我方发射
- {
- oPeratorbomb->Firing(oPeratorPlace2->bombStyle,
- oPeratorPlace2->GetX()+oPeratorPlace2->Bitlong/2,
- oPeratorPlace2->GetY()+oPeratorPlace2->Bittall/2,
- oPeratorPlace2->spx,oPeratorPlace2->spy);
- }
- void Manager::PrintMember(MemberStatus *mStatus)//输出所有成员
- {
- oWindow->PaintOutPut(mStatus->GetX(),
- mStatus->GetY(),
- mStatus->Bitlong,
- mStatus->Bittall,
- mStatus->bx,
- mStatus->by,false);
- }
- void Manager::KeyDown(WPARAM KeyCode)//定义上、下、左、右 双键方向
- {
- switch(KeyCode)
- {
- case VK_LEFT:
- // oWindow->rightsp();//背景向右走
- case VK_RIGHT:
- // oWindow->leftsp();//背景向左走
- case VK_UP:
- // oWindow->downsp();//背景向下走
- case VK_DOWN:
- if(KeyCode==TwoKey||KeyCode==OneKey)return;
- if(OneKey && TwoKey)return;
- OneKey=TwoKey;
- TwoKey=KeyCode;
- /** 判断双键按下的操作 **/
- if((OneKey==VK_LEFT && TwoKey==VK_UP)||(OneKey==VK_UP && TwoKey==VK_LEFT))
- oPeratorPlace->Start(OperatorPlace::MOVLU);
- else if((OneKey==VK_LEFT && TwoKey==VK_DOWN)||(OneKey==VK_DOWN && TwoKey==VK_LEFT))
- oPeratorPlace->Start(OperatorPlace::MOVLD);
- else if((OneKey==VK_RIGHT && TwoKey==VK_UP)||(OneKey==VK_UP && TwoKey==VK_RIGHT))
- oPeratorPlace->Start(OperatorPlace::MOVRU);
- else if((OneKey==VK_RIGHT && TwoKey==VK_DOWN)||(OneKey==VK_DOWN && TwoKey==VK_RIGHT))
- oPeratorPlace->Start(OperatorPlace::MOVRD);
- else
- oPeratorPlace->Start((OperatorPlace::START)(OperatorPlace::MOVL+KeyCode-VK_LEFT));
- break;
- case 65:
- case 68:
- case 87:
- case 83:
- if(KeyCode==TwoKey||KeyCode==OneKey)return;
- if(OneKey && TwoKey)return;
- OneKey=TwoKey;
- TwoKey=KeyCode;
- /** 判断双键按下的操作 **/
- if((OneKey==65 && TwoKey==87)||(OneKey==87 && TwoKey==65))
- oPeratorPlace2->Start2(OperatorPlace::MOVLU);
- else if((OneKey==65 && TwoKey==83)||(OneKey==83 && TwoKey==65))
- oPeratorPlace2->Start2(OperatorPlace::MOVLD);
- else if((OneKey==68 && TwoKey==87)||(OneKey==87 && TwoKey==68))
- oPeratorPlace2->Start2(OperatorPlace::MOVRU);
- else if((OneKey==68 && TwoKey==83)||(OneKey==83 && TwoKey==68))
- oPeratorPlace2->Start2(OperatorPlace::MOVRD);
- else
- {
- oPeratorPlace2->Start2((OperatorPlace::START)(OperatorPlace::MOVL+KeyCode-65));
- oPeratorPlace2->Start2((OperatorPlace::START)(OperatorPlace::MOVR+KeyCode-68));
- oPeratorPlace2->Start2((OperatorPlace::START)(OperatorPlace::MOVD+KeyCode-83));
- oPeratorPlace2->Start2((OperatorPlace::START)(OperatorPlace::MOVU+KeyCode-87));
- }
- break;
- case 85:
- oPeratorPlace2->Start2(OperatorPlace::BEGINSHOOT);
- switch(i)
- {
- case 0:
- cs_play->ActionPlay();
- break;
- case 1:
- ms_play->ActionPlay();
- break;
- case 2:
- co_play->ActionPlay();
- break;
- }
- break;
- case 79:
- oPeratorPlace2->Start2(OperatorPlace::HOLDWEA);
- break;
- case VK_SPACE:
- oPeratorPlace->Start(OperatorPlace::BEGINSHOOT);
- /*射击时采用不用种类的弹,发出不用种类的声音*/
- switch(i)
- {
- case 0:
- cs_play->ActionPlay();
- break;
- case 1:
- ms_play->ActionPlay();
- break;
- case 2:
- co_play->ActionPlay();
- break;
- }
- /** if(!bmus)
- {
- co_play->ActionPlay();
- cs_play->ActionStop();
- ms_play->ActionStop();
- }
- else if(bmus)
- {
- cs_play->ActionPlay();
- co_play->ActionStop();
- ms_play->ActionStop();
- }else
- {
- cs_play->ActionStop();
- co_play->ActionStop();
- ms_play->ActionPlay();
- }**/
- break;
- case VK_CONTROL:
- oPeratorPlace->Start(OperatorPlace::HOLDWEA);
- break;
- case VK_DELETE:
- case VK_ESCAPE:
- DestroyWindow(MgrFace);
- break;
- }
- }
- void Manager::KeyUp(WPARAM KeyCode)//释放
- {
- if(KeyCode==TwoKey)
- {
- TwoKey=0;
- if(OneKey)
- {
- TwoKey=OneKey;
- OneKey=0;
- oPeratorPlace->Start((OperatorPlace::START)(TwoKey-VK_LEFT));
- oPeratorPlace2->Start2((OperatorPlace::START)(TwoKey-65));
- }
- else
- {
- oPeratorPlace->Start(OperatorPlace::STOPMOV);
- oPeratorPlace2->Start2(OperatorPlace::STOPMOV);
- }
- }
- else if(KeyCode==OneKey)
- OneKey=0;
- else if(KeyCode==VK_SPACE)
- oPeratorPlace->Start(OperatorPlace::STOPSHOOT);
- else if(KeyCode==85)
- oPeratorPlace2->Start2(OperatorPlace::STOPSHOOT);
- }
- void Manager::RefreshScreen()//我方控制机重设回到客户区中间底部
- {
- delete oPeratorPlace;
- oPeratorPlace=new OperatorPlace(this,Imglong/2-50,Imgtall-50,0);
- flat=1;
- oEnermyPlace->RefreshStress();
- }
- void Manager::RefreshScreen2()
- {
- delete oPeratorPlace2;
- flat2=1;
- oPeratorPlace2=new OperatorPlace(this,Imglong/2+50,Imgtall-50,1);
- oEnermyPlace->RefreshStress();
- }
- BOOL Manager::InitializeDirectSound(HWND hwnd)
- {
- //创建背景音乐和音效DriectSound对象
- if(DS_OK!=DirectSoundCreate(NULL,&m_lpDS,NULL))
- {
- ::MessageBox(NULL,"创建DirectSound对象失败n找不到可利用的声音设备",NULL,MB_OK);
- return FALSE;
- }
- //设置协作级别
- if(DS_OK!=m_lpDS->SetCooperativeLevel(hwnd,DSSCL_NORMAL))
- {
- ::MessageBox(NULL,"设置协作级别失败",NULL,MB_OK);
- return FALSE;
- }
- return TRUE;
- }
- void Manager::ClearDSBuffer()
- {
- m_lPlay->ActionStop();
- ms_play->ActionStop();
- cs_play->ActionStop();
- co_play->ActionStop();
- if(m_lPlay)
- {
- delete m_lPlay;
- }
- if(ms_play)
- {
- delete ms_play;
- }
- if(co_play)
- {
- delete co_play;
- }
- if(cs_play)
- {
- delete cs_play;
- }
- }
- void Manager::playcs()
- {
- ms_play->ActionPlay();
- }