Exemple #1
0
void Character::move()
{
    //Move the dot left or right
    m_x += xVel;
    if(xVel > 0)
    {
        change_image(RIGHT);
    }
    if(xVel < 0)
    {
        change_image(LEFT);
    }

   // check if not out of bounds
   if( m_x < 0)
   {
       m_x = 0;
   }

   if( (m_x + m_width) > SCREEN_WIDTH )
   {
        m_x = SCREEN_WIDTH - m_width;
   }

    //Move the dot left or right
    m_y += yVel;

    if(yVel > 0)
    {
        change_image(DOWN);
    }

    if(yVel < 0)
    {
        change_image(UP);
    }

   // check if not out of bounds
   if( m_y < 0)
   {
       m_y = 0;
   }

   if( (m_y + m_height) > SCREEN_HEIGHT )
   {
        m_y = SCREEN_HEIGHT - m_height;
   }

}
static void wakeup_handler(WakeupId id, int32_t reasonCode) {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Wakeup happened");
  change_state();
  uint32_t image = image_for_state(current_state);
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Image: %u", (unsigned int)image);
  change_image(image);
  
  schedule_wake();
}
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(s_main_window);
  GRect bounds = layer_get_frame(window_layer);

  s_image_layer = layer_create(bounds);
  layer_set_update_proc(s_image_layer, layer_update_callback);
  layer_add_child(window_layer, s_image_layer);

  change_image(image_for_state(current_state));
}