void update_man(void){ int x, y; Oldman.pos.x = Curman.pos.x; Oldman.pos.y = Curman.pos.y; Curman.pos.x -= Curman.vel.x; Curman.pos.y += Curman.vel.y; if (left_key && right_key) ; else if (left_key){ Curman.pos.y -= bspeed * 3; /* if (Curman.state == Stand && Curstep[Curman.stone].type == Roll) Curman.pos.y += bspeed; */ } else if (right_key) Curman.pos.y += bspeed * 3; y = Curman.pos.y >> frac; if (y <= Halwid+1) Curman.pos.y = (Halwid+1) << frac; else if (y + Halwid >= 140) Curman.pos.y = (140-Halwid) << frac; if (Curman.state == Stand) jumpcheck(); else landcheck(); x = Curman.pos.x >> frac; if (x > 195){ alive = FALSE; Curman.pos.x = 187 << frac; } if (alive) clear_man(); clear_step(); draw_man(); draw_step(); if (x <= 11 && Curman.state != Jump){ Curman.state = Jump; Curman.blood -= 3; if (Curman.blood <= 0) alive = FALSE; Curman.vel.x = 0; } }
static unsigned long critical_draw (Display *dpy, Window window, void *closure) { struct state *st = (struct state *) closure; if (st->eraser) { st->eraser = erase_window (st->dpy, st->window, st->eraser); return st->delay_usecs; } /* for (d_i_batch = batchcount; d_i_batch; d_i_batch--) */ { /* Set color */ if ((st->d_i_batch % st->lines_per_color) == 0) { st->d_i_color = (st->d_i_color + 1) % st->d_n_colors; st->gcv.foreground = st->d_colors[st->d_i_color].pixel; XChangeGC (st->dpy, st->fgc, GCForeground, &st->gcv); } assert(st->d_pos >= 0 && st->d_pos < st->settings.trail); model_step (st->model, &st->history[st->d_pos]); draw_step (st, st->fgc, st->d_pos); /* we use the history as a ring buffer, but don't start erasing until we've d_wrapped around once. */ if (++st->d_pos >= st->settings.trail) { st->d_pos -= st->settings.trail; st->d_wrapped = 1; } if (st->d_wrapped) { draw_step (st, st->bgc, st->d_pos+1); } } st->d_i_batch--; if (st->d_i_batch < 0) st->d_i_batch = st->batchcount; else return st->delay_usecs; st->i_restart = (st->i_restart + 1) % st->n_restart; if (st->i_restart == 0) { /* Time to start a new simulation, this one has probably got to be a bit boring. */ free_colormap (st, &st->d_colors, st->d_n_colors); setup_colormap (st, &st->d_colors, &st->d_n_colors); st->eraser = erase_window (st->dpy, st->window, st->eraser); model_initialize (st->model); model_step (st->model, &st->history[0]); st->d_pos = 1; st->d_wrapped = 0; st->d_i_batch = st->batchcount; } return st->delay_usecs; }
//-------- Begin of function Lightning::draw_section ----------// void Lightning::draw_section(VgaBuf *vgabuf, double portion) { while( progress() < ( portion< 1.0 ? portion : 1.0 ) ) draw_step(vgabuf); }
static void canvas_update_proc(Layer *this_layer, GContext *ctx) { GRect bounds = layer_get_bounds(this_layer); uint16_t ms_start = time_ms(NULL, NULL); graphics_context_set_antialiased(ctx, true); if (!isBtConnected) { graphics_context_set_fill_color(ctx, GColorDukeBlue); graphics_fill_rect(ctx, bounds, 0, GCornerNone); } else { graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_rect(ctx, bounds, 0, GCornerNone); } graphics_context_set_fill_color(ctx, GColorBlack); uint16_t ms_fill = time_ms(NULL, NULL); graphics_context_set_stroke_color(ctx, COLOR_FALLBACK(GColorRed, GColorWhite)); #if defined(PBL_PLATFORM_APLITE) || defined(PBL_PLATFORM_DIORITE) graphics_context_set_stroke_width(ctx, 1); #else graphics_context_set_stroke_width(ctx, 3); #endif graphics_draw_line(ctx, GPoint(bounds.size.w/2, 0), GPoint(bounds.size.w/2, bounds.size.h)); graphics_context_set_stroke_color(ctx, GColorWhite); int hour_loc = bounds.size.h/2; if(ctick_time->tm_min < 20) draw_hour(this_layer, ctx, -1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); draw_hour(this_layer, ctx, 0, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); draw_hour(this_layer, ctx, 1, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); if(ctick_time->tm_min > 50) draw_hour(this_layer, ctx, 2, tz2, hour_loc, FONT_KEY_ROBOTO_BOLD_SUBSET_49, 49); graphics_context_set_stroke_width(ctx, 1); uint16_t ms_hour = time_ms(NULL, NULL); draw_minutes(this_layer, ctx, bounds.size.h/2+49/2+5); uint16_t ms_day = time_ms(NULL, NULL); int day_loc = bounds.size.h/2-49/2-12; draw_day(this_layer, ctx, -1, day_loc); draw_day(this_layer, ctx, 0, day_loc); draw_day(this_layer, ctx, 1, day_loc); draw_day(this_layer, ctx, 2, day_loc); draw_day_ticks(this_layer, ctx, bounds.size.h/2-49/2-12); if (temp != INVALID_TEMP) { draw_temp(this_layer, ctx, bounds.size.h/2+75); } getWeather(); getForecast(); uint16_t ms_end = time_ms(NULL, NULL); draw_bat(this_layer, ctx, 0); #if defined(PBL_HEALTH) // Check step data is available HealthServiceAccessibilityMask mask = health_service_metric_accessible(HealthMetricStepCount, time_start_of_today(), cur_time); if(mask & HealthServiceAccessibilityMaskAvailable) { // Data is available! int total_steps = (int)health_service_sum_today(HealthMetricStepCount); draw_step(this_layer, ctx, 22, total_steps); } time_t end_time = time(NULL); time_t start_time = end_time - 600; HealthServiceAccessibilityMask hr = health_service_metric_accessible(HealthMetricHeartRateBPM, start_time, end_time); if (hr & HealthServiceAccessibilityMaskAvailable) { uint32_t bpm = health_service_peek_current_value(HealthMetricHeartRateBPM); APP_LOG(APP_LOG_LEVEL_INFO, "HR: %d", (int)bpm); draw_bpm(this_layer, ctx, 9, bpm); } #endif static int repaints = 0; ++repaints; ms_fill = ms_fill < ms_start ? ms_fill + 1000 : ms_fill; ms_hour = ms_hour < ms_start ? ms_hour + 1000 : ms_hour; ms_day = ms_day < ms_start ? ms_day + 1000 : ms_day; ms_end = ms_end < ms_start ? ms_end + 1000 : ms_end; static uint16_t tt_max = 0; if ((ms_end-ms_start) > tt_max) tt_max = ms_end-ms_start; }