示例#1
0
bool GameLoader::Initialise(HWND hWnd)
{
	if(!SUCCEEDED(InitialiseD3D(hWnd)))
	{
		return false;
	}

	InitialiseGame();
	return true;
}
示例#2
0
int init_gl()
{

    if (!glfwInit()) {
        printf("glfwInit() failed\n");
        return false;
    }

    window = glfwCreateWindow(width, height, "2dEngine", NULL, NULL);
    if (!window) {
        printf("glfwOpenWindow() failed\n");
        return false;
    }

    glfwMakeContextCurrent(window);

    engine = InitialiseGame();

    return true;
}
示例#3
0
文件: app.c 项目: RorschachUK/Trakr
//Main program loop - Run gets called until it returns false
bool Run() {
  	//Main loop - get keypresses and interpret them
  	keystate=GetRemoteKeys();
	if(keystate & KEY_HOME) {
		return false;
	}
	switch(mode) {
		case 0: {	//Splash screen
			if (keystate & KEY_INPUT2) { //Button B
				//Start game
				InitialiseGame();
				PlaySound(SOUND_BEEP);
			}

			if (keystate & KEY_INPUT1) { //Button A
				//show help
				ShowHelp();
				PlaySound(SOUND_BEEP);
			}
		}
		break;
		case 2: {	//Help - wait for 'OK' press
			if (keystate & KEY_INPUT2) { //Button B
				//Reset back to splash screen
				ResetTimer();
				mode=0;

				Splash();
				PlaySound(SOUND_BEEP);
			}
		}
		break;
		case 1: {	//Game
			if (keystate & KEY_INPUT1) { //Button A
				//Reset back to splash screen
				ResetTimer();
				mode=0;

				Splash();
			}
			if (keystate & KEY_RUN) { //Go button
				//Fire!
				PlaySound(SOUND_SHOOT);
				refreshCount = 0;
				int hit;
				hit = LineHitsObject(cameraPos, cameraAngle);
				if (hit == tankObjectIndex) {
					//we hit the tank!
					score += 100;
					CloseGraphics();
					OpenGraphics();
					DrawWorld(&world, cameraPos, cameraAngle);
					DrawHUD();
					DrawExplosion();
					DrawArrow(cameraAngle.y);
					DrawRadarDots(true);
					DrawRadarArm(sweepAngle * sweepStepCount++);
					DrawRadarDots(false);

					SetTextColor(CYAN);
					DrawText(6,100,"Quit");
					Show();
					PlaySound(SOUND_EXPLOSION);
					PlaceTank(cameraPos, cameraAngle);
				}
			}

			//Have the movement sticks changed? This bit doesn't care about buttons
			if((keystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD)) != (oldKeystate & (KEY_RIGHT_BACK+KEY_RIGHT_FORWARD+KEY_LEFT_BACK+KEY_LEFT_FORWARD))) {

				MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate);
				arrowRefAngle=cameraAngle.y;
				baselinePos=cameraPos;

				ResetTimer();
				oldKeystate = keystate;
				if (keystate==0) //we've just stopped moving
					refreshCount=0;
			}

			if (mode==1) {
				if (sweepStepCount == SWEEPSTEPS)
					sweepStepCount=0;

				if (--behaviourCount<0)
					ChooseBehaviour();

				MoveTank();

				MoveCamera(&cameraPos, &cameraAngle, baselinePos, arrowRefAngle, ReadTimer(), oldKeystate);
				//is it time to reset the tank model?  Otherwise it gradually gets distorted
				if (--resetCount<0) {
					//Refresh the tank model which is prone to getting distorted
					//due to cumulative inaccuracies of sin/cos approximations
					Point3d angle=world.objects[tankObjectIndex].heading;
					Point3d tankPos=world.objects[tankObjectIndex].centre;
					world.objects[tankObjectIndex]=tank;
					MoveObject(&(world.objects[tankObjectIndex]), tankPos);
					RotateObjectYAxis(&(world.objects[tankObjectIndex]), angle.y);
					resetCount=50;
				}

				//Is it time to redraw the world?
				if (--refreshCount<0) {
					//Seems a bit brutal to have to close graphics but it's
					//the only way to clear the screen that'll let us draw
					//on it properly again - ClearScreen or ClearRectangle mess up
					CloseGraphics();
					OpenGraphics();

					DrawWorld(&world, cameraPos, cameraAngle);

					DrawHUD();
					refreshCount=2;
				}
				DrawArrow(cameraAngle.y);
				DrawRadarDots(true);
				DrawRadarArm(sweepAngle * sweepStepCount++);
				DrawRadarDots(false);

				SetTextColor(CYAN);
				DrawText(6,100,"Quit");
				Show();

				//just in case we changed mode...
				if (mode==0)
					Splash();
			}
		}
	}
	Sleep(50);
	return true;
}