예제 #1
0
void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	init_material(Ka, Kd, Ks, 100 * Kp, Red, Green, Blue);

	glTranslatef(xpos / 500.0, ypos / 500.0, zpos / 500.0);
	glRotatef(xangle, 1.0, 0.0, 0.0);
	glRotatef(yangle, 0.0, 1.0, 0.0);
	glRotatef(zangle, 0.0, 0.0, 1.0);

	draw_ball(Px, Py, Pz, Radius);

	init_material(Ka, Kd, Ks, 100 * Kp, bred, bgreen, bblue);

	draw_bat(Bx, By, Bz, Bradius, 10);

	draw_stick();

	glFlush();
	glutSwapBuffers();
}
예제 #2
0
/* Called whenever a ball is lost, either by it falling off the bottom of the
 * screen, or the player pressing the "suicide key". */
void lost_ball(nbstate *state)
{
	/* Decrement the balls count and if there are none left: */
	if(!state->numballs--) {
		/* Go to the "game lost" state and update the high score if
		 * appropriate: */
		state->state = STATE_GAMELOST;
		/* Update the high score and save it if necessary: */
		save_hiscore(state);
		/* This could probably be done better by just drawing the
		 * splash- set_level_active() redraws the entire game area: */
		set_level_active(state);
		return;
	}

	/* Erase the balls line at the top of the screen: */
	draw_background(state, 0, state->scores.h, state->canvaswidth,
			state->ball.s->h + (BALLS_BORDER * 2));
	/* Draw the balls again, but with one less than there was before: */
	draw_balls(state);
	/* Copy the balls row to the output window: */
	draw_canvas(state, 0, state->scores.h, state->canvaswidth,
				state->ball.s->h + (BALLS_BORDER * 2));
	/* Park the new ball and erase the old one: */
	park_ball(state);
	move_ball(state);
	/* Redraw the bat. This is a bit of a hack because sometimes when the
	 * ball falls below the top of the bat on its way to the bottom of the
	 * screen it can clip the bat and erase a bit of it. This redraws the
	 * bat to hide that: */
	draw_bat(state);
	/* Copy the redrawn bat to the output window: */
	draw_canvas(state, state->batx - (state->batwidths[state->bat] / 2),
			state->canvasheight - state->batheight,
			state->batwidths[state->bat], state->batheight);
}
예제 #3
0
파일: watchface.c 프로젝트: as-j/timeslider
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;
  
}
예제 #4
0
/* Make the current level active. This mainly consists of destroying the old
 * background image and loading the new one, destroying the splash image,
 * possibly loading a new splash image depending on the state, copying over the
 * new level data into the current level state, then redrawing the entire game
 * area. */
