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