Exemple #1
0
void pi_spawn_enemy(){
  int x = (int)(random_f()*80);
  int y = (int)(random_f()*10);
  int t = level < 4 ? level : 3;
  pi_insert_entity(eid++, t, x, 75+y);
  pi_count_enemy();
  pi_update_hud();
}
Exemple #2
0
long randomWalkMin(
                     double *best_result,
                     double *xReturn,
                     double *lower,
                     double *upper,
                     double *stepSize,
                     long n_dimen,
                     double target,
                     double (*func)(double *x, long *invalid),
                     long nSamples,
                     double (*random_f)(long iseed)
                     )
{
  double *x, *xBest;
  double result;
  long flag, i, best_found = 0;

  optimFlags = 0;

  if (random_f==NULL)
    random_f = random_1;

  x = tmalloc(sizeof(*x)*n_dimen);
  xBest = tmalloc(sizeof(*xBest)*n_dimen);
  for (i=0; i<n_dimen; i++)
    xBest[i] = xReturn[i];
  *best_result = DBL_MAX;
  while (nSamples--) {
    for (i=0; i<n_dimen; i++) {
      x[i] = xBest[i] + 2*stepSize[i]*(0.5-random_f(0));
      if (lower && x[i]<lower[i])
        x[i] = lower[i];
      if (upper && x[i]>upper[i])
        x[i] = upper[i];
    }
    result = (*func)(x, &flag);
    if (flag==0 && result<*best_result) {
      *best_result = result;
      for (i=0; i<n_dimen; i++)
        xBest[i] = x[i];
      best_found = 1;
      if (result<target)
        break;
    }
    if (optimFlags&OPTIM_ABORT)
      break;
  } 
  if (best_found) {
    for (i=0; i<n_dimen; i++)
      xReturn[i] = xBest[i];
  }
  free(x);
  free(xBest);
  return(best_found);
}
Exemple #3
0
void pi_setup(){
  int r;
  for (int y = 0; y < CELLS_ARRAY_SIZE[1]; y++){
  for (int x = 0; x < CELLS_ARRAY_SIZE[0]; x++){
    pi_buffor[x][y][0] = C_SPACE;
    pi_buffor[x][y][1] = 0;
    pi_buffor[x][y][2] = 15;
    pi_buffor[x][y][3] = 0;
    for (int b = 0; b<LAYERS; b++){
      
      if (b==0){
        r = random_f() < C_STAR_0_DENS ? C_STAR : C_SPACE;
        pi_layers[b][x][y][0] = r;
        pi_layers[b][x][y][1] = 31;
        pi_layers[b][x][y][2] = 8;

      }
      if (b==1){
        r = random_f() < C_STAR_1_DENS ? C_STAR : C_SPACE;
        pi_layers[b][x][y][0] = r;
        pi_layers[b][x][y][1] = 7;
        pi_layers[b][x][y][2] = 7;
      }

      if (b>1){
        pi_layers[b][x][y][0] = C_SPACE;
        pi_layers[b][x][y][1] = 0;
        pi_layers[b][x][y][2] = 0;
      }

      pi_layers[b][x][y][3] = 0;
      pi_layers[b][x][y][4] = 0;

    }
  }}

  pi_draw_hud_element();
  pi_update_hud();
  pi_spawn_player();
  pi_spawn_enemy();
}
Exemple #4
0
void pi_automate(int layer){

  int cell_type;
  int cell_char;
  int cell_x;
  int cell_id;

  if (layer == HUD_LAYER) return;

  for (int y = 0; y < CELLS_ARRAY_SIZE[1]; y++){
  for (int x = 0; x < CELLS_ARRAY_SIZE[0]; x++){

    cell_type = pi_layers[layer][x][y][0]; 
    cell_char = pi_layers[layer][x][y][1]; 

    if (layer == 0 or layer == 1){
      if (cell_type == C_STAR) {
        // clear old space
        pi_layers[layer][x][y][0] = C_SPACE;
        if(y>0){
          // move cell one tile ahead
          pi_layers[layer][x][y-1][0] = cell_type;
          pi_layers[layer][x][y-1][1] = cell_char;
        }else{
          // restart cell in the begining
          cell_x = (int)(random_f()*CELLS_ARRAY_SIZE[0]);
          pi_layers[layer][cell_x][CELLS_ARRAY_SIZE[1]-1][0] = cell_type;
          pi_layers[layer][cell_x][CELLS_ARRAY_SIZE[1]-1][1] = cell_char;
        }
      }
    }

    if (layer == MISSILE_LAYER and cell_type == C_MISSILE){
      cell_id = pi_layers[layer][x][y][4]; 
      if (cell_id > 1){
        pi_move_cell(layer, cell_id, x, y, x, y-1);
      }
    }
  }}

  if (layer == MISSILE_LAYER){
    for (int y = CELLS_ARRAY_SIZE[1]; y >= 0; --y){
    for (int x = 0; x < CELLS_ARRAY_SIZE[0]; x++){
      cell_id = pi_layers[layer][x][y][4]; 
      if (cell_id == 1){
        pi_move_cell(layer, cell_id, x, y, x, y+1);
      }
    }}
  }
}
Exemple #5
0
void pi_ai(int id){
  if(cycles % 10 == 0 or cycles % 3 == 0) pi_shoot_bullet(id);
  if (random_f()<0.5f) pi_move_entitie(id, true, random_f() < 0.5f ? true : false);
}