www.pudn.com > MyGame.rar > GameIntro.cpp


// GameIntro.cpp: implementation of the CGameIntro class. 
// 
////////////////////////////////////////////////////////////////////// 
 
#include "stdafx.h" 
#include "MyGame.h" 
#include "GameIntro.h" 
 
 
#ifdef _DEBUG 
#undef THIS_FILE 
static char THIS_FILE[]=__FILE__; 
#define new DEBUG_NEW 
#endif 
#ifdef _WIN32 
#define drand48() (((float) rand())/((float) RAND_MAX)) 
#define srand48(x) (srand((x))) 
#endif 
 
extern CGameSession GS; 
char *message[3]={"Press SPACEBAR to Start Game","Written By PigeonStudio","2001.7.7 CopyRight(c) NUDT"}; 
char *TitleMessage=message[0]; 
 
////////////////////////////////////////////////////////////////////// 
// Construction/Destruction 
////////////////////////////////////////////////////////////////////// 
 
CGameIntro::CGameIntro() 
{ 
	Title.Open("data/title.raw"); 
	Title.Flip(); 
} 
 
CGameIntro::~CGameIntro() 
{ 
 
} 
 
void CGameIntro::Clip(Point3f &p) 
{ 
	if(p.x() > 200-p.z() || p.y() > 200-p.z()) 
	{ 
		p.x()=(drand48()-0.5)*1000;	 
		p.y()=(drand48()-0.5)*1000;	 
		p.z()=-800; 
	} 
}; 
 
 
void CGameIntro::KeyDown(UINT nChar) 
{ 
	switch(nChar) 
	{ 
		case VK_SPACE : Game= &GS; 
			GS.Init(); 
			GS.Reshape(ScreenW,ScreenH); 
			break; 
	} 
} 
 
void CGameIntro::Init(int,int) 
{ 
	CAst3DFract::SetSharedTexture("data/ast.png"); 
	CMesh AstM; 
	AstM.Open("data/tetra.raw"); 
	if(A.size()p.x()=(drand48()-0.5)*1000;	 
			A[i]->p.y()=(drand48()-0.5)*1000;	 
			A[i]->p.z()=-800; 
			A[i]->v.z()=200; 
			A[i]->av=20+drand48()*70; 
			A[i]->axis=Normalize(Point3f(drand48(),drand48(),drand48())); 
		} 
	} 
	float lp[4]={1,1,3,0}; 
	glLightfv(GL_LIGHT0,GL_POSITION,lp); 
	glEnable(GL_LIGHT0); 
	glEnable(GL_LIGHTING); 
	glDisable(GL_CULL_FACE); 
	glEnable(GL_COLOR_MATERIAL); 
	glEnable(GL_DEPTH_TEST); 
	glEnable(GL_NORMALIZE); 
	// ²¥·ÅÉùÒôÎļþ   
	if(AudioFlag)  
	{ 
		APlayModule(lpModule); 
		ASetModuleVolume(8); 
	} 
} 
 
int CGameIntro::Draw() 
{ 
	static float angle=0; 
	int nt=0; 
	glLoadIdentity(); 
	glPushMatrix(); 
	glColor3f((GLfloat).7,(GLfloat).7,(GLfloat)1.); 
	int sw=342; // subtitle width 
	m_Utility.glPrintf(ScreenW,ScreenH,ScreenW/2,ScreenH/3,1,12, TitleMessage); 
	angle+=5.0; 
	glRotatef(angle,0,1,0); 
	glScalef(40,40,40); 
	nt+=Title.DrawDL(); 
	glPopMatrix(); 
	glPushMatrix(); 
	glTranslatef(0,0,-1000); 
	glScalef(2000,2000,2000); 
	s.Draw(); 
	glPopMatrix(); 
 
	for(int i=0;iDraw(); 
	return nt; 
} 
 
void  CGameIntro::Reshape(int w,int h) 
{ 
	ScreenW=w; 
	ScreenH=h; 
	int SpaceSize=100; 
	float wr=float(w)/h; 
	float hr=float(h)/w; 
 
	if(w>h) hr=1; 
	else wr=1; 
	int VL = -SpaceSize*wr; 
	int VR =  SpaceSize*wr; 
	int VB = -SpaceSize*hr; 
	int VT =  SpaceSize*hr; 
	glViewport(0,0,w,h); 
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity(); 
 
	gluPerspective(90,1,5,1201); 
	gluLookAt(0,0,200,0,0,0,0,1,0); 
	glMatrixMode(GL_MODELVIEW); 
} 
 
void CGameIntro::Update(int dt) 
{ 
	static int t=0; 
	static int titind; 
	t+=dt; 
	if(t>2000)  
	{ 
		t=0; 
		titind=(titind+1)%3; 
		TitleMessage=message[titind]; 
	} 
	s.Update(dt); 
	for(int i=0;iUpdate(dt); 
		 Clip(A[i]->p); 
	} 
}