Example #1
0
/* Called whenever the ball collides with a brick, and handles such things as
 * destroying the brick if appropriate, redrawing it with more transparency
 * if appropriate, incrementing to the next level when we destroy the last brick
 *  (actually, that's done by destroy_brick() which is called from
 * brick_collision()), etc. Returns 0 if the level was not incremented and 1
 * if it was. */
int brick_collision(nbstate *state, grid *g)
{
	/* If either the PowerBall power-up or the NoBounce cheat is active,
	 * simply destroy the brick in one hit even if it is immutable. */
	if(state->powertimes.powerball || state->flags.nb)
		return destroy_brick(state, g);

	/* If this is an immutable brick and PowerBall and NoBounce are not
	 * active, it can't be destroyed so return normally: */
	if(g->b->flags & BRICK_FLAG_IMMUTABLE) return 0;

	/* Increment the number of hits on this brick. This is used to keep
	 * track of when to destroy a "2 hits or "3 hits" brick, and also how
	 * transparent to draw those bricks as: */
	g->hits++;

	/* If this is a 2-hit brick and it has only been hit once or it is a
	 * 3 hit brick that has been hit either once or twice: */
	if(((g->b->flags & BRICK_FLAG_2_HITS) && g->hits < 2) ||
			((g->b->flags & BRICK_FLAG_3_HITS) && g->hits < 3)) {
		/* Clear the area where the brick is: */
		draw_background(state, g->x, g->y, state->brickwidth,
				state->brickheight);
		/* Redraw the brick (with additional transparency to indicate
		 * that it has been hit): */
		draw_brick(state, g, 0, 0, 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 changed area to the output window: */
		draw_canvas(state, g->x, g->y, state->brickwidth,
				state->brickheight);
	/* Otherwise, destroy the brick: */
	} else return destroy_brick(state, g);

	return 0; /* Level was not incremented. */
}
Example #2
0
void move_ball() {

		switch (g) {
			case 100:
			l_100:
				if (m<20) goto l_106;
				p=0; w=0;
				if ((n==(a+1)||(n==(a+2)))) {
					g=120;  goto l_120;
				}
				if (n==a) {
					g=180;  goto l_180;
				}
				if (n==(a-1)) {
					g=140;  goto l_140;
				}
			l_106:
				if (n>30) {
					hit_border();
					g=160;  goto l_160;
				}
				m++; n++;
				if (hit_brick()) {
					destroy_brick();
					if ((p==0) || (w==1))
						g=120;
				}
				break;

			case 120:
			l_120:
#ifdef SOUND
				if (m==20)
					bit_synth(20, 25, 24, 23, 22);
#endif
				if (n>30) {
					hit_border();
					g=140;  goto l_140;
				}
				if (m<1) {
					hit_border();

					/* A new trick to shake the ball and make possible
					   to hit all the bricks with a single ball */
					if (n>30) n--;

					w=1;
					g=100;  goto l_100;
				}
				m--; n++;
				if (hit_brick()) {
					destroy_brick();
					p=1;
					g=100+40*w;
				}
				break;

			case 140:
			l_140:
#ifdef SOUND
				if (m==20)
					bit_synth(20, 25, 24, 23, 22);
#endif
				if (m<1) {
					hit_border();

					/* A new trick to shake the ball and make possible
					   to hit all the bricks with a single ball */
					if (n<1) n++;

					w=1;
					g=160;  goto l_160;
				}
				if (n<1) {
					hit_border();
					g=120;  goto l_120;
				}
				m--;  n--;
				if (hit_brick()) {
					destroy_brick();
					p=1;
					g=160-40*w;
				}
				break;

			case 160:
			l_160:
				if (m<20)  goto l_166;
				p=0; w=0;
				if (n==(a+3)) {
					g=120;  goto l_120;
				}
				if (n==(a+2)) {
					g=180;  goto l_180;
				}
				if ((n==a)||(n==(a+1))) {
					g=140;  goto l_140;
				}
			l_166:
				if (n<1) {
					hit_border();
					g=100;  goto l_100;
				}
				m++;  n--;
				if (hit_brick()) {
					destroy_brick();
					if ((p==0) || (w==1))
						g=140;
				}
				break;

			case 180:
			l_180:
#ifdef SOUND
				if (m==20)
					bit_synth(20, 25, 24, 23, 22);
#endif
				if (m<1) {
					hit_border();
					g=200;  goto l_212;
				}
			l_190:
				m--;
				if (hit_brick()) {
					destroy_brick();
					g=200;
				}
				break;

			case 200:
				if (m<20)
					goto l_212;
				p=0;  w=0;
				if (n==(a+2)) {
					g=120;  goto l_120;
				}
				if (n==a+1) {
					if (rand()&1) {
						g=120; goto l_120;
					} else {
						g=140; goto l_140;
					}
				}
				if (n==a) {
						g=140; goto l_140;
				}
				l_212:
				m++;
				break;
		}
}