#include "..\\Frame\\Frame.h"
#include "vector2.h"
#include"game_input.h"
#include<math.h>
#include<Windows.h>
#include<vector>
#include<time.h>
struct xian
{
Vector2 a ;
Vector2 b ;
Vector2 c ;
Vector2 d ;
Vector2 dira ;
Vector2 dird ;
xian(Vector2 x,Vector2 y):a(x),d(y)
{
b.x = -10 ;
b.y = -10 ;
c.x = -10 ;
c.y = -10 ;
}
};
std::vector<xian> go_ing ;//
Vector2 ballPos(400,300); //小球位置 ---------
Vector2 M_mouse;
Vector2 huax(0,0);
Vector2 dir1 ;
Vector2 dir2 ;
Vector2 t1(-10.0f,-10.0f);
Vector2 t2(-10.0f,-10.0f);
int count = 0 ;
bool fa = false ;
bool cun = false ;
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();
//画线----------------------------
for(std::vector<xian>::iterator it = go_ing.begin();it != go_ing.end() ;it++)
{
(*it).a += (*it).dira ;
(*it).d += (*it).dird ;
//判断头点状态
if((*it).a.x < 0 || (*it).a.x > 800)
{
(*it).dira.x = -(*it).dira.x ;
(*it).c.x = (*it).b.x ;
(*it).c.y = (*it).b.y ;
(*it).a.x < 0 ? ((*it).b.x = 0 ): ((*it).b.x = 800);
(*it).b.y = (*it).a.y ;
}
if((*it).a.y < 0 || (*it).a.y > 600)
{
(*it).dira.y = -(*it).dira.y ;
(*it).c.x = (*it).b.x ;
(*it).c.y = (*it).b.y ;
(*it).b.x = (*it).a.x ;
(*it).b.y = (*it).a.y ;
}
//判断尾点状态
if((*it).d.x < 0 || (*it).d.x > 800)
{
(*it).dird.x = -(*it).dird.x ;
if((*it).c.x > -1)
{
(*it).c.x = -10 ;
}
else
{
if((*it).b.x > -1)
(*it).b.x = -10 ;
}
}
if((*it).d.y < 0 || (*it).d.y > 600)
{
(*it).dird.y = -(*it).dird.y ;
if((*it).c.x > -1)
{
(*it).c.x = -10 ;
}
else
{
if((*it).b.x > -1)
(*it).b.x = -10 ;
}
}
//画出每条线------------------------------
if((*it).b.x > -1)
{
out->DrawLine((*it).b.x,(*it).b.y, (*it).a.x , (*it).a.y ,0xffda) ;
if((*it).c.x > -1)
{
out->DrawLine((*it).c.x,(*it).c.y, (*it).b.x, (*it).b.y ,0xff00) ;
out->DrawLine((*it).d.x,(*it).d.y,(*it).c.x, (*it).c.y ,0xff00) ;
}
else
{
out->DrawLine((*it).d.x,(*it).d.y, (*it).b.x, (*it).b.y ,0xbb11ff) ;
}
}
else
out->DrawLine((*it).d.x,(*it).d.y, (*it).a.x,(*it).a.y ,0xff0000);
}
int px ,py ;
in->GetCursor(&px,&py);
Vector2 mousePos(px,py);
Vector2 paoguan = mousePos - ballPos ;
Vector2 biao = paoguan.Normalize()*10 ;
if((in->GetKeyState(VK_LBUTTON) == _KS_CU)&&fa == false )
{
fa = true ;
huax = ballPos ;
dir1 =biao ;
dir2 =biao ;
}
if(fa)
{
count ++ ;
if(count < 20)
{
huax += dir1 ;
if(huax.x < 0 || huax.x > 800)
{
dir1.x = -dir1.x ;
t2.x = t1.x ;
t2.y = t1.y ;
t1.x = huax.x ;
t1.y = huax.y ;
}
if(huax.y < 0 || huax.y > 600)
{
dir1.y = -dir1.y ;
t2.x = t1.x ;
t2.y = t1.y ;
t1.x = huax.x ;
t1.y = huax.y ;
}
}
else
{
xian abc(huax,ballPos);
abc.dira = dir1 ;
abc.dird = dir2 ;
abc.b = t1 ;
abc.c = t2 ;
go_ing.push_back(abc);
count = 0 ;
huax.x = ballPos.x ;
huax.y = ballPos.y ;
fa = false ;
t1.x = -10 ;
t2.x = -10 ;
}
if(t1.x > -1)
{
out->DrawLine(t1.x,t1.y, huax.x , huax.y ,0xbb11ff) ;
if(t2.x > -1)
{
out->DrawLine(t2.x,t2.y, t1.x, t1.y ,0xbb11ff) ;
out->DrawLine(ballPos.x,ballPos.y,t2.x, t2.y ,0xbb11ff) ;
}
else
{
out->DrawLine(ballPos.x,ballPos.y, t1.x, t1.y ,0xbb11ff) ;
}
}
else
out->DrawLine(ballPos.x,ballPos.y, huax.x,huax.y ,0xbb11ff);
}
else
out->DrawLine(ballPos.x,ballPos.y,ballPos.x + 5*biao.x,ballPos.y + 5*biao.y ,0xbb11ff) ;
//绘制发射点
out->DrawEllipse(ballPos.x -20,ballPos.y-20 ,ballPos.x +20,ballPos.y+20 ,0xffff00,0xbb11ff);
//移动发射点---------------------
if(!fa)
{
if((GetAsyncKeyState('W') & 0x8000) && ballPos.y > 0)ballPos.y -= 5 ;
else if((GetAsyncKeyState('S') & 0x8000) && ballPos.y < 600)ballPos.y += 5 ;
else if((GetAsyncKeyState('A') & 0x8000) && ballPos.x > 0)ballPos.x -= 5 ;
else if((GetAsyncKeyState('D') & 0x8000) && ballPos.x < 800)ballPos.x += 5 ;
}
//退出游戏
if (in->GetKeyState(VK_ESCAPE) == _KS_CU)
frame->GameExit();
}
void GameEnd()
{
}
win32 框架 射线输出
最新推荐文章于 2025-07-30 13:50:13 发布