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

📄 ship3d.cpp

📁 基于引擎基础上开发的三维游戏实例“恐怖之战”游戏者可以自爱三维地形上漫游
💻 CPP
字号:
// Ship3D.cpp: implementation of the CShip3D class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MyGame.h"
#include "Ship3D.h"

#include "GameObjTimed.h"
#include "Bullet.h"
#include "Ship.h"
//#include "BulletFireBall.h"

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

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

CShip3D::~CShip3D()
{

}

CShip3D::CShip3D(char * filename, char * texturename)
{
	M.Open(filename);
	M.Normalize();
	if(texturename)
	{
		M.SetTexture(texturename);
		M.SetMapMode(CMesh::PLANAR);
	}
    M.Smooth();
	B.r=3;
}

int CShip3D::Draw()
{
	int nt=0;
	static float flamelen=5;
	glPushMatrix();
	glTranslate(p);
	glRotatef(angle,0,0,1);
	if(av>0) glRotatef(-30,1,0,0);
	if(av<0) glRotatef( 30,1,0,0);
	glPushMatrix();
	glScalef(8,8,8);
	glRotatef(180,1,0,0);
	glColor3f((GLfloat).7,(GLfloat)1.,(GLfloat).7);
    glDisable(GL_CULL_FACE);
	nt+=M.Draw();
	glEnable(GL_CULL_FACE);
	glPopMatrix();
	glTranslatef(-2,0,0);
	glDisable(GL_LIGHTING);
	if(lthrust)
	{
		glBegin(GL_TRIANGLE_FAN);
		glColor3f((GLfloat).95,(GLfloat).9,(GLfloat).6);
		glVertex3f(-1, -6,  0);
		glVertex3f(0,  -10,  0);
		glVertex3f(1, -6,  0);
		glVertex3f(0,  -4,  0);
		glEnd();
		nt+=2;
	}
	if(rthrust)
	{
		glBegin(GL_TRIANGLE_FAN);
		glColor3f((GLfloat).95,(GLfloat).9,(GLfloat).6);
		glVertex3f(1, 6,  0);
		glVertex3f(0,  10,  0);
		glVertex3f(-1,  6,  0);
		glVertex3f(0,  5,  0);
		glEnd();
		nt+=2;
	}
	if(thrust)
	{
		if(flamelen==12) flamelen=10;
		else flamelen=12;
		glBegin(GL_TRIANGLE_FAN);
		glColor3f((GLfloat).95,(GLfloat).9,(GLfloat).6);
		glVertex3f(-5,0,0);
		glColor3f((GLfloat).95,(GLfloat).5,(GLfloat).1);
		glVertex3f(-2, 0,  0);
		glVertex3f((GLfloat)-3, (GLfloat)1.7,(GLfloat)0);
		glVertex3f(-4, 2,  0);
		glVertex3f(-7, 1, 0);
		glColor3f((GLfloat).6,(GLfloat).3,(GLfloat).1);
		glVertex3f(-flamelen,0,0);
		glColor3f((GLfloat).95,(GLfloat).5,(GLfloat).1);
		glVertex3f(-7,-1,  0);
		glVertex3f(-4,-2,  0);
		glVertex3f(-3,(GLfloat)-1.7,0);
		glVertex3f(-2, 0,  0);
		glEnd();
		nt+=8;
	}
	glEnable(GL_LIGHTING);
	glPopMatrix();
	return nt;
}

void CShip3D::Shoot(list<CBullet *> &LB)
{
	if(ActiveBullet+2 < MaxBullet())
	{
		ActiveBullet+=3;
		CBullet *bb;
		angle-=10;
		bb =new CBullet(p - RotateZ(Point3f(0,+2,0),float((angle+10)*M_PI/180.0f)),angle,v+VDir()*30);
		LB.push_back(bb);
		angle+=20;
		bb =new CBullet(p - RotateZ(Point3f(0,-2,0),float((angle-10)*M_PI/180.0f)),angle,v+VDir()*30);
		LB.push_back(bb);
		angle-=10;
		bb =new CBullet(p,angle,v+VDir()*30);
		LB.push_back(bb);
	}
}

⌨️ 快捷键说明

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