ObjectHit.cpp
资源名称:LwGame2.0.rar [点击查看]
上传用户:semy2100
上传日期:2013-01-22
资源大小:3633k
文件大小:4k
源码类别:
射击游戏
开发平台:
Visual C++
- /********************************************************************
- * 空运爆发 *
- * Version 2.0 *
- * 本游戏全部代码由: *
- * 冲天实验室 梁锋 编写 *
- * 邮箱:lenwine@126.com *
- * bbs: http://free2.e-168.cn/lenwind (正在开发中...) *
- **********************************************************************/
- ////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "MusicPlace.h"
- ////////////////////////////////////////////////////
- int ObjectHit::i=0;
- ObjectHit::ObjectHit(Manager *mgr)
- {
- oPeratorPlace=mgr->oPeratorPlace;
- oPeratorPlace2=mgr->oPeratorPlace2;
- oEnermyPlace=mgr->oEnermyPlace;
- oPeratorbomb=mgr->oPeratorbomb;
- oEnermybomb=mgr->oEnermybomb;
- //==================================================
- _getcwd( muspath, sizeof(muspath));
- strcpy(bplay, "play ");
- strcat(bplay, muspath);
- strcat(bplay, "\cs.wav");
- strcpy(bclose, "close ");
- strcat(bclose, muspath);
- strcat(bclose, "\cs.wav");
- //==================================================
- }
- ObjectHit::~ObjectHit()
- {
- }
- void ObjectHit::Update()
- {
- Brock *bBrock;
- Bomb *bBomb;
- bBrock=oEnermyPlace->GetOneBrock();
- while(bBrock)
- {
- //检查敌机与操作者的碰撞
- WatchHit(oPeratorPlace,bBrock);
- WatchHit(oPeratorPlace2,bBrock);
- bBomb=oPeratorbomb->GetOneBomb();
- while(bBomb)
- {
- WatchHit(bBrock,bBomb);
- bBomb=oPeratorbomb->GetTwoBomb();
- }
- bBrock=oEnermyPlace->GetTwoBrock();
- }
- bBomb=oEnermybomb->GetOneBomb();
- while(bBomb)
- {
- WatchHit(oPeratorPlace,bBomb);
- WatchHit(oPeratorPlace2,bBomb);
- bBomb=oEnermybomb->GetTwoBomb();
- }
- }
- //检查敌机的子弹与操作者的子弹是否有碰撞
- void ObjectHit::WatchHit(Brock *lpBrockPlace,Bomb *bBomb)
- {
- if(lpBrockPlace->alive<=0 || bBomb->alive<=0)return;
- if(lpBrockPlace->GetX()+lpBrockPlace->rx+lpBrockPlace->rlong>bBomb->GetX()+bBomb->rx &&
- lpBrockPlace->GetY()+lpBrockPlace->ry+lpBrockPlace->rtall>bBomb->GetY()+bBomb->rtall &&
- lpBrockPlace->GetX()+lpBrockPlace->rx<bBomb->GetX()+bBomb->rx+bBomb->rlong &&
- lpBrockPlace->GetY()+lpBrockPlace->ry<bBomb->GetY()+bBomb->ry+bBomb->rtall)
- {
- char buf[256];
- lpBrockPlace->alive-=bBomb->shootpower;
- bBomb->alive=0;
- oPeratorPlace->result+=lpBrockPlace->alive;
- if(lpBrockPlace->alive<=0)
- {
- oPeratorPlace->decedent++;
- }
- mciSendString(bplay, buf, sizeof(buf), NULL);
- }
- }
- //碰撞检测:操作者与敌方子弹
- void ObjectHit::WatchHit(OperatorPlace *lpOperatorPlace,Bomb *bBomb)
- {
- if(lpOperatorPlace->alive<=0 || bBomb->alive<=0)return;
- if(lpOperatorPlace->GetX()+lpOperatorPlace->rx+lpOperatorPlace->rlong>bBomb->GetX()+bBomb->rx &&
- lpOperatorPlace->GetY()+lpOperatorPlace->ry+lpOperatorPlace->rtall>bBomb->GetY()+bBomb->rtall &&
- lpOperatorPlace->GetX()+lpOperatorPlace->rx<bBomb->GetX()+bBomb->rx+bBomb->rlong &&
- lpOperatorPlace->GetY()+lpOperatorPlace->ry<bBomb->GetY()+bBomb->ry+bBomb->rtall)
- {
- char buf[256];
- lpOperatorPlace->alive-=bBomb->shootpower;
- bBomb->alive=0;
- mciSendString(bplay, buf, sizeof(buf), NULL);
- }
- }
- //碰撞检测:操作者与敌机
- void ObjectHit::WatchHit(OperatorPlace *oPeratorPlace,Brock *bBrock)
- {
- if(oPeratorPlace->alive<=0||bBrock->alive<=0)return;
- if(oPeratorPlace->GetX()+oPeratorPlace->rx+oPeratorPlace->rlong > bBrock->GetX()+bBrock->rx &&
- oPeratorPlace->GetY()+oPeratorPlace->ry+oPeratorPlace->rtall > bBrock->GetY()+bBrock->rtall &&
- oPeratorPlace->GetX()+oPeratorPlace->rx < bBrock->GetX()+bBrock->rx+bBrock->rlong &&
- oPeratorPlace->GetY()+oPeratorPlace->ry < bBrock->GetY()+bBrock->ry+bBrock->rtall)
- {
- char buf[256];
- oPeratorPlace->alive-=5;
- oPeratorPlace->decedent++;
- oPeratorPlace->result+=bBrock->alive;
- /* 如果碰撞了敌人活率减小*/
- bBrock->alive=0;
- mciSendString(bplay, buf, sizeof(buf), NULL);
- }
- }