コード例 #1
0
ファイル: brick.c プロジェクト: Kvasshtain/uos-embedded
/* Destroy the specified brick, clear the relevant piece of the game area,
 * increment the score by the appropriate amount, decrement the current
 * number of bricks, and if we run out of bricks, increment to the next level.
 * Returns 0 if the level wasn't incremented and 1 if it was. */
static int destroy_brick(nbstate *state, grid *g)
{
	int immutable;

	/* Wipe the canvas where the brick is back to the background: */
	draw_background(state, g->x, g->y, state->brickwidth,
			state->brickheight);
	/* Redraw any powers we may just have accidentally erased: */
	redraw_powers(state, g->x, g->y, state->brickwidth, state->brickheight);
	/* Copy the affected area to the output window: */
	draw_canvas(state, g->x, g->y, state->brickwidth,
			state->brickheight);

	/* Increment the score by the appropriate amount: */
	if(g->b->flags & BRICK_FLAG_HUGE_BONUS)
		increment_score(state, state->hugebonuspoints);
	else if(g->b->flags & BRICK_FLAG_LARGE_BONUS)
		increment_score(state, state->largebonuspoints);
	else if(g->b->flags & BRICK_FLAG_MEDIUM_BONUS)
		increment_score(state, state->mediumbonuspoints);
	else if(g->b->flags & BRICK_FLAG_SMALL_BONUS)
		increment_score(state, state->smallbonuspoints);
	else increment_score(state, state->normalpoints);

	/* Remember whether this was an immutable brick (which does not factor
	 * when counting the number of bricks remaining because it cannot
	 * normally be destroyed- only the PowerBall power-up and the
	 * NoBounce cheat can cause immutable bricks to be destroyed. */
	immutable = g->b->flags & BRICK_FLAG_IMMUTABLE;
	g->b = 0; /* Wipe the brick from this grid location. */

	/* If this wasn't an immutable brick, decrement the current count of
	 * bricks and if we run out, increment to the next level and return. */
	if(!immutable && !--state->numbricks) {
		increment_level(state);
		return 1; /* Level was incremented. */
	}

	/* Create the power-up or power-down (if any): */
	if(g->power != NOPOWER)
		new_power(state, g->power, g->x + (state->brickwidth / 2),
									g->y);

	return 0; /* Level wasn't incremented. */
}
コード例 #2
0
ファイル: application.cpp プロジェクト: franc0is/sparkle-pong
void loop()
{
  static system_tick_t last = millis();
  if (millis() - last > 3000)
  {
    char player = 1 + (rand() & 1);
    increment_score(player);

    if (PONG_DEBUG)
    {
      Serial.print("Incrementing player ");
      Serial.print((int)player);
      Serial.print("'s score. New score: ");
      Serial.println(score);
    }

    last = millis();
  }

  updateDisplay();
}