Beispiel #1
0
int main()
{	
	system("clear");

	for(int i=0;i<2;i++){
		map_init(&gScreenBuffer[i]);
		gScreenBuffer[i].fpnew(&gScreenBuffer[i],35,16);
		//map_new(&gScreenBuffer[i],35,16);
	}

	map_init(&gPlayerModel);
	map_load(&gPlayerModel,"plane.dat");

	Plane_init(&gPlayerObject,&gPlayerModel,17,10);
	bullet_init(&gBulletObject,0,0,0,&gPlayerModel);

	map_init(&gBulletModel);
	map_load(&gBulletModel,"plasma.dat");

	bullet_init(&gBulletObject,0,0,0,&gBulletModel);
	
	set_conio_terminal_mode();
	acc_tick=last_tick=0;
	acc_bullet_delay_tick=0;

	while(bLoop) {
		//타이밍처리 
		clock_gettime(CLOCK_MONOTONIC,&work_timer);
		double cur_tick = work_timer.tv_sec + 
			(double)(work_timer.tv_nsec * 1e-9);
		double delta_tick = cur_tick - last_tick;
		last_tick = cur_tick;
		//실시간 입력
		if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("bye~ \r");
			}
			else if(ch=='j'){
				double bullet_posx=0;
				double bullet_posy=0;

				double target_posx=gPlayerObject.m_fXpos;
				double target_posy=gPlayerObject.m_fYpos;

				double vx=target_posx-bullet_posx;
				double vy=target_posy-bullet_posy;

				double dist=sqrt(vx*vx+vy*vy);

				vx/=dist; vy/=dist;

				gBulletObject.pfFire(&gBulletObject,bullet_posx,bullet_posy,10,vx,vy,10.0);
			}
			gPlayerObject.pfApply(&gPlayerObject,delta_tick,ch);
			//Plane_Apply(&gPlayerObject,delta_tick,ch);
		}

		acc_bullet_delay_tick+=delta_tick;
		if(acc_bullet_delay_tick>2.0){	//2초동안 방향설정

			acc_bullet_delay_tick=0;

			double bullet_posx=gBulletObject.m_fXpos;
			double bullet_posy=gBulletObject.m_fYpos;

			double target_posx=gPlayerObject.m_fXpos;
			double target_posy=gPlayerObject.m_fYpos;

			double vx=target_posx-bullet_posx;
			double vy=target_posy-bullet_posy;

			double dist=sqrt(vx*vx+vy*vy);

			vx/=dist; vy/=dist;

			gBulletObject.m_fvx=vx;
			gBulletObject.m_fvy=vy;
		}


		//apply위치
		gBulletObject.pfApply(&gBulletObject,delta_tick);
	
		//타이밍 계산 
		acc_tick += delta_tick;
		
		if(acc_tick > 0.1) {
			//puts("tick..\r");
			gotoxy(0,0);
			map_drawTile(&gScreenBuffer[0],0,0,&gScreenBuffer[1]);
			gPlayerObject.pfDraw(&gPlayerObject,&gScreenBuffer[1]);
			gBulletObject.pfDraw(&gBulletObject,&gScreenBuffer[1]);
			
			//Plane_Draw(&gPlayerObject,&gScreenBuffer[1]);
			map_dump(&gScreenBuffer[1],Default_Tilepalete);
			acc_tick = 0;
		}

	}

	return 0;

}
Beispiel #2
0
Datei: game.c Projekt: chaem/test
/*=======================================================*/
int main()
{
    set_conio_terminal_mode();
	acc_tick = last_tick = 0;

 	while(bLoop) {
		// time process
		clock_gettime(CLOCK_MONOTONIC,&work_timer);
		double cur_tick = work_timer.tv_sec + 
			(double)(work_timer.tv_nsec * 1e-9);
		double delta_tick = cur_tick - last_tick;
		last_tick = cur_tick;

		// input
		if (nFSM == 0) {
			gameStart_Title(delta_tick);

		}
		else if (nFSM == 1) { 
			gameStart_Play();

		}

        if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("bye~ \r");
			}
            else if (ch =='p') {  //laser
				double bullet_pos_x = gTestBulletObject.m_fXpos;
				double bullet_pos_y = gTestBulletObject.m_fYpos;
			
				double target_pos_x = gPlaneObject.m_fXpos;
				double target_pos_y = gPlaneObject.m_fYpos;

				double vx = target_pos_x - bullet_pos_x;
				double vy = target_pos_y - bullet_pos_y;
				double dist  = sqrt(vx*vx+vy*vy);
				vx /= dist;
				vy /= dist;

				gLaserObject.pfFire(&gLaserObject,
				gPlaneObject.m_fXpos,gPlaneObject.m_fYpos,
				-1,0,gPlaneObject.m_fYpos,15);

			}

			gPlaneObject.pfApply(&gPlaneObject,delta_tick,ch);

        }
        gTestAlienObject.pfApply(&gTestAlienObject,delta_tick);
		gTestBulletObject.pfApply(&gTestBulletObject,delta_tick);
		gLaserObject.pfApply(&gLaserObject,delta_tick);

		if (gTestBulletObject.m_nFSM != 0) {
			double bullet_pos_x = gTestBulletObject.m_fXpos;
			double bullet_pos_y = gTestBulletObject.m_fYpos;

			double target_pos_x = gPlaneObject.m_fXpos;
			double target_pos_y = gPlaneObject.m_fYpos;

			double vx = target_pos_x + bullet_pos_x;
			double vy = target_pos_y + bullet_pos_y;
			double dist  = sqrt(vx*vx+vy*vy);

			if(dist < 2) {
				gTestBulletObject.m_nFSM = 0;
				gPlaneObject.m_nFSM = 0;
				
			}

		}
        acc_tick += delta_tick;
		if(acc_tick > 0.1) {
			gotoxy(0,0);
			map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]);

			setColor(33,40);
			gPlaneObject.pfDraw(&gPlaneObject,&gScreenBuf[1]);
			gTestAlienObject.pfDraw(&gTestAlienObject,&gScreenBuf[1]);
			gTestBulletObject.pfDraw(&gTestBulletObject,&gScreenBuf[1]);
			gLaserObject.pfDraw(&gLaserObject,&gScreenBuf[1]);

			map_dump(&gScreenBuf[1],Default_Tilepalete);
			acc_tick = 0;
		}

     }

    return 0;

}
Beispiel #3
0
int main()
{
	system("clear");

	for(int i=0;i<2;i++)
	{
		map_init(&gScreenBuf[i]);
		map_new(&gScreenBuf[i],35,30);
	}

	map_init(&gPlayerModel);
	map_load(&gPlayerModel,"plane5.dat");


	map_init(&gBulletModel);
	map_load(&gBulletModel,"target5.dat");


	Plane_init(&gPlayerObject,&gPlayerModel,17,24);
	bullet_init(&gTestBullet,0,0,0,&gBulletModel);

	set_conio_terminal_mode();
	acc_tick=last_tick=0;

	gPlayerObject.m_nFSM = 1;

	while(bLoop) {
		//타이밍처리 
		clock_gettime(CLOCK_MONOTONIC,&work_timer);
		double cur_tick = work_timer.tv_sec + 
			(double)(work_timer.tv_nsec * 1e-9);
		double delta_tick = cur_tick - last_tick;
		last_tick = cur_tick;
		//실시간입력	
		if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("Good bye~ \r");
			}
			else if (ch == 'j') {

				double vx,vy;
				gTestBullet.m_fXpos = 0;
				gTestBullet.m_fYpos = 0;
				getDirection(&gTestBullet,&gPlayerObject,&vx,&vy);
				gTestBullet.pfFire(&gTestBullet,
				gTestBullet.m_fXpos,
				gTestBullet.m_fYpos,
				10,vx,vy,10);
			}

			gPlayerObject.pfApply(&gPlayerObject,delta_tick,ch);
		}

		gTestBullet.pfApply(&gTestBullet,delta_tick);

		if(gTestBullet.m_nFSM != 0)	{
	
			double dist = getDistance(&gTestBullet,&gPlayerObject);

			if(dist < 2.0) {
				gTestBullet.m_nFSM = 0;
				gPlayerObject.m_nFSM = 0;
			}

		}


		//타이밍계산
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {
			gotoxy(0,0);
			map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]);

			gPlayerObject.pfDraw(&gPlayerObject,&gScreenBuf[1]);
			gTestBullet.pfDraw(&gTestBullet,&gScreenBuf[1]);	

			map_dump(&gScreenBuf[1],Default_Tilepalete);
			acc_tick = 0;
		}
	}

	return 0;
}
Beispiel #4
0
int main()
{
	system("clear");

	for(int i=0;i<2;i++) {
		map_init(&gScreenBuf[i]);
		map_new(&gScreenBuf[i],35,16);
	
	
	}

	map_init(&gPlayerModel);
	map_load(&gPlayerModel,"plane1.dat");

	map_init(&gBulletModel);
	map_load(&gBulletModel,"plasma.dat");
	
	Plane_init(&gPlayerObject,&gPlayerModel,17,10);
	bullet_init(&gTestBullet,0,0,0,&gBulletModel);

	set_conio_terminal_mode();
	acc_tick = last_tick = 0;

	//플레이상태로 만들기
	gPlayerObject.m_nFSM = 1;
	
	
	while(bLoop) {

		//타이밍처리
		clock_gettime(CLOCK_MONOTONIC,&work_timer);
		double cur_tick = work_timer.tv_sec + (double)(work_timer.tv_nsec * 1e-9);
		double delta_tick = cur_tick - last_tick;
		last_tick = cur_tick;

		//실시간입력	
		if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("bye~\r");
			}
			else if(ch == 'j') {
				
				double bullet_pos_x = 0;
				double bullet_pos_y = 0;

				double target_pos_x = gPlayerObject.m_fXpos;
				double target_pos_y = gPlayerObject.m_fYpos;

				double vx = target_pos_x - bullet_pos_x;
				double vy = target_pos_y - bullet_pos_y;
				double dist = sqrt(vx*vx+vy*vy);
				
				vx /= dist;
				vy /= dist;
				

				gTestBullet.pfFire(&gTestBullet,bullet_pos_x,bullet_pos_y,10.0,vx,vy,10);

			}

			gPlayerObject.pfApply(&gPlayerObject,delta_tick,ch);
		}
		gTestBullet.pfApply(&gTestBullet,delta_tick);

		if(gTestBullet.m_nFSM != 0) {
			double bullet_pos_x = gTestBullet.m_fXpos;
			double bullet_pos_y = gTestBullet.m_fYpos;

			double target_pos_x = gPlayerObject.m_fXpos;
			double target_pos_y = gPlayerObject.m_fYpos;

			double vx = target_pos_x - bullet_pos_x;
			double vy = target_pos_y - bullet_pos_y;
			double dist = sqrt(vx*vx+vy*vy);

			if(dist < 0.25) {
				gTestBullet.m_nFSM = 0;
				gPlayerObject.m_nFSM = 0;
	
			}

		}



		//타이밍계산
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {
			//puts("tick...\r");
			gotoxy(0,0);
			map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]);
			gPlayerObject.pfDraw(&gPlayerObject,&gScreenBuf[1]);
			gTestBullet.pfDraw(&gTestBullet,&gScreenBuf[1]);
				
			map_dump(&gScreenBuf[1],Default_Tilepalete);
			acc_tick = 0;
		}
	}


	return 0;
}
Beispiel #5
0
int main()
{

	for(int i=0;i<2;i++)
	{
		map_init(&gScreenBuf[i]);
		map_new(&gScreenBuf[i],35,16);
	}

	map_init(&gAlienModel);
	map_load(&gAlienModel,"alien.dat");

	map_init(&gPlasmaModel);
	map_load(&gPlasmaModel,"plasma.dat");

	alien_init(&gTestAlienObject,&gAlienModel);
	bullet_init(&gTestBulletObject,0,0,0,&gPlasmaModel);

	gTestAlienObject.m_pBullet = &gTestBulletObject;

	gTestAlienObject.m_fXpos = 5;
	gTestAlienObject.m_fYpos = 5;
	gTestAlienObject.m_nFSM = 1;

	set_conio_terminal_mode();
	acc_tick=last_tick=0;

	system("clear");

	while(bLoop) {
		//타이밍처리
		clock_gettime(CLOCK_MONOTONIC,&work_timer);
		double cur_tick = work_timer.tv_sec +
			(double)(work_timer.tv_nsec * 1e-9);
		double delta_tick = cur_tick - last_tick;
		last_tick = cur_tick;
		//실시간 입력
		if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("Bye~ \r");
			}
		}
	
		gTestAlienObject.pfApply(&gTestAlienObject,delta_tick);
		gTestBulletObject.pfApply(&gTestBulletObject,delta_tick);

		//타이밍 계산
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {
			gotoxy(0,0);
			map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]);

			gTestAlienObject.pfDraw(&gTestAlienObject,&gScreenBuf[1]);
			gTestBulletObject.pfDraw(&gTestBulletObject,&gScreenBuf[1]);

			map_dump(&gScreenBuf[1],Default_TilePalette);
			acc_tick = 0;
		}

	}

	return 0;

}