コード例 #1
0
ファイル: ship.c プロジェクト: benlemasurier/asteroids
void
ship_fire(SHIP *ship, ALLEGRO_TIMER *timer)
{
  LIST *head = NULL;
  MISSILE *missile = NULL;
  VECTOR position;

  /* full button press required for each missile */
  if(ship->fire_debounce)
    return;

  /* find an inactive missile to launch */
  head = list_first(ship->missiles);
  while(head && !missile) {
    MISSILE *m = (MISSILE *) head->data;
    if(!m->active)
      missile = m;

    head = head->next;
  }

  /* all missiles in use? */
  if(missile == NULL)
    return;

  position.x = ship->position->x;
  position.y = ship->position->y;

  missile_fire(missile, &position, ship->angle, timer);
  ship->fire_debounce = true;
}
コード例 #2
0
ファイル: ex1.c プロジェクト: chaem/test
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(&gMissile);
	map_load(&gMissile,"plasma.dat");
	missile_init(&gMissileObject,0,0,0,&gMissile);

	system("clear");	

	//target
	int targetx, targety;
	targety = 3;
	targetx = 2; 

	int fire_x = 24;
	int fire_y = 12;


	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(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;
		
				missile_fire(&gMissileObject,
				fire_x, fire_y,
				10.0, vx, vy,
				10);
					
			}
			else if (ch == 'a') {
				targetx -= 1;

			}
			else if (ch == 'd') {
				targetx += 1;

			}

		}

		// apply location
		missile_apply(&gMissileObject,delta_tick);

		// time calculate
		acc_tick += delta_tick;
		if(acc_tick > 0.1) {
			//puts("tick...\r");
			map_drawTile(&gScreenBuffer[0],0,0,&gScreenBuffer[1]);
			missile_draw(&gMissileObject,&gScreenBuffer[1]);	
			gotoxy(0,0);
			
			map_PutTile(&gScreenBuffer[1],fire_x,fire_y,1);
			map_PutTile(&gScreenBuffer[1],targetx,targety,5);

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

	}

	return 0;

}