⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gun.cpp

📁 小蜜蜂射击游戏,画面精彩,声音也不错
💻 CPP
字号:
// gun.cpp: implementation of the gun class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "bee.h"
#include "gun.h"


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

gun::gun()
{
x1=120,y1=0;
x2=140,y1=40;
x3=160,y1=0;
status=5;
}

gun::~gun()
{

}

void gun::move(int direct,screen* pscreen)
{
	int moved;
	if((x2>=pscreen->maxx&&direct==1)||(x2<=0&&direct==-1)){
	moved=0;
	}else{
	moved=1;
	}

	x1=x1+5*direct*moved;
	x2=x2+5*direct*moved;
	x3=x3+5*direct*moved;
}

void gun::shot()
{

}

//DEL void gun::showme(screen gamescreen)
//DEL {
//DEL 
//DEL }

void gun::paint(CDC *pdc,screen* pscreen)
{
	if(status>0){
	CPoint gun[4];
	CBrush BrRed(RGB(255,0,0));
	CBrush *pOldBrush=NULL;
	pOldBrush=pdc->SelectObject(&BrRed);
	gun[0].x=pscreen->transitx(x1);
	gun[0].y=pscreen->transity(y1);
	gun[1].x=pscreen->transitx(x2);
	gun[1].y=pscreen->transity(y2);
	gun[2].x=pscreen->transitx(x3);
	gun[2].y=pscreen->transity(y3);
	gun[3].x=pscreen->transitx(x1);
	gun[3].y=pscreen->transity(y1);
	pdc->Polygon(gun,4);
	pdc->SelectObject(pOldBrush);
	}

}

gun::gun(int cx1, int cy1,int cx2,int cy2,int cx3,int cy3)
{
x1=cx1,y1=cy1,x2=cx2,y2=cy2,x3=cx3,y3=cy3;
status=5;
}

void gun::shape(int cx1, int cy1,int cx2,int cy2,int cx3,int cy3)
{
x1=120,y1=0;
x2=140,y1=40;
x3=160,y1=0;
status=5;
}

void gun::getpos(int *x, int *y)
{
*x=x2,*y=y2;
}

bool gun::isInMe(int cx,int cy)
{

    float lx1,lx2,lx3;
	if((y2-y1)!=0)
		lx1=(float)(x2-x1)/(float)(y2-y1)*(cy-y1)+x1;     //(lx1,cy)
    else lx1=-10000;
	if((y3-y2)!=0)
		lx2=(float)(x3-x2)/(float)(y3-y2)*(cy-y2)+x2;    //(lx2,cy)
	else lx2=-10000;
	if((y3-y1)!=0)
		lx3=(float)(x3-x1)/(float)(y3-y1)*(cy-y1)+x1;     //(lx3,cy)
    else lx3=-10000;
	
	if((lx1-x1)*(lx1-x2)<=0)lx1=lx1;else lx1=-10000;
    if((lx2-x3)*(lx2-x2)<=0)lx2=lx2;else lx2=-10000;
    if((lx3-x3)*(lx3-x1)<=0)lx3=lx3;else lx3=-10000;
	if((lx1-cx)*(lx2-cx)*(lx3-cx)>=0){return true;}
	else {return false;}
}

void gun::init()
{
x1=120,y1=0;
x2=140,y1=40;
x3=160,y1=0;
status=5;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -