Exemplo n.º 1
0
int		take_it(t_player *player, t_map *map)
{
  int		pos[2];

  pos[0] = 0;
  pos[1] = 0;
  search_pos(map, pos, KEY_CHAR);
  if (pos[0] == player->position.x && pos[1] == player->position.y)
    {
      printf("You got a key.\n");
      map->map[pos[1]][pos[0]] = '.';
      player->item.key = 1;
      return (1);
    }
  pos[0] = 0;
  pos[1] = 0;
  search_pos(map, pos, EXIT_CHAR);
  if (pos[0] == player->position.x 
      && pos[1] == player->position.y 
      && player->item.key)
    {
      printf("\033[36mLevel complete!\033[00m\n");
      return (0);
    }
  return (1);
}
Exemplo n.º 2
0
void		init(t_player *player, t_map *map, t_image *img)
{
  int		pos[2];

  pos[0] = 0;
  pos[1] = 0;
  search_pos(map, pos);
  player->position.x = pos[0];
  player->position.y = pos[1];
  player->move = 5;
  player->life = 3;
  player->weapon = 0;
  player->direction = 1;
  player->img_lenght = 10;
  player->img_height = 10;
  player->player_img1 = img->hero1;
  player->player_img2 = img->hero2;
  player->player_img3 = img->hero3;
  player->player_img4 = img->hero4;
  player->player_img5 = img->hero5;
  player->player_img6 = img->hero6;
}
Exemplo n.º 3
0
void
DeadRec::UpdatePosition(const DeadRecInformation info)
{
	if(!sample_set) return;

//	OSYSPRINT(("DeadRec::UpdatePosition() %f %f %f\n",info.dx,info.dy,info.dt));
	double x,y,t;
	x = info.dx;y = info.dy;t = info.dt*DEGTO;
	
	int max_ex = abs((int)(x*0.1))+1;
	int max_ey = abs((int)(y*0.1))+1;
	int max_et = abs((int)(t*0.25))+2;
	int max_ex2 = max_ex*2+1;
	int max_ey2 = max_ey*2+1;
	int max_et2 = max_et*2+1;

	double ex,ey,et;
	unsigned int a;
	int tmp_x,tmp_y;


//	double prob_distribution[SAMPLE_NUMBER+1];
	static int prob_distribution[SAMPLE_NUMBER+1];
	double prob_sum = 0.0;
	static int old_x[SAMPLE_NUMBER];
	static int old_y[SAMPLE_NUMBER];
	static unsigned int old_t[SAMPLE_NUMBER];
	prob_distribution[0] = 0;

	for(int i=0;i<SAMPLE_NUMBER;i++)
	{
		prob_sum += sample->sample[i].m_w;
		prob_distribution[i+1] = (int)(prob_sum*MAX_WEIGHT);
		old_x[i] = sample->sample[i].m_x;
		old_y[i] = sample->sample[i].m_y;
		old_t[i] = sample->sample[i].m_t;
	}
	
	for(int i=0;i<SAMPLE_NUMBER;i++)
	{
		int index = search_pos(0,SAMPLE_NUMBER+1,USHORT_RAND15b,prob_distribution);

		a = old_t[index]&MCLSample::m_nSinCosMask;

		ex = x + (USHORT_RAND15b%max_ex2-max_ex);
		ey = y + (USHORT_RAND15b%max_ey2-max_ey);
		et = t + (USHORT_RAND15b%max_et2-max_et);

		tmp_x = old_x[index] + (int)(ex*(MCLSample::m_dCos[a]) - ey*(MCLSample::m_dSin[a]));
		tmp_y = old_y[index] + (int)(ex*(MCLSample::m_dSin[a]) + ey*(MCLSample::m_dCos[a]));

		int ax = (int)abs(tmp_x);
		int ay = (int)abs(tmp_y);
		bool flag_normal = true;

		if(ax > FIELD_MAX_X + FIELD_REMAIN_X + ROBOT_LENGTH)		flag_normal = false;
		if(ay > FIELD_MAX_Y + FIELD_REMAIN_Y + ROBOT_LENGTH)		flag_normal = false;
		if(flag_normal)
		{
			sample->sample[i].m_x = tmp_x;
			sample->sample[i].m_y = tmp_y;
			sample->sample[i].m_t = old_t[index] + (int)et + 512;
			sample->sample[i].m_t &= MCLSample::m_nSinCosMask;
		}
		else
		{
			sample->sample[i].m_x = tmp_x;
			sample->sample[i].m_y = tmp_y;
			sample->sample[i].m_t = old_t[index] + (int)et;
			sample->sample[i].m_t &= MCLSample::m_nSinCosMask;
		}
		sample->sample[i].m_w = 1.0 / (double)SAMPLE_NUMBER;
	}
	state.self.position = sample->CalcAverageAndStdDev();
}