void set_level_active(nbstate *state)
{
	int i;
	level *lev;
	grid *g, *gg;
	int bgchanged;
	sprite *s = NULL;
	power *p, *pnext;
	GR_PIXMAP_ID ctmp;
	char *backgroundfile;

	/* Destroy the old splash image sprite: */
	destroy_sprite(state, state->splash);

	/* If we're on the title screen: */
	if(state->state == STATE_TITLESCREEN) {
		/* Set the background file to the title background file: */
		backgroundfile = state->titlebackground;
		/* Set the tiled state appropriately: */
		state->backgroundtiled = state->titlebackgroundtiled;
		/* Try to load the title screen splash graphic (if it doesn't
		 * work nothing bad will happen- load_sprite() will print an
		 * error message and draw_splash() will not draw anything.) */
		state->splash = load_sprite(state, state->titlesplash, -1, -1);
	} else { /* Not on the title screen. */
		/* Find the level structure for the current level number: */
		for(lev = state->levels, i = 1; i < state->level;
				lev = lev->next, i++);
		/* Set the current number of bricks and background info: */
		state->numbricks = lev->numbricks;
		backgroundfile = lev->backgroundname;
		state->backgroundtiled = lev->backgroundtiled;
		/* If we're in the "game won" state, try to load the appropriate
		 * splash image: */
		if(state->state == STATE_GAMEWON) {
			state->splash = load_sprite(state, state->gamewonsplash,
									-1, -1);
		/* If we're in the "game lost" state, try to load the
		 * appropriate splash image: */
		} else if(state->state == STATE_GAMELOST) {
			state->splash = load_sprite(state,
						state->gamelostsplash, -1, -1);
		} else { /* We must be in the STATE_RUNNING state. */
			/* No splash image: */
			state->splash = NULL;
			/* Copy this levels game grid into the current game
			 * grid: */
			g = state->grid;
			gg = lev->grid;
			for(i = 0; i < state->width * state->height; i++)
				*g++ = *gg++;
		}
	}

	/* If there was a background filename specified: */
	if(backgroundfile) {
		/* If there is a current background sprite with a filename
		 * and the filename is the same as the new background
		 * filename, the background file has not changed. Otherwise,
		 * assume that it has. */
		if(state->background && state->background->fname &&
				!strcmp(backgroundfile,
					state->background->fname))
			bgchanged = 0;
		else bgchanged = 1;
	/* No background filename was specified, so assume it has changed (to
	 * a blank black frame): */
	} else bgchanged = 1;

	/* If the background image has changed, try to load the new one: */
	if(bgchanged && !(s = load_sprite(state, backgroundfile, -1, -1))) {
		/* If it fails, try to make a new empty sprite and colour it
		 * in black (the 16*16 pixels is purely arbitrary- make it too
		 * large and it uses a lot of memory, make it too small and
		 * we spend ages painting hundreds of tiny tiles onto the
		 * background. */
		if(!(s = make_empty_sprite(state, backgroundfile, 16, 16))) {
			/* If that fails too (shouldn't happen under normal
			 * circumstances), issue a warning and keep the old
			 * background image sprite: */
			s = state->background;
		} else {
			/* Fill in the new dummy background black: */
			GrSetGCForeground(state->gc, GR_COLOR_BLACK);
			GrFillRect(s->p, state->gc, 0, 0, 16, 16);
			/* Make it tiled. FIXME: it would make more sense to
			 * have a "no background image" option which simply
			 * coloured in the background black: */
			state->backgroundtiled = 1;
		}
	}

	/* If we have made a new background image sprite: */
	if(bgchanged && s != state->background) {
		/* Destroy the old one: */
		destroy_sprite(state, state->background);
		/* Set the background to the new sprite: */
		state->background = s;
	}

	/* Empty the list of power boxes: */
	for(p = state->powers; p; p = pnext) {
		pnext = p->next;
		free(p);
	}
	state->powers = NULL;

	/* If fading has been requested, we want to fade the new level in, so
	 * swap the canvasses around so the current screen is the old canvas,
	 * then draw the new screen and make the new canvas, then start the
	 * process of fading it in: */
	if(state->faderate) {
		/* Swap the canvasses around: */
		ctmp = state->oldcanvas;
		state->oldcanvas = state->canvas;
		state->canvas = ctmp;

		/* Remember the state we're fading into: */
		state->nextstate = state->state;

		/* Go into the fading state: */
		state->state= STATE_FADING;

		/* Initialise the fade level as completely opaque: */
		state->fadelevel = 256;
	}

	/* Clear the whole game area to the background image: */
	draw_background(state, 0, 0, state->canvaswidth, state->canvasheight);

	/* If we're not on the title screen or fading to the title screen: */
	if(state->state != STATE_TITLESCREEN && !(state->state == STATE_FADING
				&& state->nextstate == STATE_TITLESCREEN)) {
		/* Draw the bricks: */
		draw_bricks(state, 0, 0, state->canvaswidth,
						state->canvasheight);
		draw_scores(state); /* Draw the scores bar. */
		draw_balls(state); /* Draw the row of balls. */
		draw_bat(state); /* Draw the bat. */
		/* Draw the current ball unless the game is over: */
		if(state->state != STATE_GAMELOST &&
				state->state != STATE_GAMEWON)
			draw_ball(state);
	}

	draw_splash(state); /* Draw the splash graphic (if there is one). */

	/* If we're fading, remember the new canvas and generate the first
	 * frame of the fade: */
	if(state->state == STATE_FADING) {

		/* Swap the canvasses around: */
		ctmp = state->newcanvas;
		state->newcanvas = state->canvas;
		state->canvas = ctmp;

		/* Reduce the opacity: */
		state->fadelevel -= state->faderate;

		/* Generate the first frame: */
		GrCopyArea(state->canvas, state->gc, 0, 0, state->canvaswidth,
				state->canvasheight, state->newcanvas, 0, 0, 0);
		GrCopyArea(state->canvas, state->gc, 0, 0, state->canvaswidth,
				state->canvasheight, state->oldcanvas, 0, 0,
				GR_CONST_BLEND | state->fadelevel);
	}

	/* Copy the entire redrawn canvas to the output window: */
	draw_canvas(state, 0, 0, state->canvaswidth, state->canvasheight);
}