int main() { system("clear"); for(int i=0;i<2;i++){ map_init(&gScreenBuffer[i]); map_new(&gScreenBuffer[i],35,16); } map_init(&gAlienModel); map_load(&gAlienModel,"alien.dat"); map_init(&gPlasmaModel); map_load(&gPlasmaModel,"plasma.dat"); map_init(&gAlienModel); map_load(&gAlienModel,"alien.dat"); double TablePosition[] = {0,6.0}; for(int i=0;i<2;i++) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; alien_init(pObj,&gAlienModel); pObj->m_fXpos = 0;: pObj->m_fYpos = 2; pObj->m_nFSM = 1; }
void gameStart_Play() { for(int i=0;i<2;i++) { map_init(&gScreenBuf[i]); map_new(&gScreenBuf[i],35,22); } map_init(&gAlienModel); map_load(&gAlienModel,"alien.dat"); map_init(&gBulletModel); map_load(&gBulletModel,"bullet1.dat"); map_init(&gPlaneModel); map_load(&gPlaneModel,"plane1.dat"); map_init(&gLaserModel); map_load(&gLaserModel,"plasma.dat"); alien_init(&gTestAlienObject,&gAlienModel); bullet_init(&gTestBulletObject,0,0,0,&gBulletModel); Plane_init(&gPlaneObject,&gPlaneModel,0,0); laser_init(&gLaserObject,0,0,0,&gLaserModel); gTestAlienObject.m_pBullet = &gTestBulletObject; gPlaneObject.m_fXpos = 17; gPlaneObject.m_fYpos = 20; gPlaneObject.m_nFSM = 1; gTestAlienObject.m_fXpos = -10; gTestAlienObject.m_fYpos = 1; gTestAlienObject.m_nFSM = 1; system("clear"); }
int main() { for(int i=0;i<2;i++){ map_init(&gScreenBuf[i]); map_new(&gScreenBuf[i],45,30); } map_init(&gPlayerModel); map_load(&gPlayerModel,"plane1.dat"); map_init(&gPlasmaModel); map_load(&gPlasmaModel,"plasma.dat"); map_init(&gAlienModel); map_load(&gAlienModel,"alien.dat"); map_init(&gPlaneBulletModel); map_load(&gPlaneBulletModel,"bullet1.dat"); map_init(&gPotal); map_load(&gPotal,"potal.dat"); map_init(&gPotalBulletModel); map_load(&gPotalBulletModel,"potal_bullet.dat"); Plane_init(&gPlayerObject,&gPlayerModel,30,26); Potal_init(&gPlayerPotal,&gPotal,1,1); Potal_Bullet_init(&gPotalBulletObject,0,0,0,&gPotalBulletModel); gPlayerObject.m_nFSM=1; for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_BULLET_OBJECT);i++){ bullet_init(&gPlaneBulletObjects[i],0,0,0,&gPlaneBulletModel); } for(int i=0;i<sizeof(gBulletObjects)/sizeof(_S_BULLET_OBJECT);i++){ bullet_init(&gBulletObjects[i],0,0,0,&gPlasmaModel); } double TablePosition[]={0,10,20,30,40}; for(int i=0;i<5;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=&gBulletObjects[i]; } system("clear"); set_conio_terminal_mode(); acc_tick=last_tick=0; acc_guid_delay_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') { for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_BULLET_OBJECT);i++) { double vx,vy,c; vx=gAlienObjects[i].m_fXpos-gPlayerObject.m_fXpos; vy=gAlienObjects[i].m_fYpos-gPlayerObject.m_fYpos; c=sqrt(vx*vx+vy*vy); vx/=c; vy/=c; _S_BULLET_OBJECT *pObj = &gPlaneBulletObjects[i]; if(pObj->m_nFSM==0) { //슬립상태 pObj->pfFire(pObj,gPlayerObject.m_fXpos,gPlayerObject.m_fYpos,10.0,vx,vy,10.0); break; } } } _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.m_fXpos; double target_y=gPlayerObject.m_fYpos; double vx=target_x-potal_bullet_posx; double vy=target_y-potal_bullet_posy; /* 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); vx/=dist; vy/=dist; Potal_Bullet_Fire(&gPotalBulletObject,gPlayerPotal.m_nXpos,gPlayerPotal.m_nYpos,10,vx,vy,10.0); } gPlayerObject.pfApply(&gPlayerObject,delta_tick,ch); } //apply Potal_Bullet_Apply(&gPotalBulletObject,delta_tick); for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_BULLET_OBJECT);i++) { _S_BULLET_OBJECT *pObj=&gPlaneBulletObjects[i]; pObj->pfApply(pObj,delta_tick); } for(int i=0;i<5;i++ ){ _S_ALIEN_OBJECT *pObj=&gAlienObjects[i]; pObj->pfApply(pObj,delta_tick); } //potal_bullet { double potal_bullet_posx=gPlayerPotal.m_nXpos; double potal_bullet_posy=gPlayerPotal.m_nYpos; double target_x=gPlayerObject.m_fXpos; double target_y=gPlayerObject.m_fYpos; /* double vx=target_x-potal_bullet_posx; double vy=target_y-potal_bullet_posy;*/ 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.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; gPotalBulletObject.m_fvx=vx; gPotalBulletObject.m_fvy=vy; } //총알 맞았을때 게임오버 for(int i=0;i<sizeof(gBulletObjects)/sizeof(_S_BULLET_OBJECT);i++) { if(gBulletObjects[i].m_nFSM!=0) { double bullet_posx=gBulletObjects[i].m_fXpos; double bullet_posy=gBulletObjects[i].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); if(dist<0.1) { gBulletObjects[i].m_nFSM=0; gPlayerObject.m_nFSM=0; gAlienObjects[i].m_nFSM=0; } } } //alien 총알 맞았을때 for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_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(gBulletObjects)/sizeof(_S_BULLET_OBJECT);i++) { gBulletObjects[i].pfApply(&gBulletObjects[i],delta_tick); } //타이밍 계산 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]); Potal_Draw(&gPlayerPotal,&gScreenBuf[1]); for(int i=0;i<5;i++) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; pObj->pfDraw(pObj,&gScreenBuf[1]); } for(int i=0;i<sizeof(gBulletObjects)/sizeof(_S_BULLET_OBJECT);i++){ gBulletObjects[i].pfDraw(&gBulletObjects[i],&gScreenBuf[1]); } for(int i=0;i<sizeof(gPlaneBulletObjects)/sizeof(_S_BULLET_OBJECT);i++){ _S_BULLET_OBJECT *pObj = &gPlaneBulletObjects[i]; pObj->pfDraw(pObj,&gScreenBuf[1]); } puts("---------------------------------------------\r"); map_dump(&gScreenBuf[1],Default_Tilepalete); puts("---------------------------------------------\r"); puts("move : w,a,s,d \r"); puts("quit : q \r"); acc_tick = 0; } } return 0; }
int main() { //srand((float)time(NULL)); //랜덤 함수 for(int i=0;i<2;i++) { map_init(&gScreenBuf[i]); map_new(&gScreenBuf[i],40,25); } map_init(&gPlayerModel); map_load(&gPlayerModel,"plane3.dat"); map_init(&gBulletModel); map_load(&gBulletModel,"plasma1.dat"); map_init(&gAlienModel); map_load(&gAlienModel,"alien1.dat"); map_init(&gMissileModel); map_load(&gMissileModel,"missile.dat"); map_init(&gFishModel); map_load(&gFishModel,"fish1.dat"); //비행기 init Plane_init(&gPlayerObject,&gPlayerModel,20,22); gPlayerObject.m_nFSM = 1; //에일리언 총알 init for(int i=0;i< sizeof(gBulletObject)/sizeof(_S_BULLET_OBJECT) ;i++) { bullet_init(&gBulletObject[i],0,0,0,&gBulletModel); } //비행기 총알 init for(int i=0;i< sizeof(gMissileObject)/sizeof(_S_BULLET_OBJECT) ;i++) { bullet_init(&gMissileObject[i],0,0,0,&gMissileModel); } //에일리언 갯수와 위치 double TablePosition1[] = {0,6.0,30.0,13.0}; for(int i=0;i<4;i++) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; alien_init(pObj,&gAlienModel); pObj->m_fXpos = TablePosition1[i]; pObj->m_fYpos = 2; pObj->m_nFSM = 1; gAlienObjects[i].m_pBullet = &gBulletObject[i]; } //물고기 init //srand(time(NULL)); double TablePosition2[] = {6.0,19.0,31.0}; //double TablePosition3[] = {5.0,15.0}; for(int i=0;i<3;i++) { _S_FISH_OBJECT *pObj = &gFishObject[i]; Fish_init(pObj,&gFishModel); pObj->m_fXpos = TablePosition2[i]; //rand() % 20; 랜덤값을 불러온다 pObj->m_fYpos = 2; pObj->m_nFSM = 2; } set_conio_terminal_mode(); acc_tick=last_tick=0; system("clear"); //플레이상태로 만들기 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') { for(int i=0;i<sizeof(gMissileObject)/sizeof(_S_BULLET_OBJECT);i++) { _S_BULLET_OBJECT *pObj = &gMissileObject[i]; if(pObj->m_nFSM == 0) { //슬립상태라면.... gMissileObject[i].pfFire(pObj,gPlayerObject.m_fXpos,gPlayerObject.m_fYpos, 10,0,-1,5.0); break; } } } //비행기apply gPlayerObject.pfApply(&gPlayerObject,delta_tick,ch); } //비행기총알 apply for(int i=0;i< sizeof(gMissileObject)/sizeof(_S_BULLET_OBJECT) ;i++) { _S_BULLET_OBJECT *pObj = &gMissileObject[i]; pObj->pfApply(pObj,delta_tick); } //에일리언총알 apply for(int i=0;i< sizeof(gBulletObject)/sizeof(_S_BULLET_OBJECT) ;i++) { _S_BULLET_OBJECT *pObj = &gBulletObject[i]; pObj->pfApply(pObj,delta_tick); } //에일리언apply for(int i=0;i<4;i++) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; pObj->pfApply(pObj,delta_tick); } //물고기 apply for(int i=0;i<3;i++) { _S_FISH_OBJECT *pObj = &gFishObject[i]; pObj->pfApply(pObj,delta_tick); } //충돌-에일리언총알에 비행기가 맞을때 for(int i=0;i< sizeof(gBulletObject)/sizeof(_S_BULLET_OBJECT) ;i++) { _S_BULLET_OBJECT *pObj = &gBulletObject[i]; if(pObj->m_nFSM != 0) { double dist = getDistance_1(pObj,&gPlayerObject); if(dist < 0.25) { pObj->m_nFSM = 0; gPlayerObject.m_nFSM = 0; printf("---------------GAME OVER----------------\r\n"); bLoop = 0; } } } //충돌-에일리언이 비행기 총알에 맞을때 for(int i=0;i< sizeof(gMissileObject)/sizeof(_S_BULLET_OBJECT) ;i++) { _S_BULLET_OBJECT *pObj = &gMissileObject[i]; if(pObj->m_nFSM != 0) { double dist = getDistance_2(pObj,&gAlienObjects[i]); if(dist < 4.0) { gAlienObjects[i].m_nFSM = 0; //printf("---------------GAME WIN----------------\r\n"); } } } //충돌-물고기에 비행기가 맞을때 for(int i=0;i<2;i++) { _S_FISH_OBJECT *pObj = &gFishObject[i]; if(pObj->m_nFSM != 0) { double dist = getDistance_3(pObj,&gPlayerObject); if(dist < 1.0) { //pObj->m_nFSM = 0; gPlayerObject.m_nFSM = 0; printf("---------------GAME OVER----------------\r\n"); bLoop = 0; } } } //타이밍 계산 acc_tick += delta_tick; if(acc_tick > 0.1) { gotoxy(0,0); map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]); //비행기draw gPlayerObject.pfDraw(&gPlayerObject,&gScreenBuf[1]); //에일리언 draw for(int i=0;i<4;i++) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; pObj->pfDraw(pObj,&gScreenBuf[1]); } //에일리언 총알 draw for(int i=0;i< sizeof(gBulletObject)/sizeof(_S_BULLET_OBJECT) ;i++) { _S_BULLET_OBJECT *pObj = &gBulletObject[i]; pObj->pfDraw(pObj,&gScreenBuf[1]); } //비행기 총알 draw for(int i=0;i<sizeof(gMissileObject)/sizeof(_S_BULLET_OBJECT);i++) { _S_BULLET_OBJECT *pObj = &gMissileObject[i]; pObj->pfDraw(pObj,&gScreenBuf[1]); } //물고기 draw for(int i=0;i<3;i++) { _S_FISH_OBJECT *pObj = &gFishObject[i]; pObj->pfDraw(pObj,&gScreenBuf[1]); } map_dump(&gScreenBuf[1],Default_Tilepalete); puts("move : w,a,s,d \r"); puts("quit : q \r"); acc_tick = 0; } } return 0; }
int main() { for(int i=0;i<2;i++) { map_init(&gScreenBuf[i]); map_new(&gScreenBuf[i],35,35); } map_init(&gPlayerModel); map_load(&gPlayerModel,"airplane.dat"); map_init(&gBulletModel); map_load(&gBulletModel,"bullet1.dat"); map_init(&gAlienModel); map_load(&gAlienModel,"tank1.dat"); Plane_init(&gPlayerObject,&gPlayerModel,17,10); //bullet_init(&gBulletModel,0,0,0,&gBulletModel); gPlayerObject.m_nFSM = 1; double TablePosition[] = {0,8,16,24}; /* for(int i=0;i<2;i++) { _S_BULLET_OBJECT *pObj = &gBulletObject[i]; bullet_init(pObj,&gBulletObject[i]; pObj->m_nFSM = 1; } */ for(int i=0;i<4;i++) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; alien_init(pObj,&gAlienModel); pObj->m_fXpos = TablePosition[i]; pObj->m_fYpos = 2; pObj->m_nFSM = 1; } /* set_conio_terminal_mode(); acc_tick=last_tick=0; int targetx,targety; int fire_x, fire_y; */ 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; //실시간 입력 /* fire_x = gAlienObjects.m_nXpos; fire_y = gAlienObjects.m_nYpos; targetx = gPlayerObject.m_nXpos; targety = gPlayerObject.m_nypos; */ if(kbhit() != 0) { char ch = getch(); if(ch == 'q') { bLoop = 0; puts("bye~ \r"); } /* else if(ch == 'j') { double vx,vy,c; vx = targetx - fire_x; vy = targety - fire_y; c = sqrt(vx*vx+vy*vy); vx /= c; vy /= c; bullet_fire(&gBulletObject,fire_x,fire_y,10.0,vx,vy,10.0); }*/ gPlayerObject.pfApply(&gPlayerObject,delta_tick,ch); // bullet_apply(&gBulletObject,delta_tick); } for(int i=0;i<4;i++ ) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; pObj->pfApply(pObj,delta_tick); } //타이밍 계산 acc_tick += delta_tick; if(acc_tick > 0.1) { gotoxy(0,0); map_drawTile(&gScreenBuf[0],0,0,&gScreenBuf[1]); // bullet_draw(&gBulletObjects, &gScreenBuf[1]); gPlayerObject.pfDraw(&gPlayerObject,&gScreenBuf[1]); for(int i=0;i<4;i++ ) { _S_ALIEN_OBJECT *pObj = &gAlienObjects[i]; pObj->pfDraw(pObj,&gScreenBuf[1]); } map_dump(&gScreenBuf[1],Default_Tilepalete); acc_tick = 0; } } return 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; }
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; }
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; }
void alien_list_init() { direction = 1; if ((invaders = (alien_list*) malloc(sizeof(alien_list))) == NULL) return; invaders->head = NULL; invaders->last = NULL; invaders->movement_frequency = INITIAL_MOV_FREQ; ufo = NULL; unsigned char row_pos; unsigned char line = 0; unsigned char counter; int x = INITIAL_X_POS; int y = INITIAL_Y_POS; enum alien_type type; for (counter = 0; counter < ALIENS_PER_ROW * ALIEN_ROWS; counter++) { if (counter % ALIENS_PER_ROW == 0) { y += ALIEN_HEIGHT + ALIEN_SPACEMENT; x = INITIAL_X_POS; line++; } else x += ALIEN_WIDTH + ALIEN_SPACEMENT; switch(line){ case 1: type = SMALL; break; case 2: case 3: type = MEDIUM; break; case 4: case 5: type = LARGE; break; } alien_add((alien_init(x, y, type))); } search_new_extreme(1); search_new_extreme(2); //initialize small aliens animation invaders->small_alien = animation_init(); animation_add_by_filename(invaders->small_alien, "small_invader1.bmp"); animation_add_by_filename(invaders->small_alien, "small_invader2.bmp"); //initialize medium aliens animation invaders->medium_alien = animation_init(); animation_add_by_filename(invaders->medium_alien, "medium_invader1.bmp"); animation_add_by_filename(invaders->medium_alien, "medium_invader2.bmp"); //initialize large aliens animation invaders->large_alien = animation_init(); animation_add_by_filename(invaders->large_alien, "large_invader1.bmp"); animation_add_by_filename(invaders->large_alien, "large_invader2.bmp"); //initialize ufo image ufo_img = bitmap_load("ufo.bmp"); invaders->destroy = animation_init(); animation_add_by_filename(invaders->destroy, "explosion.bmp"); }