dirtprojectile.cpp
来自「这是整套横扫千军3D版游戏的源码」· C++ 代码 · 共 100 行
CPP
100 行
#include "StdAfx.h"
// DirtProjectile.cpp: implementation of the CDirtCloudProjectile class.
//
//////////////////////////////////////////////////////////////////////
#include "DirtProjectile.h"
#include "Game/Camera.h"
#include "Map/Ground.h"
#include "Rendering/GL/VertexArray.h"
#include "Sim/Projectiles/ProjectileHandler.h"
#include "mmgr.h"
CR_BIND_DERIVED(CDirtProjectile, CProjectile, );
CR_REG_METADATA(CDirtProjectile,
(
CR_MEMBER_BEGINFLAG(CM_Config),
CR_MEMBER(alpha),
CR_MEMBER(alphaFalloff),
CR_MEMBER(size),
CR_MEMBER(sizeExpansion),
CR_MEMBER(slowdown),
CR_MEMBER(color),
CR_MEMBER(texture),
CR_MEMBER_ENDFLAG(CM_Config),
CR_RESERVED(8)
));
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CDirtProjectile::CDirtProjectile(const float3 pos,const float3 speed,const float ttl,const float size,const float expansion,float slowdown,CUnit* owner,const float3& color)
: CProjectile(pos,speed,owner, false),
alpha(255),
size(size),
sizeExpansion(expansion),
slowdown(slowdown),
color(color)
{
checkCol=false;
alphaFalloff=255/ttl;
texture = &ph->randdotstex;
}
CDirtProjectile::CDirtProjectile() :
alpha(255.0f),
size(10.0f),
sizeExpansion(0.0f),
slowdown(1.0f),
alphaFalloff(10.0f)
{
checkCol=false;
synced=false;
texture = &ph->randdotstex;
}
CDirtProjectile::~CDirtProjectile()
{}
void CDirtProjectile::Update()
{
speed*=slowdown;
speed.y+=gs->gravity;
pos+=speed;
alpha-=alphaFalloff;
size+=sizeExpansion;
if(ground->GetApproximateHeight(pos.x,pos.z)-40>pos.y){
deleteMe=true;
}
if(alpha<=0){
deleteMe=true;
alpha=0;
}
}
void CDirtProjectile::Draw()
{
float partAbove=(pos.y/(size*camera->up.y));
if(partAbove<-1)
return;
else if(partAbove>1)
partAbove=1;
inArray=true;
unsigned char col[4];
col[0]=(unsigned char) (color.x*alpha);
col[1]=(unsigned char) (color.y*alpha);
col[2]=(unsigned char) (color.z*alpha);
col[3]=(unsigned char) (alpha)/*-gu->timeOffset*alphaFalloff*/;
float3 interPos=pos+speed*gu->timeOffset;
float interSize=size+gu->timeOffset*sizeExpansion;
float texx = texture->xstart + (texture->xend-texture->xstart)*((1-partAbove)*0.5f);//0.25f*(1-partAbove)
va->AddVertexTC(interPos-camera->right*interSize-camera->up*interSize*partAbove,texx,texture->ystart,col);
va->AddVertexTC(interPos+camera->right*interSize-camera->up*interSize*partAbove,texx,texture->yend,col);
va->AddVertexTC(interPos+camera->right*interSize+camera->up*interSize,texture->xend,texture->yend,col);
va->AddVertexTC(interPos-camera->right*interSize+camera->up*interSize,texture->xend,texture->ystart,col);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?