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

📄 game.cpp

📁 一个96K的3D游戏源码
💻 CPP
📖 第 1 页 / 共 5 页
字号:

				CalcObjUsingAnimationAndCountReal(Player[PlNum]->Obj,Player[PlNum]->Ani,Player[PlNum]->AniCnt);
				SkelPhysicAusgleich(Player[PlNum]->Obj->Skel);
				for(I=0;I<Amount;I++) 
				{
					CalcSkelSpeeds(Player[PlNum]->Obj->Skel);
				}

}

void DoMove(long PlNum,char _Index)
{

			if((Player[PlNum]->AttackRefresh==0))
			{
				Player[PlNum]->AttackPower=10;
				SetAnimation(Player[PlNum],_Index);
				ForwardAni(PlNum,6);
			}
}


void KI(long PlayerNum)
{
	tPlayer *Temp;
	tP3D Richtung,Test,EVek;
	Temp=Player[PlayerNum];
	float DerCos,Entf,OldY,SMul;
	long AttNr,M;

	if(PlDead||LevComplete) return;

	Richtung=vSub2(&Player[0]->Pos,&Temp->Pos);
	EVek=Richtung;
	Entf=vLength2(Richtung)-ModelAbstand[Temp->ModelType];
	Norm(&Richtung);

//if((Entf<_Act_Player_Abstand)||(Player[PlayerNum]->StandOnSector==NULL))
if(Entf<VisBorder)
{
	Player[PlayerNum]->Active=true;
	Norm3(&Test,vCross(v010,Temp->Matrix.Forward));
	Temp->LastRot=Temp->Rot;
	if(Entf<_Act_Player_Abstand)
	{
//		if(((EVek.Y>10.0)&&(Random(10)==0))||(Random(1000)==0)) DoJump(Temp);
		if((Temp->ModelType==_Model_Spider)&&(!EndGegner))
		{
			EndGegner=true;
			ChangeMusic((void*)&bossong,true);
		}
		if(((EVek.Y>10.0f)&&(Random(10)==0))) DoJump(Temp);
		Player[PlayerNum]->RealActive=true;
		DerCos=vMul(Richtung,Test);
		if((DerCos>0.1f)||(DerCos<-0.1f))
		{
			if(DerCos>0)
			{
				Temp->NextRot.Y=Temp->Rot.Y-ETurnSpeed;
			} else {
				Temp->NextRot.Y=Temp->Rot.Y+ETurnSpeed;
			}
		}
		if(vLength2(vAdd(Temp->Matrix.Forward,Richtung))<1.0f)
		if((DerCos>-0.2f)&&(DerCos<0.2f))
			if(Entf>_KI_Entf)
			{
//				vAdd4(&Temp->Speed,vAdd(vMulK2(&Temp->Matrix.Forward,-PSpeed),vMulK2(&Temp->Matrix.Up,0.01)));
//				vAdd4(&Temp->Speed,vAdd(vMulK2(&Temp->Matrix.Forward,-PSpeed),vMulK2(&Temp->Matrix.Up,0.02f)));
				SMul=-0.7;
				if(Temp->ModelType==_Model_Spider) SMul=-0.9;
				OldY=Temp->Speed.Y;
				Temp->Speed=vMulK2(&Temp->Matrix.Forward,PlayerSpeed*SMul);
				Temp->Speed.Y=OldY;
//				vAdd4(&Temp->Speed,vMulK2(&Temp->Matrix.Up,0.02f));
//				Temp->Speed=vMulK2(&Temp->Matrix.Forward,-PlayerSpeed*0.9);
			}
		if((Entf<_KI_KloppEntf)&&(Temp->AttackRefresh==0))
			if(Random(5)==0) 
			{
				AttNr=5;
				if((Temp->ModelType==_Model_Dog)||(Temp->ModelType==_Model_Spider)) AttNr=3;
				do
				{
					M=2+Random(AttNr);
				} while(M==Temp->LastAction);
				DoMove(PlayerNum,M);
				Temp->LastAction=M;
/*				
				if(Temp->ModelType==_Model_Player)	DoMove(PlayerNum,2+Random(5));
				if(Temp->ModelType==_Model_Dog)	DoMove(PlayerNum,2+Random(3));
				if(Temp->ModelType==_Model_Enemy1)	DoMove(PlayerNum,2+Random(5));
				if(Temp->ModelType==_Model_Spider)	DoMove(PlayerNum,2+Random(3));
				if(Temp->ModelType==_Model_Echse)	DoMove(PlayerNum,2+Random(5));
*/
			}
	} else {Player[PlayerNum]->RealActive=false;}
} else { Player[PlayerNum]->Active=false;}
}

