コード例 #1
0
ファイル: fold.c プロジェクト: cwarden/tuxpaint
void fold_release(magic_api * api, int which,
	           SDL_Surface * canvas, SDL_Surface * snapshot,
	           int x, int y, SDL_Rect * update_rect)
{
  int a,b;
  SDL_Surface * temp, *temp2;

  x=fold_x;
  y=fold_y;
  fold_ox=fold_oy=0;
  SDL_BlitSurface(snapshot, 0, canvas, 0);
  switch (corner)
    {
    case 1:
      translate_xy(canvas,x,y,&a,&b,90);
      translate_coords(canvas,90);
      temp=rotate(api, canvas, 90);
      fold_draw (api, which, temp, snapshot, a, b,update_rect);
      temp2=rotate(api,temp,270);
      SDL_BlitSurface(temp2,0,canvas,0);
      SDL_FreeSurface(temp);
      SDL_FreeSurface(temp2);
      break;

    case 2:
      fold_draw (api, which, canvas, snapshot, x,y,update_rect);
      break;
      
    case 3:
	translate_xy(canvas,x,y,&a,&b,270);
	translate_coords(canvas,270);
	temp=rotate(api, canvas, 270);
	fold_draw (api, which, temp, snapshot, a, b,update_rect);
	temp2=rotate(api,temp,90);
	SDL_BlitSurface(temp2,0,canvas,0);
	SDL_FreeSurface(temp);
	SDL_FreeSurface(temp2);
	break;

    case 4:
      	translate_xy(canvas,x,y,&a,&b,180);
	translate_coords(canvas,180);
	temp=rotate(api, canvas, 180);
	fold_draw (api, which, temp, snapshot, a, b,update_rect);
	temp2=rotate(api,temp,180);
	SDL_BlitSurface(temp2,0,canvas,0);
	SDL_FreeSurface (temp);
	SDL_FreeSurface (temp2);
	break;
    }

  update_rect->x=update_rect->y=0;
  update_rect->w=canvas->w;
  update_rect->h=canvas->h;
  api->playsound(fold_snd, (x * 255) / canvas->w, 255);
}
コード例 #2
0
void shoot(int y, int x, int y_offset, int x_offset, board_t* board, bool turn_a){
    coords_t coords = translate_coords(y,x, y_offset, x_offset, board);
    if (coords.fits && (turn_a == coords.player_a)){
        cell_t **battlefield;
        if (coords.player_a){
            battlefield = board->player_a;
        } else {
            battlefield = board->player_b;
        }
        battlefield[coords.x][coords.y] |= SHOT;

    }
}
コード例 #3
0
void place(int y, int x, int y_offset, int x_offset, board_t* board){
    coords_t coords = translate_coords(y,x, y_offset, x_offset, board);
    if (coords.fits){
        cell_t **battlefield;
        if (coords.player_a){
            battlefield = board->player_a;
        } else{
            battlefield = board->player_b;
        }
        if (is_allowed(coords.y, coords.x, battlefield, board->length) && try_obeys(coords.y, coords.x,battlefield, board->length)){
            start_replace(coords.y, coords.x, battlefield, board->length);
        }
    }
}
コード例 #4
0
void remove_at(int y, int x, int y_offset, int x_offset, board_t* board){
    coords_t coords = translate_coords(y,x, y_offset, x_offset, board);
    if (coords.fits){
        cell_t **battlefield;
        if (coords.player_a){
            battlefield = board->player_a;
        } else{
            battlefield = board->player_b;
        }
        if (battlefield[coords.x][coords.y] & SHIP){
            int y_dir = 0, x_dir =0;
            battlefield[coords.x][coords.y] = EMPTY;
            for(int i=0; i<4; i++){
                get_direction(coords.y, coords.x, &y_dir, &x_dir, battlefield, board->length);
                if (y_dir == 0 && x_dir == 0){
                    break;
                } else {
                    replace(coords.y+y_dir, coords.x+x_dir, y_dir, x_dir, battlefield, board->length, EMPTY);
                }
            }
        }
    }
}
コード例 #5
0
ファイル: read_gmx.c プロジェクト: arcan1s/moldyn
/**
 * @fn rw_gmx
 */
