DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T p

⟦64f550976⟧ TextFile

    Length: 8156 (0x1fdc)
    Types: TextFile
    Names: »process_input.c«

Derivation

└─⟦b20c6495f⟧ Bits:30007238 EUUGD18: Wien-båndet, efterår 1987
    └─⟦this⟧ »EUUGD18/General/Tetris/process_input.c« 

TextFile

/*
** written by adam margulies vespa@ssyx.ucsc.edu
**                           {...}!ucbvax!ucscc!ssyx!vespa
**
** permission is granted to freely distribute this code provided that you:
**
** 1) don't charge for it
** 2) leave my name and header on it
** 3) clearly document your changes and place your name on them
**
*/
/* Tetris: process_input.c                                                  */
/*                                                                          */
/* This reads user input and calls funtions accordingly.                    */
/* I used a series of if statements because case statements seemed          */
/* too unwieldy for entries with long lists of code.                        */
/*                                                                          */
/* This function is also where all collision detection is done.             */
/* The collision detection is quite ugly, but fast.                         */
#include "tetris.h"

process_input(input)
char input;
{
	void bfill(), redefine();
	FILE *fp, *fopen();
	int i=0,j=0,tmp_int = 0;
	char tmp[81],c;

	SIGHOLD(14);

	if (input == 'S')   /* save game */
		save_game();

	if (input == 'D') {
		redefine();
		return;
	}
			
	if (input == key->togdisp) {  /* toggle next block display */
		print_shape(next->shape, 17, 6, next->rot, 
				(disp_next ? ' ' : next->color));
		csr_draw(6,17,9,20);
		disp_next = !disp_next;
		if (disp_next)
			next->was_shown = 1;
		SIGRELSE(14);
		return;
	}

	if (input == key->togshad) { /* toggle shadowing */
		shadow *= -1;
		if (shadow == -1) {
			mvaddstr(22,35,"----------");
			csr_draw(22,35,22,45);
		}
		else {
			draw_shadow();
			current->was_shadowed = 0;
		}
		return;
	}

	if (input == '?') {  /* info */
		
		save_screen(0,0,23,79);
		clear(0,0,23,79);

		if ((fp = fopen(HELPFILE, "r")) == NULL){
			SIGHOLD(14);
			cls();
			csr(23,0);
			resetty();
			fprintf(stderr, "%s\n", HELPFILE);
			perror("opening help file");
			exit(3);
		}

		flock(fileno(fp), LOCK_EX);
		for(i=2;i<22;i++) {
			while((c = fgetc(fp)) != '\n') 
				tmp[j++]= c;
			tmp[j] = '\0';
			move(i,0);
			printc("%s",tmp);
			j = 0;
		}
		csr_draw(0,0,23,79);
		csr(0,0);
		getchar();
		clear(2,0,22,79);
		for(i=2;i<22;i++) {
			while((c = fgetc(fp)) != '\n') 
				tmp[j++]= c;
			tmp[j] = '\0';
			move(i,0);
			printc("%s",tmp);
			j = 0;
		}
		flock(fileno(fp), LOCK_UN);
		fclose(fp);
		csr_draw(2,0,22,79);
		csr(0,0);

		getchar();
		restore_screen(0,0,23,79);
		csr_draw(0,0,23,79);
		SIGRELSE(14);
		return;
	}

	if (input == 'P') {  /* pause */
		save_screen(2,35,21,44);
		
		for(i=2;i<13;i++){
			move(i,35);
			printc("||||||||||");
			csr_draw(i,35,i,44);

			move(23-i,35);
			printc("||||||||||");
			csr_draw(23-i,35,23-i,44);
		}
			csr(12,35);
			printf("  PAUSED  ");
		csr(0,0);

		getchar();

		restore_screen(2,35,21,44);
		csr_draw(2,35,21,44);
		SIGRELSE(14);
		return;
	}

	if (input == key->left && 	/* move block left, horiz collision detect */
		( cury < 2 ||
		!(shape[current->shape].table[0][current->rot] & (xoffset ? 4 : 8)
		&& (window0[cury][curx-(xoffset ? 0 : 1)] != ' '))) &&

		( cury < 1 ||
		!(shape[current->shape].table[1][current->rot] & (xoffset ? 4 : 8)
		&& (window0[cury+1][curx-(xoffset ? 0 : 1)] != ' '))) &&

		( cury < 0 ||
		!(shape[current->shape].table[2][current->rot] & (xoffset ? 4 : 8)
		&& (window0[cury+2][curx-(xoffset ? 0 : 1)] != ' ')))) 

		if(( cury < -1 ||
		!(shape[current->shape].table[3][current->rot] & (xoffset ? 4 : 8)
		&& (window0[cury+3][curx-(xoffset ? 0 : 1)] != ' ')))) 
			if (curx + ( xoffset ? 1 : 0)
				> 35 ) {

				print_shape(current->shape,curx--, cury, current->rot, ' ');
				print_shape(current->shape, curx, cury, current->rot,
								current->color);
				if (shadow == 1)
					draw_shadow();

				SIGRELSE(14);
				return;
			}
							/* move block right, collision detect       */
							/* this collision detection is more complex */
	if (input == key->right && ((cury < 2) ||	
		(!(shape[current->shape].table[0][current->rot] & 1
		&& (window0[cury][curx+4] != ' ')) &&

		!((shape[current->shape].table[0][current->rot] & 8 &&
		!(shape[current->shape].table[0][current->rot] & 4)
		&& (window0[cury][curx+1] != ' '))) &&

		!((shape[current->shape].table[0][current->rot] & 2 &&
		!(shape[current->shape].table[0][current->rot] & 1)
		&& (window0[cury][curx+3] != ' '))) &&

		!((shape[current->shape].table[0][current->rot] & 4 &&
		!(shape[current->shape].table[0][current->rot] & 2)
		&& (window0[cury][curx+2] != ' ')))))) 

	if ((cury < 1) || 
		(!(shape[current->shape].table[1][current->rot] & 1
		&& (window0[cury+1][curx+4] != ' ')) &&

		!((shape[current->shape].table[1][current->rot] & 4 &&
		!(shape[current->shape].table[1][current->rot] & 2)
		&& (window0[cury+1][curx+2] != ' '))) &&

		!((shape[current->shape].table[1][current->rot] & 8 &&
		!(shape[current->shape].table[1][current->rot] & 4)
		&& (window0[cury+1][curx+1] != ' '))) &&

		!((shape[current->shape].table[1][current->rot] & 2 &&
		!(shape[current->shape].table[1][current->rot] & 1)
		&& (window0[cury+1][curx+3] != ' ')))))

	if ((cury < 0) ||
		(!(shape[current->shape].table[2][current->rot] & 1
		&& (window0[cury+2][curx+4] != ' ')) &&

		!((shape[current->shape].table[2][current->rot] & 8 &&
		!(shape[current->shape].table[2][current->rot] & 4)
		&& (window0[cury+2][curx+1] != ' '))) &&

		!((shape[current->shape].table[2][current->rot] & 2 &&
		!(shape[current->shape].table[2][current->rot] & 1)
		&& (window0[cury+2][curx+3] != ' '))) &&

		!((shape[current->shape].table[2][current->rot] & 4 &&
		!(shape[current->shape].table[2][current->rot] & 2)
		&& (window0[cury+2][curx+2] != ' ')))))

	if ((cury < -1) ||
		(!(shape[current->shape].table[3][current->rot] & 1
		&& (window0[cury+3][curx+4] != ' ')) &&

		!((shape[current->shape].table[3][current->rot] & 2 &&
		!(shape[current->shape].table[3][current->rot] & 1)
		&& (window0[cury+3][curx+3] != ' '))) &&

		!((shape[current->shape].table[3][current->rot] & 4 &&
		!(shape[current->shape].table[3][current->rot] & 2)
		&& (window0[cury+3][curx+2] != ' '))) &&

		!((shape[current->shape].table[3][current->rot] & 8 &&
		!(shape[current->shape].table[3][current->rot] & 4)
		&& (window0[cury+3][curx+1] != ' '))))) 
			if (curx + current->width < 45) {
				print_shape(current->shape,curx++, cury, current->rot, ' ');
				print_shape(current->shape, curx, cury, current->rot,
								current->color);
				if (shadow == 1)
					draw_shadow();

				SIGRELSE(14);
				return;
			}

	if (input == key->rotright &&		/* rotate shape clockwise */
		(curx + current->height < 46) &&
		!(xoffset && curx < 36) &&
		(cury + current->width < 22)
		)
		{
			print_shape(current->shape, curx, cury, current->rot, ' ');
			current->rot = ++current->rot % 4;
			print_shape(current->shape, curx, cury, current->rot,
						current->color);
			tmp_int = current->height;
			current->height = current->width;
			current->width = tmp_int;
			if (shadow == 1)
				draw_shadow();

			SIGRELSE(14);
			return;
		}

	if (input == key->rotleft &&		/* rotate shape clockwise */
		(curx + current->height < 46) &&
		!(xoffset && curx < 35) &&
		(cury + current->width < 22)
		)
		{

			print_shape(current->shape, curx, cury, current->rot, ' ');
			current->rot = (current->rot + 3) % 4;
			print_shape(current->shape, curx, cury, current->rot,
							current->color);
			tmp_int = current->height;
			current->height = current->width;
			current->width = tmp_int;
			if (shadow == 1)
				draw_shadow();

			SIGRELSE(14);
			return;
		}

		if (input == key->drop) {	/* drop shape as fast as possible */

			dropped_from = cury + current->height -1;
			fast_drop = 1;

			while (cury < 3)
				drop_block();
				
			while(cury > 2)
				drop_block();

			dropped_from = 0;
			fast_drop = 0;
			SIGRELSE(14);
			return;
		}

		if (input == 'Q') {		/*	quit   */
			current->shape = 7;
			end_game();
		}
		
			/* changed '^R' to '\022'; billr@saab.CNA.TEK.COM */
		if (input == '\022' || input == '\014') {
			cls();
			bfill(window0, sizeof(window0), ' ');
			refresh();
			SIGRELSE(14);
			return;
		}

}