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

📄 terraingame.cpp

📁 一個簡單的游戲設計...好好玩的
💻 CPP
字号:
#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>
#include <stdio.h>
#include "define.h"
#include "game.h"
#include "opening.h"
#include "terrainGame.h"

static GAME *G;
static bool FirstRun = false;
static bool RightReslution = false;

int main(int argc, char** argv) {

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
	glutInitWindowSize(WIDTH,HEIGHT);
	glutInitWindowPosition(0, 0);
	glutCreateWindow(argv[0]);

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel(GL_FLAT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, WIDTH, 0, HEIGHT, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	G = new OPENING;
	G->SetWinSize(WIDTH,HEIGHT); 

	glutReshapeFunc(Reshape);
	glutDisplayFunc(Display);
	glutKeyboardFunc(KeyBoard);
	glutSpecialFunc(KeySpecial);
	glutMouseFunc(Mouse);
	glutMotionFunc(MouseMotion);
	glutPassiveMotionFunc(MousePassiveMotion);
	glutTimerFunc(33,Timer,1);
	glClearColor(1.0,1.0,1.0,0.0);
	glutMainLoop();

	delete G; //Delete the GAME OBject
	return 0; //End the Program
}

void Display () 
{ G->Display();
	if ( RightReslution ) G->Display(); 
	else {
		glClear(GL_COLOR_BUFFER_BIT);
		glutSwapBuffers();
	}
}

void CheckGameState() 
{
	if ( G->NextState() ) {
		GAME *gTemp = G->NextState();
		delete G;
		G = gTemp;
		Display();
	}
}

void KeyBoard (unsigned char Key, int KX , int KY) 
{ 
	if ( RightReslution ) {
		K_EVENT kTemp((int) Key, KX , KY , glutGetModifiers() , ::K_EVENT.KEY );
		G->KeyBoard(kTemp); 
		CheckGameState();
	}
} 

void KeySpecial (int Key, int KX , int KY ) 
{ 
	if ( RightReslution ) {
		K_EVENT kTemp((int) Key, KX , KY , glutGetModifiers() , ::K_EVENT.SPECIAL );
		G->KeyBoard(kTemp);
		CheckGameState();
	}
}

void Mouse (int MButton, int MState, int MX , int MY) 
{ 
	if ( RightReslution ) {
		M_EVENT mTemp(MX,MY,MButton,MState, ::M_EVENT.MOUSE);
		G->Mouse(mTemp);
		CheckGameState();
	}

} 

void MouseMotion (int MX,int MY) 
{ 
	if ( RightReslution ) {
		M_EVENT mTemp(MX,MY,-1,-1, ::M_EVENT.MOTION); 
		G->Mouse(mTemp);
		CheckGameState();
	}

} 

void MousePassiveMotion(int MX,int MY) 
{ 
	if ( RightReslution ) {
		M_EVENT mTemp(MX,MY,-1,-1, ::M_EVENT.PMOTION); 
		G->Mouse(mTemp);
		CheckGameState();
	}
} 

void Reshape(GLsizei Width , GLsizei Height)
{ 

	if (!FirstRun) {
		if ( Width < 1000 && Height < 700 ) {
			glClear(GL_COLOR_BUFFER_BIT);
			printf("Please change your screen reslution to 1024x726.\n"); 
		} else RightReslution = true;

		FirstRun = true;
	}

	RightReslution = true;

	if ( RightReslution ) G->Reshape(Width,Height); 
} 

void Timer(int n) 
{

	if ( RightReslution ) G->GameTimer(n);

	glutTimerFunc(33,Timer,n);

}

⌨️ 快捷键说明

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