void DrawGLLine(long X1,long Y1,long X2,long Y2,tP4D C1,tP4D C2)
{
	glBegin(GL_LINE_STRIP);
		glColor4fv((float*)&C1);
		glVertex2f(X1,Y1);
		glColor4fv((float*)&C2);
		glVertex2f(X2,Y2);
	glEnd();
}

void DrawGLRectangle(long X1,long Y1,long X2,long Y2,tP4D Color)
{
	glBegin(GL_LINE_STRIP);
		glColor4fv((float*)&Color);
		glVertex2f(X1,Y1);
		glVertex2f(X2,Y1);
		glVertex2f(X2,Y2);
		glVertex2f(X1,Y2);
		glVertex2f(X1,Y1);
	glEnd();
}

void DrawGLBox(long X1,long Y1,long X2,long Y2,tP4D C1,tP4D C2,tP4D C3,tP4D C4)
{
	glBegin(GL_QUADS);
		glColor4fv((float*)&C1);
		glVertex2f(X1,Y1);
		glColor4fv((float*)&C2);
		glVertex2f(X2,Y1);
		glColor4fv((float*)&C3);
		glVertex2f(X2,Y2);
		glColor4fv((float*)&C4);
		glVertex2f(X1,Y2);
	glEnd();
}


void DrawEnergy(long X1,long Y1,long X2,long Y2,float Energy,float RCol,float GCol,float BCol)
{
//	float GCol,RCol,BCol;
	float AMid=0.4f,AEnd=0.7f,AStart=0,MY;
/*
	if(Energy<0) Energy=0;
	if(Energy>1) Energy=1;
*/
	fRange(&Energy);
	DrawGLRectangle(X1,Y1,X2,Y2,v4Set(1,1,1,1));	
	MY=Y1+1+(float)(Y2-Y1-2)*Energy;

	if(Energy!=0)
		DrawGLBox(X1+1,Y1+1,X2-1,MY,v4Set(RCol,GCol,BCol,AEnd),v4Set(RCol,GCol,BCol,AEnd),v4Set(RCol,GCol,BCol,AMid),v4Set(RCol,GCol,BCol,AMid));
	if(Energy!=1)
		DrawGLBox(X1+1,MY,X2-1,Y2-1,v4Set(RCol,GCol,BCol,AMid),v4Set(RCol,GCol,BCol,AMid),v4Set(RCol,GCol,BCol,AStart),v4Set(RCol,GCol,BCol,AStart));

	DrawGLLine(X1,MY,X1+10,MY,v4Set(1,1,1,1),v4Set(1,1,1,0));
	DrawGLLine(X2,MY,X2-10,MY,v4Set(1,1,1,1),v4Set(1,1,1,0));
}

void DrawPlayerStats()
{
	float A;
	if((!PlDead))
	{
		A=(float)Player[0]->Energy/(float)PlayerEnergy;
		DrawEnergy(10,10,30,200,A,1.0f-A,A,0);
		A=(float)BMZPos/(float)BMZMax;
		DrawEnergy(610,10,630,100,A,1,1,1);
//		glColor4f(1,1,1,1);
		SetAlpha(1);
		glPrint(40,12,"Lives: %d",Lives);
		if(Player[0]->Gun==1) glPrint(260,12,"Pistol:%d",Player[0]->Ammo[Player[0]->Gun-1]);
		if(Player[0]->Gun==2) glPrint(260,12,"Flamer:%d",Player[0]->Ammo[Player[0]->Gun-1]);
	}
/*
	DrawGLRectangle(30,30,130,250,vSet(1,1,1),1);	
	DrawGLBox(31,31,129,249,v4Set(0,1,0,1),v4Set(0,1,0,1),v4Set(0,1,0,0),v4Set(0,1,0,0));
*/
}

