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

📄 projectile.cpp

📁 这是整套横扫千军3D版游戏的源码
💻 CPP
字号:
#include "StdAfx.h"
// Projectile.cpp: implementation of the CProjectile class.
//
//////////////////////////////////////////////////////////////////////

#include "Rendering/GL/myGL.h"			// Header File For The OpenGL32 Library
#include "Projectile.h"
#include "ProjectileHandler.h"
#include "Game/Camera.h"
#include "Rendering/GL/VertexArray.h"
#include "Sim/Units/Unit.h"
#include "LogOutput.h"
#include "Rendering/UnitModels/3DModelParser.h"
#include "mmgr.h"

CR_BIND_DERIVED(CProjectile, CExpGenSpawnable, );

CR_REG_METADATA(CProjectile,
(
	CR_MEMBER(checkCol),
	CR_MEMBER(castShadow),
	CR_MEMBER(owner),
	CR_MEMBER(synced),

	CR_MEMBER_BEGINFLAG(CM_Config),
		CR_MEMBER(speed),
	CR_MEMBER_ENDFLAG(CM_Config),
	CR_RESERVED(8)
));

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
bool CProjectile::inArray=false;
CVertexArray* CProjectile::va=0;

CProjectile::CProjectile()
:	owner(0),
	checkCol(true),
	deleteMe(false),
	castShadow(false),
	s3domodel(0),
	collisionFlags(0)
{}

void CProjectile::Init (const float3& explosionPos, CUnit *owner)
{
	pos += explosionPos;
	SetRadius(1.7f);
	ph->AddProjectile(this);
	if(owner)
		AddDeathDependence(owner);
}

CProjectile::CProjectile(const float3& pos,const float3& speed,CUnit* owner, bool synced)
:	CExpGenSpawnable(pos),
	owner(owner),
	speed(speed),
	checkCol(true),
	deleteMe(false),
	castShadow(false),
	s3domodel(0),
	collisionFlags(0),
	synced(synced)
{
	SetRadius(1.7f);
	ph->AddProjectile(this);
	if(owner)
		AddDeathDependence(owner);
}

CProjectile::~CProjectile()
{
//	if(owner)
//		DeleteDeathDependence(owner);
}

void CProjectile::Update()
{
	speed.y+=gs->gravity;

	pos+=speed;
}

void CProjectile::Collision()
{
	deleteMe=true;
	checkCol=false;
	pos.y=MAX_WORLD_SIZE;
}

void CProjectile::Collision(CUnit *unit)
{
	deleteMe=true;
	checkCol=false;
	pos.y=MAX_WORLD_SIZE;
}

void CProjectile::Collision(CFeature* feature)
{
	Collision();
}

void CProjectile::Draw()
{
	inArray=true;
	unsigned char col[4];
	col[0]=1*255;
	col[1]=(unsigned char) (0.5f*255);
	col[2]=0*255;
	col[3]=10;
	float3 interPos=pos+speed*gu->timeOffset;
	va->AddVertexTC(interPos-camera->right*drawRadius-camera->up*drawRadius,ph->projectiletex.xstart,ph->projectiletex.ystart,col);
	va->AddVertexTC(interPos+camera->right*drawRadius-camera->up*drawRadius,ph->projectiletex.xend,ph->projectiletex.ystart,col);
	va->AddVertexTC(interPos+camera->right*drawRadius+camera->up*drawRadius,ph->projectiletex.xend,ph->projectiletex.yend,col);
	va->AddVertexTC(interPos-camera->right*drawRadius+camera->up*drawRadius,ph->projectiletex.xstart,ph->projectiletex.yend,col);
}

void CProjectile::DrawArray()
{
	va->DrawArrayTC(GL_QUADS);
	ph->currentParticles+=va->drawIndex/24;		//each particle quad is 24 values large
	va=GetVertexArray();
	va->Initialize();
	inArray=false;
}


void CProjectile::DependentDied(CObject *o)
{
	if(o==owner)
		owner=0;
}

void CProjectile::DrawCallback(void)
{
}

void CProjectile::DrawUnitPart(void)
{
}

⌨️ 快捷键说明

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