int rw_gmx (const char *input, const int step, const char *output, const int num_types, 
            const int *num_mol, const int *num_atoms, const char *ch_atom_types, 
            const int *atom_types, float *coords)
{
  char filename[256], tmp_str[256];
  float cell[3], trans[3], r_min;
  int atoms, i, j, k, l, m, n;
  FILE *f_inp;
  
/* filename               output file name
 * cell                   cell size
 * trans                  translated coordinates
 * r_min                  minimal radius
 * atom                   number of atoms
 * f_inp                  input file
 */
  
  f_inp = fopen (input, "r");
  if (f_inp == NULL)
    return 1;
  
  for (i=0; i<step; i++)
  {
// initial variables
    sprintf (filename, "%s.%03i", output, i+1);
    fgets (tmp_str, 256, f_inp);
    fgets (tmp_str, 256, f_inp);
    sscanf (tmp_str, "   natoms=%i%s", &atoms, tmp_str);
    fgets (tmp_str, 256, f_inp);
    fgets (tmp_str, 256, f_inp);
    sscanf (tmp_str, "      box[    0]={%f%s", &cell[0], tmp_str);
    fgets (tmp_str, 256, f_inp);
    sscanf (tmp_str, "      box[    1]={%f,%f%s", &cell[1], &cell[1], tmp_str);
    fgets (tmp_str, 256, f_inp);
    sscanf (tmp_str, "      box[    2]={%f,%f,%f%s", &cell[2], &cell[2], &cell[2], tmp_str);
    fgets (tmp_str, 256, f_inp);
    for (j=0; j<3; j++)
      cell[j] = 10 * cell[j];
// coordinates
    for (j=0; j<atoms; j++)
    {
      fgets (tmp_str, 256, f_inp);
      sscanf (tmp_str, "      x[%i]={%f,%f,%f%s", &k, &coords[3*j+0], &coords[3*j+1], 
              &coords[3*j+2], tmp_str);
      for (k=0; k<3; k++)
        coords[3*j+k] = 10 * coords[3*j+k];
    }
// velocities
    fgets (tmp_str, 256, f_inp);
    for (j=0; j<atoms; j++)
      fgets (tmp_str, 256, f_inp);
    
// processing coordinates
    j = 0;
    while (j < atoms)
      for (k=0; k<num_types; k++)
        for (l=0; l<num_mol[k]; l++)
        {
          for (m=1; m<num_atoms[k]; m++)
            for (n=0; n<3; n++)
            {
              r_min = fabs (coords[3*(j+m)+n] - coords[3*j+n]);
              translate_coords (coords[3*(j+m)+n], cell[n], trans);
              if (fabs (trans[1] - coords[3*j+n]) < r_min)
                coords[3*(j+m)+n] = trans[1];
              if (fabs (trans[2] - coords[3*j+n]) < r_min)
                coords[3*(j+m)+n] = trans[2];
            }
          j += num_atoms[k];
        }
    j = 0;
    while (j < atoms)
      for (k=0; k<num_types; k++)
        for (l=0; l<num_mol[k]; l++)
        {
          for (m=0; m<3; m++)
          {
            while (coords[3*j+m] > cell[m]/2)
              for (n=j; n<j+num_atoms[k]; n++)
                coords[3*n+m] -= cell[m];
            while (coords[3*j+m] < -cell[m]/2)
              for (n=j; n<j+num_atoms[k]; n++)
                coords[3*n+m] += cell[m];
          }
          j += num_atoms[k];
        }
    
// write to output
    printing_trj (filename, atoms, num_types, num_mol, num_atoms, ch_atom_types, 
                  atom_types, coords, cell);
  }
  
  fclose (f_inp);
  
  return 0;
}