void EndPrint(float X,float Y,char *Text)
{
#define FadeLen 50.0f
	float Pos;
	float Col;

	float Len=(float)(GlobalTimer-EndCnt)/3.0f;
	if(Len>1130) Len=1130;
	Pos=-Y+Len;
	if((Pos>-10)&&(Pos<500))
	{
		Col=1;
		if(Pos<FadeLen) Col=Pos/FadeLen;
		if(Pos>480-FadeLen) Col=(480-Pos)/FadeLen;
		fRange(&Col);
/*
		if(Col<0) Col=0;
		if(Col>1) Col=1;
*/
//		glColor4f(1,1,1,Col);
		SetAlpha(Col);
		glPrintMid(X,Pos,Text);
	}
}

void DrawGLBox2(long X1,long Y1,long X2,long Y2,tP4D Col,float Alpha)
{
	Col.A*=Alpha;
	DrawGLRectangle(X1,Y1,X2,Y2,v4Set(1,1,1,1*Alpha));
	DrawGLBox(X1+1,Y1+1,X2-1,Y2-1,Col,Col,Col,Col);
}

void DrawStats()
{

	InitText();
//	glColor3f(1,1,1);
	SetAlpha(1);
	if(!SynthInit) glPrint(0,300,"Synth is not working");
	if(StatsOn)
	{
		glPrint(10,460,"FpS:%d",FramesPS);
/*
		glPrint(10,440,"Testnode:%d",TestNodeNr);
		if(BF1) glPrint(10,420,"F1");
		if(BF2) glPrint(60,420,"F1");
		if(BF3) glPrint(110,420,"F1");
		if(BF4) glPrint(160,420,"F1");
		if(BF5) glPrint(210,420,"F1");
		if(BF6) glPrint(260,420,"F1");
		if(BF7) glPrint(310,420,"F1");
		if(BF8) glPrint(360,420,"F1");
*/
	}


	if(MenuOn)
	{
//		DrawGLBox2(200,180,440,340,v4Set(0,1,0.2,0.25));
//		DrawGLBox2(200,273-MenuItems*22,440,290,v4Set(0,1,0.2,0.25));
		DrawGLBox2(200,273-MenuItems*22,440,290,v4Set(0,0.8,0.2,0.3),1);
//		DrawGLBox2(225,290,415,320,v4Set(1,0.3,0.1,0.4),1);
		DrawGLBox2(225,290,415,320,v4Set(0.8,0.7,0.3,0.2),1);

/*
		tP4D BackCol=v4Set(0,1,0.2,0.5);

		DrawGLRectangle(200,170,440,340,v4Set(1,1,1,1));
		DrawGLBox(201,171,439,339,BackCol,BackCol,BackCol,BackCol);
*/
#ifdef DebugVersion
		glPrintMid(320,450,"(1..3 f黵 Levelauswahl dr點ken)");
#endif

		glColor3f(1,1,1);
		glPrintMid(315,300,"-= B-Clopd 3D =-");
		glPrintMid(312,265,"New Game");
		glPrintMid(312,243,"Music On/Off");
		glPrintMid(322,221,"Mouse Sensitivity (%d%c)",MouseSens,'%');
		glPrintMid(312,199,"Quit Game");
		if(MenuItems>4) glPrintMid(310,177,"RESUME");
//		glPrintMid(350,260-MenuPos*20,"->                                   <-");
		DrawGLBox2(205,259-MenuPos*22,435,282-MenuPos*22,v4Set(1,1,1,0.4),1);
		if(MainMenu)
		{
			glColor4f(0.9f,0.9f,0.9f,1);
			glPrintMid(320,7,"www.creative-mind.org");
		}
	}

	if(PlDead)
	{
		if(PlDeadCnt<50) {glPrintMid(320,250,"- You -");}
		else if(PlDeadCnt<100) {glPrintMid(320,250,"- are -");}
		else 
		{
			glPrintMid(320,250,"-= DEAD =-");
			if(Lives<0)
			{
				glPrintMid(320,210,"GAME OVER");
			} else {
				glPrintMid(335,210,"%d Lives left",Lives);
			}
			glPrint(485,10,"Hit [SPACE] ...");
		}
	
	}
	if(LevComplete)
	{
		if(EndGegner)
		{
			EndPrint(300,0,"-= Victory =-");
			EndPrint(320,40,"The evil Mastermind Spiderion(tm) has been defeated.");
			EndPrint(320,60,"Finally, Plattform-World is a save place again :o)");
			EndPrint(320,80,"Hurry up, tell your kids !");
			EndPrint(320,120,"...Consider yourself victorios !...");
			EndPrint(300,200,"- [THE END] -");
			EndPrint(320,340,"-= Coming up : The Credits =-");
			EndPrint(320,370,"Coding this game took about half a year and was");
			EndPrint(320,390,"done by Pap in 2003/04.");
			EndPrint(320,410,"The project includes a Texture-Generator, an");
			EndPrint(320,430,"Animation-Tool, a 3D-Editor and a Post-Optimizer.");
			EndPrint(320,460,"The nice Texture-Generation-Algorithm called 'FillGen'");
			EndPrint(320,480,"was done by Fillbert");
			EndPrint(320,510,"The 'Tunefish subtractive modular Synthesizer' was done");
			EndPrint(320,530,"by Snej of Braincontrol (www.braincontrol.org)");
			EndPrint(320,560,"The Objects and Levels were created and animated without");
			EndPrint(320,580,"3rd-party Software. A lot of them have been designed by");
			EndPrint(320,600,"Ghettobitch and then been modeled by Pap.");
			EndPrint(320,630,"The music was composed by Starbuck and Skyrunner");
			EndPrint(330,850,"For further information check:");
			EndPrint(320,870,"-= www.creative-mind.org =-");
			EndPrint(320,920,"[You may Press ESC now]");
		} else {
			glPrintMid(320,250,"-= Level Completed =-");
			glPrint(485,10,"Hit [SPACE] ...");
		}
	}

	if((!MainMenu)&&(!LevComplete))
		DrawPlayerStats();

	DoneText();
}

