Exemplo n.º 1
0
void *animateSaucer(void *arg) {
	struct propset *info = arg;		/* point to info block	*/
	int	len = strlen(info->str)+2;	/* +2 for padding	*/
	int	col = 0;

	while(col+len < COLS && info->live == true) {
		usleep(info->delay*TUNIT);
		pthread_mutex_lock(&ufo_mx);
		moveHorizontal(info, col);
		info->col = col;
		pthread_mutex_unlock(&ufo_mx);
		col++;

	}
	pthread_mutex_lock(&esc_mx);
	if(info->live == true && !strcmp(info->str, "<--->")) {
		escaped++;
		displayInfo();
	}
	pthread_mutex_unlock(&esc_mx);
	info->live = false;
	strcpy(info->str, "     ");
	moveHorizontal(info, col);
	if (escaped >= 3) {
		displayInfo();
		endwin();
		exit(0);
	}
}
Exemplo n.º 2
0
int main(int ac, char *av[]) {

	/* set up curses */
	initscr(); // init curses
	crmode(); // disable required \r after each key press
	noecho(); // don't print out the character the key is bound to
	clear();

	int	       	c;		/* user input		*/
	pthread_t 	maker;
	int 		i = 0;
	int 		column = COLS/2;
	ammo = MAXROCKET+10;
	escaped = 0;

	pthread_create(&maker, NULL, setupUFO, NULL);
	pthread_mutex_init(&mx, NULL);
	pthread_mutex_init(&scr_mx, NULL);
	pthread_mutex_init(&esc_mx, NULL);
	pthread_mutex_init(&rckt_mx, NULL);
	pthread_mutex_init(&ufo_mx, NULL);
	
	struct propset launchSite = { "|", COLS, LINES-3, 0, 0}; 
	displayInfo();
	moveHorizontal(&launchSite, column);

	while(1) {
		displayInfo();
		if (ammo < 0 || escaped >= 3) {
			break;
		}

		c = getchar();

		if ( c == 'Q' || c == 'q' ) { // Q quits the program
			break;
		} 	
		if ( c == ' ' ) { // check if space button was pressed
			int k = i % MAXROCKET;
			buildRocket(k, column);
			i++;
			pthread_mutex_lock(&mx);
			ammo--;
			pthread_mutex_unlock(&mx);
			/* refresh info */
			displayInfo();
		}

		if ( c == ',') {
			if (column > 0) {
				column--;
				moveHorizontal(&launchSite, column);
			}
		}
		if ( c == '.') {
			if (column+1 < COLS-1) {
				column++;
				moveHorizontal(&launchSite, column);
			}	
		}
	}
	pthread_cancel(maker);
	endwin();
	return 0;
}
Exemplo n.º 3
0
void Paddle::moveTo(GLfloat x, GLfloat y) {
    moveVertical(y - _topLeftCorner.getY());
    moveHorizontal(x - _topLeftCorner.getX());
}