예제 #1
0
파일: main.c 프로젝트: Zerthick/PebbleMaze
static void init() {
  srand(time(NULL));
  lightup();
  // Create maze
  mazeWidth = 18;
  mazeHeight = 19;
  corridorSize = 8;
  maze = genmaze(mazeWidth, mazeHeight);
  
  // Init Accelerometer
  accel_data_service_subscribe(10, NULL);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
  
  // Init Player Position
  playerX = 0;
  playerY = 0; 
  

  // Create main Window
  s_main_window = window_create();
  window_set_click_config_provider(s_main_window,clickprovider);
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
void Tourelle::animate(long startFrame, long stopFrame, int *startState, int *stopState)
{
	rotate(startFrame,stopFrame,startState[0],stopState[0]);
	elevate(startFrame,stopFrame,startState[1],stopState[1]);
	lightup(startFrame,stopFrame,startState[2],stopState[2]);
}
void Tourelle::lightup(long frame, int intensityPct)
{
	lightup(frame,frame+1,intensityPct,intensityPct);
}
예제 #4
0
파일: main.c 프로젝트: Zerthick/PebbleMaze
static void data_handler(void* out) {
  app_timer_register(30, data_handler, NULL);
  layer_mark_dirty(s_player_layer);
  
  
  //you win
  if (playerY == mazeHeight-1 && playerX == mazeWidth-1 && dx==0 && dy==0){
    vibes_short_pulse();
    load(mazeWidth,mazeHeight,corridorSize);
    return;
  }
  
  int speed = difficulty==1?2:1;
  if(dx!=0 || dy!=0) {
    if(dx<0) dx+=speed;
    if(dx>0) dx-=speed;
    if(dy<0) dy+=speed;
    if(dy>0) dy-=speed;
    
    return;
  }
  
  AccelData* data = malloc(sizeof(*data));
  accel_service_peek(data);
  

  if(data->x*data->x + data->y*data->y > 150*150) {
    //left, right, up, down, just like maze.c
    int xopts[4] = {-1,1,0,0};
    int yopts[4] = {0,0,-1,1};
    int bestopt=0, bestscore=0;
    int xmag = abs(data->x),
        ymag = abs(data->y);
    //app_log(APP_LOG_LEVEL_INFO,"main.c",1337,"mag %i %i",xmag,ymag);
    for(int i=0; i<4; i++) {
      int newx = playerX+xopts[i],
          newy = playerY+yopts[i];
      //bounds checking
      int curscore = (newx>=0 && newy>=0 && newx<mazeWidth && newy < mazeHeight) ? 1 : 0;
      //wall checking
      if(i<2) {//x
        curscore *= 1-maze[getPOS(playerY,(xopts[i]==1?playerX:newx),mazeWidth)].r;
        curscore *= xmag<50?0:xopts[i]*data->x;
      } else {//y
        curscore *= 1-maze[getPOS((yopts[i]==1?playerY:newy),playerX,mazeWidth)].b;
        curscore *= ymag<50?0:-yopts[i]*data->y;
      }
      //app_log(APP_LOG_LEVEL_INFO,"main.c",1338,"score %i %i",i,curscore);
      if(curscore > bestscore) {
        bestopt = i;
        bestscore = curscore;
      }
    }
    if(bestscore>0) {
      lightup();
      playerX += xopts[bestopt];
      playerY += yopts[bestopt];
      dx -= xopts[bestopt]*(corridorSize-speed);
      dy -= yopts[bestopt]*(corridorSize-speed);
    }
  }
  free(data);
}