//void DrawPartikel(tPartikel *Partikel)
void DrawSprite(GLuint TexNr,tP3D SprPos,tP3D Color,float Alpha,float Size,float X1,float Y1,float X2,float Y2)
{
	tP3D Pos;

	glLoadIdentity ();													// Reset The Modelview Matrix
	gluLookAt(CPos.X,CPos.Y,CPos.Z,CLook.X,CLook.Y,CLook.Z,0,1,0);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, TexNr);	

	glDisable(GL_LIGHT0);	
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_LIGHT1);	
	glDisable(GL_LIGHTING);

	glBegin(GL_QUADS);

//		glColor4f(Temp->Color.X,Temp->Color.Y,Temp->Color.Z,0.5*((float)Temp->Life/(float)Temp->MaxLife));
//	glColor4f(Color.X,Color.Y,Color.Z,Alpha);
	glColor4fv((float*)&Color);


	glTexCoord2f(X1,Y2);
	Pos=vAdd5(&SprPos,vAdd(vMulK2(&ViewX,-Size),vMulK2(&ViewY,-Size)));
	glVertex3fv((float*)&Pos);

	glTexCoord2f(X2,Y2);
	Pos=vAdd5(&SprPos,vAdd(vMulK2(&ViewX,Size),vMulK2(&ViewY,-Size)));
	glVertex3fv((float*)&Pos);

	glTexCoord2f(X2,Y1);
	Pos=vAdd5(&SprPos,vAdd(vMulK2(&ViewX,Size),vMulK2(&ViewY,Size)));
	glVertex3fv((float*)&Pos);

	glTexCoord2f(X1,Y1);
	Pos=vAdd5(&SprPos,vAdd(vMulK2(&ViewX,-Size),vMulK2(&ViewY,Size)));
	glVertex3fv((float*)&Pos);

	glEnd();
	glDisable(GL_TEXTURE_2D);

}

void DrawPartikel(tPartikel *Partikel)
{
	tP3D Pos,OldPos;
	tP4D Col;
	tPartikel *Temp;
	long L,LL,It;
	float Size,A;

//	return;


	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, textures[3].texID);	
	glDisable(GL_LIGHT0);	
	glDisable(GL_COLOR_MATERIAL);
	glDisable(GL_LIGHT1);	
	glDisable(GL_LIGHTING);

	MakeGlMatrix(&ViewMatrix,vNull);
	Temp=Partikel;
	OldPos=vNull;

	L=0;
