Пример #1
0
/* Increment to the next level. */
void increment_level(nbstate *state)
{
	/* If we are already on the last level: */
	if(state->level == state->numlevels) {
		/* Go the the "game won" state. */
		state->state = STATE_GAMEWON;
		/* Update the high score and save it if appropriate: */
		save_hiscore(state);
	} else { /* Not on the last level. */
		/* If we're on the title screen, go to the running state. */
		if(state->state == STATE_TITLESCREEN) {
			state->state = STATE_RUNNING;
		/* Otherwise give the player some more balls for completing a
		 * level: */
		} else state->numballs += state->newlevelballs;
		state->level++; /* Increment the level counter. */
	}
	/* We always start a new level with the ball parked: */
	park_ball(state);
	/* Draw the new level and set up various other things for it: */
	set_level_active(state);
}
Пример #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);
}