win32框架黄金矿工

#include "..\\Frame\\Frame.h"
#include "vector2.h"
#include"game_input.h"
#include<math.h>
#include<Windows.h>
#include<vector>
#include<time.h>

bool _go = false ;//抓取状态
bool had = false ;//有小球
bool _b = true ;
bool peng = false ;
bool zhuaball = false ;
int count = 0;
Vector2 ballPos;//小球位置
Vector2 P_zhua(400,0);
Vector2 K_zhua(400,60);
Vector2 GOing ;
int a = 0 ;
double fudu = 3.1415926/60 ;
double jiaodu = 0 ;
void GameInit()
{
	GameFrame* frame = GameFrame::GetFrame();
	CGameAudio* audio = frame->GetAudio();
}

void GameRun()
{
	GameFrame* frame = GameFrame::GetFrame();
	CGameOutput* out = frame->GetOutput();
	CGameInput* in = frame->GetInput();
	CGameAudio* audio = frame->GetAudio();
	//添加背景
	out->DrawBmp1("asdf.bmp",0,0,800,600,0,0); 


	//画小球----------------------------
	//for(std::vector<NDAN>::iterator it = chuan.begin();it != chuan.end() ;)
	//{
	//	if((*it).dir.x > 800 || (*it).dir.y > 600 || (*it).dir.y < 0)
	//	{
	//		it = chuan.erase(it);
	//	}
	//	else
	//	{
	//		
	//		out->DrawEllipse((*it).dir.x - 10,(*it).dir.y - 10,(*it).dir.x + 10,(*it).dir.y + 10,0xff,0xff);
	//		(*it).dir += (*it).speed*5 ;
	//		(*it).speed.y ++ ;
	//		//(*it).t_time += 1 ;
	//		it++ ;
	//	}
	//	
	//	
	//}


	//随机产生一个小球--------------------------
	srand((unsigned int)time(0));
	if(!had)
	{
		a = ((rand()%4)+2 ) * 10;
		ballPos.x = (rand()%700) + 50 ;
		ballPos.y = (rand()%500) + 50 ;
		had = true ;
	}


	//爪子变换方向----------------------------
	if(!_go)
	{
		jiaodu = fudu * count;
		K_zhua.x = 400 - 30*cos(jiaodu);
		K_zhua.y = 0  + 60*sin(jiaodu) ;
		if(_b)
		{
			count++ ;
			if(count == 60)
				_b = !_b ;
		}
		else 
		{
			count-- ;
			if(count == 0)
				_b = ! _b ;
		}
		
	}
	if (in->GetKeyState(' ') == _KS_CD)
	{
 		_go = true ;
	}

	//计算爪子方向向量----------------------
	Vector2 GO_zhua = K_zhua - P_zhua ;
	//鸟蛋起始坐标---------------------------
	GO_zhua = GO_zhua.Normalize()*60 ;


	if(_go)
	{
		Vector2 H = K_zhua - P_zhua ;
		double xx = H.x +400 ;
		double xy = H.y ;
		if(!peng )  //没有碰撞小球伸长 或者 没有碰撞边界
			GOing += H.Normalize()*10 ;
		else
		{
			GOing -= H.Normalize()*10 ;
			if(zhuaball)
				ballPos -= H.Normalize()*10 ;
			if(GOing.y < 10)
			{
				if(zhuaball)
				{
					had = false ;	
					zhuaball = false ;
				}			
				peng = false ;
				_go = false ;
			}
		}
		out->DrawLine(400,0,400+GOing.x, GOing.y,0xff00ff);
		xx = 400+GOing.x ;
		xy = GOing.y ;
		if(xx < 0 || xx > 800 || xy > 600)
			peng = true ;
		double r = sqrt((xx - ballPos.x)*(xx - ballPos.x) + (xy - ballPos.y)*(xy - ballPos.y)) ;
		if( r < a && GOing.y > 30)
		{
			ballPos.x = xx ;
			ballPos.y = xy ;
			peng = true ;
			zhuaball = true ;
		}
	}
	else
	{
		out->DrawLine(400,0,400+GO_zhua.x, GO_zhua.y,0xff00ff);
		
	}

	out->DrawEllipse(ballPos.x -a,ballPos.y-a ,ballPos.x +a,ballPos.y+a ,0xff00ff,0xffffff);
	//炮台-----------------
	out->DrawEllipse(P_zhua.x -40,P_zhua.y-40 ,P_zhua.x +40,P_zhua.y+40 ,0xff0000,0xffaaff);



	//鼠标点击时添加抛出鸟蛋------------------
	//if (in->GetKeyState(VK_LBUTTON) == _KS_CD)
	//{ 		
		//Vector2 mousePos(px,py);//鼠标位置
		//mouseClickPos = mousePos;//记录鼠标点击的位置
		//Vector2 dir = mousePos - niao;//小球到鼠标的方向
		//NDAN d ;
		//d.dir.x =T.x ;
		//d.dir.y =T.y+600 ;
		//d.speed = dir/60 ;
		//chuan.push_back(d);		
	//}

	//爪子发射点---------------------
	



	//退出游戏
	if (in->GetKeyState(VK_ESCAPE) == _KS_CU)
		frame->GameExit();
}

void GameEnd()
{

}




 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值