Ejemplo n.º 1
0
int main()
{
	set_conio_terminal_mode();
	acc_tick = last_tick = 0;

	for(int i=0;i<2;i++) {
		map_init(&gScreenBuffer[i]);
		map_new(&gScreenBuffer[i],35,15);

	}

	map_init(&gBulletModel);
	map_load(&gBulletModel,"plasma.dat");
	bullet_init(&gBulletObject,0,0,0,&gBulletModel);
	
	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");
			}
			else if(ch == 'j') {
				double vx,vy,c;
				vx = 1.0;
				vy = 1.0;
				c = sqrt(vx*vx + vy*vy);
				vx /= c; vy /= c;

				bullet_fire(&gBulletObject,17,7,1.0,vx,vy,10.0);

			}

		}


		//apply 위치
		bullet_apply(&gBulletObject,delta_tick);

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


	return 0;
}
Ejemplo n.º 2
0
int main(int argc,char *argv[])
{
	if(argc < 2) {
		gnPlayerIndex = 0;
	}
	else {
		gnPlayerIndex = atoi(argv[1]);
	}

	printf("ready player %d \r\n",gnPlayerIndex);
	

//소켓 연결 시도...
	struct sockaddr_in server;

	socket_desc = socket(AF_INET,SOCK_STREAM,0);
	if(socket_desc == -1)
	{
		puts("err create socket");
	}
	server.sin_addr.s_addr = inet_addr("127.0.0.1");
	server.sin_family = AF_INET;
	server.sin_port = htons(8080);
	if(connect(socket_desc,(struct sockaddr *)&server,sizeof(server)) < 0) {
		puts("connect error");
		return 1;
	}

	puts("connect ok!");
//쓰레드 기동 ..
	{
		int err = pthread_create(&tid,NULL,&InputThread,NULL);
		if(err != 0) {
			printf("err : %s \r\n",strerror(err));
		}
		else {
			printf("thread create success \r\n");
		}
	}

	{
		int err = pthread_create(&tid,NULL,&ListenThread,NULL);
		if(err != 0) {
			printf("err : %s \r\n",strerror(err));
		}
		else {
			printf("thread create success \r\n");
		}
	}

	puts("system ready!");
	sleep(3);

//게임 리소스 로딩 
	for(int i=0;i<2;i++)
	{
		map_init(&gScreenBuf[i]);
		map_new(&gScreenBuf[i],60,30);
	}

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

	map_init(&gPlaneBulletModel);
	map_load(&gPlaneBulletModel,"bullet1.dat");

	map_init(&gPotal);
	map_load(&gPotal,"potal.dat");

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

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

    Plane_init(&gPlayerObject[0],&gPlayerModel,5,25);
	gPlayerObject[0].m_nFSM = 1;

    Plane_init(&gPlayerObject[1],&gPlayerModel,50,25);
	gPlayerObject[1].m_nFSM = 1;

	Potal_init(&gPlayerPotal,&gPotal,1,1);

    for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_PLANE_BULLET_OBJECT);i++){
		plane_bullet_init(&gPlaneBulletObjects[i],0,0,0,&gPlaneBulletModel);
	}

	for(int i=0;i<sizeof(gPlasmaObjects)/sizeof(_S_BULLET_OBJECT);i++){
		bullet_init(&gPlasmaObjects[i],0,0,0,&gPlasmaModel);
	}

    double TablePosition[]={0,10,20,30,40,50,60};

	for(int i=0;i<6;i++){
		_S_ALIEN_OBJECT *pObj=&gAlienObjects[i];
		alien_init(pObj,&gAlienModel);
		pObj->m_fXpos=TablePosition[i];
		pObj->m_fYpos=5;
		pObj->m_nFSM=1;
		gAlienObjects[i].m_pBullet=&gPlasmaObjects[i];

	}

	puts("object setup ok!");
	sleep(1);

	system("clear");

	set_conio_terminal_mode();
	acc_tick=last_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;

        for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_PLANE_BULLET_OBJECT);i++) {
			_S_PLANE_BULLET_OBJECT *pObj=&gPlaneBulletObjects[i];
			pObj->pfApply(pObj,delta_tick);

		}

		for(int i=0;i<6;i++ ){
			_S_ALIEN_OBJECT *pObj=&gAlienObjects[i];
			pObj->pfApply(pObj,delta_tick);

		}

		// _S_Potal_Bullet_Object *pObj=&gPotalBulletObject;
		// 	if(pObj->m_nFSM==0){
        //             double potal_bullet_posx=gPlayerPotal.m_nXpos;
        //             double potal_bullet_posy=gPlayerPotal.m_nYpos;

        //             double target_x=gPlayerObject[0].m_fXpos;
        //             double target_y=gPlayerObject[0].m_fYpos;

		// 			double vx=target_x-potal_bullet_posx;
        //             double vy=target_y-potal_bullet_posy;

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

		// 			Potal_Bullet_Fire(&gPotalBulletObject,gPlayerPotal.m_nXpos,gPlayerPotal.m_nYpos,10,vx,vy,10.0);
		// 	}

		//총알 맞았을때 게임오버
		for(int i=0;i<sizeof(gPlasmaObjects)/sizeof(_S_BULLET_OBJECT);i++) {
			if(gPlasmaObjects[i].m_nFSM!=0) {
				
				double bullet_posx=gPlasmaObjects[i].m_fXpos;
				double bullet_posy=gPlasmaObjects[i].m_fYpos;

				double target_posx=gPlayerObject[0].m_fXpos;
				double target_posy=gPlayerObject[0].m_fYpos;

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

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

				if(dist<0.1) {
					gPlasmaObjects[i].m_nFSM=0;
					gPlayerObject[0].m_nFSM=0;
					gAlienObjects[i].m_nFSM=0;
					system("clear");
					printf("----------------------\r\n");
					printf("      Game over\r\n");
					printf("----------------------\r\n");

					bLoop=0;
				}
			}
		}

		//alien 총알 맞았을때
		for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_PLANE_BULLET_OBJECT);i++) {
			if(gPlaneBulletObjects[i].m_nFSM!=0) {
				double bullet_posx=gPlaneBulletObjects[i].m_fXpos;
				double bullet_posy=gPlaneBulletObjects[i].m_fYpos;

				double target_posx= gAlienObjects[i].m_fXpos;
				double target_posy= gAlienObjects[i].m_fYpos;

				double vx=target_posx-bullet_posx;
				double vy=target_posy-bullet_posy;
				double dist=sqrt(vx*vx+vy*vy);

				if(dist<5.0) {
					gAlienObjects[i].m_nFSM=0;
				}
			}
		}	

		for(int i=0;i<sizeof(gPlasmaObjects)/sizeof(_S_BULLET_OBJECT);i++) {
			gPlasmaObjects[i].pfApply(&gPlasmaObjects[i],delta_tick);

		}

		Potal_Bullet_Apply(&gPotalBulletObject,delta_tick);

        //충돌여부확인-거리계산
        {
            double potal_bullet_posx=gPlayerPotal.m_nXpos;
            double potal_bullet_posy=gPlayerPotal.m_nYpos;

            double target_x=gPlayerObject[0].m_fXpos;
            double target_y=gPlayerObject[0].m_fYpos;

            double angle=0;
    		angle+=(delta_tick*45);
	    	double rad=(angle/180.0)*PI;

			double vx=(target_x-potal_bullet_posx)*cos(rad)-(target_y-potal_bullet_posy)*sin(rad);
			double vy=(target_x-potal_bullet_posx)*sin(rad)+(target_y-potal_bullet_posy)*cos(rad);
		
            double dist=sqrt(vx*vx+vy*vy);

            if(dist<0.1){
                gPotalBulletObject.m_nFSM=0;
            }
         }

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

			acc_bullet_delay_tick=0;

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

			double target_posx=gPlayerObject[0].m_fXpos;
			double target_posy=gPlayerObject[0].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;

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

		//타이밍 계산 
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {
			gotoxy(0,0);
			map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]);
			
			for(int i=0;i<2;i++){
		    	gPlayerObject[i].pfDraw(&gPlayerObject[i],&gScreenBuf[1]);
            }

			Potal_Draw(&gPlayerPotal,&gScreenBuf[1]);
			Potal_Bullet_Draw(&gPotalBulletObject,&gScreenBuf[1]);

            for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_PLANE_BULLET_OBJECT);i++){
				_S_PLANE_BULLET_OBJECT *pObj = &gPlaneBulletObjects[i];
				pObj->pfDraw(pObj,&gScreenBuf[1]);
			}

            for(int i=0;i<6;i++) {
				_S_ALIEN_OBJECT *pObj = &gAlienObjects[i];
				pObj->pfDraw(pObj,&gScreenBuf[1]);
			}

			for(int i=0;i<sizeof(gPlasmaObjects)/sizeof(_S_BULLET_OBJECT);i++){
				gPlasmaObjects[i].pfDraw(&gPlasmaObjects[i],&gScreenBuf[1]);
			}
			
			puts("------------------------------------------------------------\r");
			map_dump(&gScreenBuf[1],Default_Tilepalete);
			puts("------------------------------------------------------------\r");

			puts("move :  w,  a,  s,  d \r");
            puts("player0 fire : j   player1 fire : k");
			puts("quit : q \r");
			acc_tick = 0;
		}

	}

	return 0;

}
Ejemplo n.º 3
0
int main()
{

	system("clear");
	for(int i=0;i<10;i++)
	{
		map_init(&gScreenBuf[i]);
		map_new(&gScreenBuf[i],35,30);
	}
	map_init(&gPlaneModel);
	map_load(&gPlaneModel,"plane5.dat");


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

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

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


	Plane_init(&gTestPlaneObject,&gPlaneModel,17,25);
	

	gTestPlaneObject.m_nFSM = 1;

	double TablePosition[] = {0,3.0,6.0,9.0,12.0,15.0,18.0,21.0,24.0};

	for(int i=0;i< sizeof(gTestBulletObject)/sizeof(_S_BULLET_OBJECT); i++)
	{
		bullet_init(&gTestBulletObject[i],0,0,0,&gBulletModel);
	}
		for(int i=0;i< 10; i++)
	{
		bullet_init(&gTestBulletObject2[i],0,0,0,&gPlasmaModel);
	}
	
	
	for(int i=0;i<10;i++)
	{
		_S_ALIEN_OBJECT *pObj = &gTestAlienObject[i];
		alien_init(pObj,&gAlienModel,1,2);
		pObj->m_fXpos = TablePosition[i];
		pObj->m_fYpos = 3;
		pObj->m_nFSM = 1;
		gTestAlienObject[i].m_pBullet = &gTestBulletObject2[i];
	}


	set_conio_terminal_mode();
	acc_tick=last_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");
			}
			if(ch == 'j') {
				for(int i=0;i<sizeof(gTestBulletObject)/sizeof(_S_BULLET_OBJECT);i++) {
					_S_BULLET_OBJECT *pObj = &gTestBulletObject[i];
					if(pObj->m_nFSM == 0) { //슬립상태라면...
						pObj->pfFire(pObj,
								gTestPlaneObject.m_fXpos,
								gTestPlaneObject.m_fYpos,5,0,-2,10);
						break;
					}

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

		for(int i=0;i<sizeof(gTestBulletObject)/sizeof(_S_BULLET_OBJECT);i++) {
			_S_BULLET_OBJECT *pObj = &gTestBulletObject[i];
			pObj->pfApply(pObj,delta_tick);


		}
		for(int i=0;i<10;i++) {
			_S_ALIEN_OBJECT *pObj = &gTestAlienObject[i];
			pObj->pfApply(pObj,delta_tick);		
	
		}
		for(int i=0;i<10;i++) {
			gTestBulletObject2[i].pfApply(&gTestBulletObject2[i],delta_tick);
		

		if(gTestBulletObject2[i].m_nFSM != 0)	{
	
			double dist = getDistance(&gTestBulletObject2[i],&gTestPlaneObject);

			if(dist < 1.0) {
				gTestBulletObject2[i].m_nFSM = 0;
				gTestPlaneObject.m_nFSM = 0;
			}
		}

}
	

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

			for(int i=0;i<sizeof(gTestBulletObject)/sizeof(_S_BULLET_OBJECT);i++) {
				_S_BULLET_OBJECT *pObj = &gTestBulletObject[i];
				pObj->pfDraw(pObj,&gScreenBuf[1]);	
			}



			for(int i=0;i<10;i++) {

				_S_ALIEN_OBJECT *pObj = &gTestAlienObject[i];
				pObj->pfDraw(pObj,&gScreenBuf[1]);
			}
			for(int i=0;i<4;i++) {

				_S_BULLET_OBJECT *pObj = &gTestBulletObject2[i];
				pObj->pfDraw(pObj,&gScreenBuf[1]);
			}


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

	}

	return 0;

}
Ejemplo n.º 4
0
int main()
{
	set_conio_terminal_mode();
	acc_tick=last_tick=0;
	system("clear");
	map_init(&gScreenBuffer);
	map_new(&gScreenBuffer,45,20);

	map_init(&gBackBuffer);
	map_new(&gBackBuffer,45,20);

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

	map_init(&gF22Bullet);
	map_load(&gF22Bullet,"bullet1.dat");

	map_init(&gPotal);
	map_load(&gPotal,"potal.dat");

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

	Plane_init(&gPlayerPlane,&gF22Raptor,35,17);
	Potal_init(&gPlayerPotal,&gPotal,1,1);
	//Potal_Bullet_init(&gPotalBulletObject,0,0,0,&gPotalBulletModel);

	for(int i=0;i<sizeof(g_bullets)/sizeof(_S_Bullet_Object);i++){
		bullet_init(&g_bullets[i],0,0,0,&gF22Bullet);
	}

	for(int i=0;i<sizeof(gPotalBulletObject)/sizeof(_S_Potal_Bullet_Object);i++){
		Potal_Bullet_init(&gPotalBulletObject[i],0,0,0,&gPotalBulletModel);
	}

	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;

		clock_gettime(CLOCK_MONOTONIC,&work_timer2);
		double cur_tick2 = work_timer2.tv_sec + 
			(double)(work_timer2.tv_nsec * 1e-9);
		double delta_tick2 = cur_tick2 - last_tick2;
		last_tick2 = cur_tick2;

		//실시간 입력
		if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("bye~ \r");
			}
			
			else if(ch=='j'){
				for(int i=0;i<sizeof(g_bullets)/sizeof(_S_Bullet_Object);i++){
					_S_Bullet_Object *pObj=&g_bullets[i];
					if(pObj->m_nFSM==0){	//슬립상태
						bullet_fire(pObj,gPlayerPlane.m_nXpos,gPlayerPlane.m_nYpos,10,5.0);
						break;
					}
				}
			}

			else if(ch=='k'){

				for(int i=0;i<sizeof(gPotalBulletObject)/sizeof(_S_Potal_Bullet_Object);i++){
					_S_Potal_Bullet_Object *pObj=&gPotalBulletObject[i];

					if(pObj->m_nFSM==0){

					double vx,vy,c;
					double angle=0;

					angle+=(delta_tick2*45);
					double rad=(angle/180.0)*PI;

					vx=(gPlayerPlane.m_nXpos-gPlayerPotal.m_nXpos)*cos(rad)-(gPlayerPlane.m_nYpos-gPlayerPotal.m_nYpos)*sin(rad);
					vy=(gPlayerPlane.m_nXpos-gPlayerPotal.m_nXpos)*sin(rad)+(gPlayerPlane.m_nYpos-gPlayerPotal.m_nYpos)*cos(rad);
	/*
					vx=gPlayerPlane.m_nXpos-gPlayerPotal.m_nXpos;
					vy=gPlayerPlane.m_nYpos-gPlayerPotal.m_nYpos;
	*/				
					c=sqrt(vx*vx+vy*vy);
					
					vx/=c; vy/=c;

					Potal_Bullet_Fire(&gPotalBulletObject[i],gPlayerPotal.m_nXpos,gPlayerPotal.m_nYpos,vx,vy,10,0);
					
					

					break;
					}
				}
			}
	
			Plane_Apply(&gPlayerPlane,delta_tick2,ch);

		}

		for(int i=0;i<sizeof(g_bullets)/sizeof(_S_Bullet_Object);i++){
				_S_Bullet_Object *pObj=&g_bullets[i];
				bullet_apply(pObj,delta_tick);
		}
		//apply 위치..
		//Potal_Bullet_Apply(&gPotalBulletObject,delta_tick2);

		//타이밍 계산 
		acc_tick += delta_tick;
		acc_tick2 += delta_tick2;
		if(acc_tick && acc_tick2 > 0.1) {
			
			map_drawTile(&gBackBuffer,0,0,&gScreenBuffer); //클리어 

			//map_drawTile_trn(&gF22Raptor,xpos,ypos,&gScreenBuffer);//오브잭트 출력 
			
			Plane_Draw(&gPlayerPlane,&gScreenBuffer);
			Potal_Draw(&gPlayerPotal,&gScreenBuffer);
			
			for(int i=0;i<sizeof(g_bullets)/sizeof(_S_Bullet_Object);i++){
				_S_Bullet_Object *pObj=&g_bullets[i];
				bullet_draw(pObj,&gScreenBuffer);
			}

			for(int i=0;i<sizeof(gPotalBulletObject)/sizeof(_S_Potal_Bullet_Object);i++){
				_S_Potal_Bullet_Object *pObj=&gPotalBulletObject[i];
				Potal_Bullet_Draw(pObj,&gScreenBuffer);
			}

			gotoxy(0,0);
			puts("---------------------------------------------\r");
			map_dump(&gScreenBuffer,Default_Tilepalete);
			puts("---------------------------------------------\r");

			puts("move : w,a,s,d \r");
			puts("quit : q \r");
			
			acc_tick = 0;
			acc_tick2 = 0;
		}

	}

	return 0;

}
Ejemplo n.º 5
0
int main()
{

	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;

	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");
			}
			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);
		}

		acc_guide_delay_tick += delta_tick;
		if(acc_guide_delay_tick > 2.5 ) {

			acc_guide_delay_tick = 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);
			vx /=dist;
			vy /=dist;

			gTestBullet.m_fvx = vx;
			gTestBullet.m_fvy = vy;

		}
		gTestBullet.pfApply(&gTestBullet,delta_tick);

		
		//타이밍 계산
		acc_tick += delta_tick;
		acc_guide_delay_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_TilePalette);
			acc_tick = 0;
		}

	}

	return 0;

}
Ejemplo n.º 6
0
int main()
{
	set_conio_terminal_mode();
	acc_tick=last_tick=0;
	system("clear");
	map_init(&gScreenBuffer);
	map_new(&gScreenBuffer,35,16);

	map_init(&gBackBuffer);
	map_new(&gBackBuffer,35,16);

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

	map_init(&gF22Bullet);
	map_load(&gF22Bullet,"bullet1.dat");

	Plane_init(&gPlayerPlane,&gF22Raptor,17,10);

	for(int i=0;i< sizeof(g_bullets)/sizeof(S_BULLET_OBJECT) ;i++)
	{
		bullet_init(&g_bullets[i],0,0,0,&gF22Bullet);
	}

	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("\r\n Bye~ \r");
			}
			else if(ch == 'j') {
				for(int i=0;i<sizeof(g_bullets)/sizeof(S_BULLET_OBJECT);i++) {
					S_BULLET_OBJECT *pObj = &g_bullets[i];
					if(pObj->m_nFSM == 0) { //sleep 상태라면-
						bullet_fire(pObj,
								gPlayerPlane.m_nXpos+2,
								gPlayerPlane.m_nYpos,10,5.0);
						break;
					}
				}	
			}
			Plane_Apply(&gPlayerPlane,delta_tick,ch);

		}

		for(int i=0;i<sizeof(g_bullets)/sizeof(S_BULLET_OBJECT);i++) {
			S_BULLET_OBJECT *pObj = &g_bullets[i];
			bullet_apply(pObj,delta_tick);
		}


		//타이밍 계산
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {

			map_drawTile(&gBackBuffer,0,0,&gScreenBuffer); //클리어
			Plane_Draw(&gPlayerPlane,&gScreenBuffer);
			for(int i=0;i<sizeof(g_bullets)/sizeof(S_BULLET_OBJECT);i++) {
				S_BULLET_OBJECT *pObj = &g_bullets[i];
				bullet_draw(pObj,&gScreenBuffer);
			}

			//map_drawTile_trn(&gF22Raptor,xpos,ypos,&gScreenBuffer); //오브젝트 출력
			
			gotoxy(0,0);
			puts("-------------------------------------\r");
			map_dump(&gScreenBuffer,Default_TilePalette);
			puts("-------------------------------------\r");
			
			puts("move : w,a,s,d \r");
			puts("quit : q \r");
			acc_tick = 0;
		}
	}



	return 0;

}
Ejemplo n.º 7
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;

}
Ejemplo n.º 8
0
int main()
{
	set_conio_terminal_mode();
	acc_tick = last_tick = 0;
	system("clear");

	map_init(&gScreenBuffer);
	map_new(&gScreenBuffer,50,23);

	map_init(&gBackBuffer);
	map_new(&gBackBuffer,50,23);

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

	map_init(&gF22Bullet);
	map_load(&gF22Bullet,"bullet1.dat");

	Plane_init(&gPlayerPlane,&gF22Raptor,22,17);	

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


	for(int i=0;i<sizeof(g_bullets)/sizeof(S_BULLET_OBJECT);i++)
	{
		bullet_init(&g_bullets[i],0,0,0,&gF22Bullet);
	}

	int shootx = 25;
	int shooty = 21;
	
	int fire_x = 25;
	int fire_y = 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;

		double vx,vy,c;
		//실시간입력	
		if(kbhit() != 0) {
			char ch = getch();
			if(ch == 'q') {
				bLoop = 0;
				puts("bye~\r");
			}

			else if(ch == 'j') {
				for(int i=0;i<sizeof(g_bullets)/sizeof(S_BULLET_OBJECT);i++) {
					double vx,vy,c;
					vx = gPlayerPlane.m_nXpos - shootx;
					vy = gPlayerPlane.m_nYpos - shooty;
					c = sqrt(vx*vx+vy*vy);
					vx /= c;
					vy /= c;

					S_BULLET_OBJECT *pObj = &g_bullets[i];
					if(pObj->m_nFSM == 0) { //슬립상태라면..
						setColor(33,40);
						bullet_fire(pObj,gPlayerPlane.m_nXpos,gPlayerPlane.m_nYpos,5.0,vx,vy,10);
						setColor(0,0);
						break;
					}
				}


			}

			else if(ch == 'k') {
				double vx,vy,c;
				vx = gPlayerPlane.m_nXpos - fire_x;
				vy = gPlayerPlane.m_nYpos - fire_y;
				c = sqrt(vx*vx+vy*vy);
				vx /= c;
				vy /= c;

				bullet_fire(&gmissile,fire_x,fire_y,5.0,vx,vy,10);
			

			}
		
			Plane_Apply(&gPlayerPlane,delta_tick,ch);
			

		}

		for(int i=0;i<sizeof(g_bullets)/sizeof(S_BULLET_OBJECT);i++) {
			S_BULLET_OBJECT *pObj = &g_bullets[i];
			bullet_apply(pObj,delta_tick);

		}

		bullet_apply(&gmissile,delta_tick);

		//타이밍계산
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {

			map_drawTile(&gBackBuffer,0,0,&gScreenBuffer); //클리어

			//map_drawTile_trn(&gF22Raptor,xpos,ypos,&gScreenBuffer); //오브젝트 출력
			Plane_Draw(&gPlayerPlane,&gScreenBuffer);
		
			bullet_draw(&gmissile,&gScreenBuffer);

			for(int i=0;i<sizeof(g_bullets)/sizeof(S_BULLET_OBJECT);i++)
			{
				S_BULLET_OBJECT *pObj = &g_bullets[i];

					bullet_draw(pObj,&gScreenBuffer);
			}
			
			gotoxy(0,0);
			map_dump(&gScreenBuffer,Default_Tilepalete);
			
			puts("move : w,a,s,d \r");
			puts("quit : q \r");
			
			acc_tick = 0;
		}

	}

	return 0;
}