//	while((Temp!=NULL)&&(L<MaxParticles))
	for(It=0;It<Particles;It++)
	{
		Temp=(Partikel+It);
		Size=Temp->Size;

		LL=L*4;

		A=0.5f*((float)Temp->Life/(float)Temp->MaxLife);
		Pos=CalcRelPosition(Temp->Pos,&ViewMatrix);

		*(PartPos+(LL))= vSet(Pos.X,Pos.Y-Size,Pos.Z+Size);
		*(PartPos+(LL+1))=vSet(Pos.X,Pos.Y+Size,Pos.Z+Size);
		*(PartPos+(LL+2))=vSet(Pos.X,Pos.Y+Size,Pos.Z-Size);
		*(PartPos+(LL+3))=vSet(Pos.X,Pos.Y-Size,Pos.Z-Size);
	
		Col=v4Set(Temp->Color.X,Temp->Color.Y,Temp->Color.Z,A);
		*(PartCol+(LL))=Col;
		*(PartCol+(LL+1))=Col;
		*(PartCol+(LL+2))=Col;
		*(PartCol+(LL+3))=Col;

		*(PartTex+(LL))=v2Set(0,0);
		*(PartTex+(LL+1))=v2Set(1,0);
		*(PartTex+(LL+2))=v2Set(1,1);
		*(PartTex+(LL+3))=v2Set(0,1);

		*(PartIndex+(LL))=LL;
		*(PartIndex+(LL+1))=LL+1;
		*(PartIndex+(LL+2))=LL+2;
		*(PartIndex+(LL+3))=LL+3;

		L++;
	}

    glVertexPointer(3,GL_FLOAT,0,PartPos);
    glColorPointer(4,GL_FLOAT,0,PartCol);
    glTexCoordPointer(2,GL_FLOAT,0,PartTex);

	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glDepthMask(false);
	glColorMask(true,true,true,false);
//	glDisable(GL_DEPTH_TEST);							// Enables DePth Testing

	glDrawElements(GL_QUADS,L*4,GL_UNSIGNED_INT,PartIndex);

//	glEnable(GL_DEPTH_TEST);							// Enables DePth Testing
	glDepthMask(true);
	glColorMask(true,true,true,true);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);


	glPopMatrix();

}

void ManualDraw(tGrund *Mesh,tMaterial *TempM,float EnvEnt,bool UseTexC)
{
	long L,LL;
	tWandPoly *TempP;
	tP2D TexMod=EnvAdd;
	L=0;
	LL=0;
//	vAdd3(&TexMod,&EnvAdd);
	TempP=Mesh->Poly;

	__asm
	{
		mov		ebx,[MDPos]
		mov		ecx,[MDNormal]
// ebx = MDPos
// ecx = MDNormal
		mov		esi,[TempP]
PolyLoop:
		cmp		esi,0
		je		JumpOut

		mov		edi,esi
		mov		edx,3
Loop1:
		mov		eax,[edi+t_WandPoly.P1]
// edi = TempP->Px
		fld		dword ptr [eax+t_WandVertice.Normal.X]
		fst		dword ptr [ecx+tP3D.X]
		fld		dword ptr [eax+t_WandVertice.Normal.Y]
		fst		dword ptr [ecx+tP3D.Y]
		fld		dword ptr [eax+t_WandVertice.Normal.Z]
		fst		dword ptr [ecx+tP3D.Z]
		fld		dword ptr [EnvEnt]
		fmul	st(1),st(0)
		fmul	st(2),st(0)
		fmulp	st(3),st(0)
		fadd	dword ptr [eax+t_WandVertice.WorldPos.Z]		
		fstp	dword ptr [ebx+tP3D.Z]
		fadd	dword ptr [eax+t_WandVertice.WorldPos.Y]		
		fstp	dword ptr [ebx+tP3D.Y]
		fadd	dword ptr [eax+t_WandVertice.WorldPos.X]		
		fstp	dword ptr [ebx+tP3D.X]

		add		edi,4
		add		ecx,12
		add		ebx,12
		dec		edx
		jnz		Loop1


		mov		esi,[esi+t_WandPoly.Next]
		jmp		PolyLoop
JumpOut:






		mov		ebx,[MDTex]
		mov		ecx,[MDIndex]
		mov		edx,[TempM]
// ebx = MDPos
// ecx = MDNormal
		mov		esi,[TempP]
PolyLoop2:
		cmp		esi,0
		je		JumpOut2

		mov		edi,esi

⌨️ 快捷键说明

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