Пример #1
0
int main(int argc, char *argv[])
{
	if (argc > 1)
		file = fopen(argv[1], "r");
	gfx_open(width*sizex, width*sizey, "Life");
	// cycle through cells to determine next generation state of each, not including edges for simplicity
	while(1){
		if (choice!='p')
			input(&argc);
		system("clear");
		if (choice=='q')
			break;
		neighborcount();
		// display next generation
		for(y=0; y<sizey; y++){
			for(x=0; x<sizex; x++){
				// transfer state data from temp to new generation life grid 
				if (edit != 1)
					life[y][x]=temp[y][x];
				// reset temp grid
				temp[y][x]=0;
				if (life[y][x]==1){
					gfxcell(x, y);
				}
			}
		}
	gfx_flush();
	usleep(75000);
	if (edit != 1)
		gfx_clear();
	}
}
void terminal_message(){
//draws a prompt to open the terminal

draw_P(230,750,60);
draw_L(265,750,60);
draw_E(300,750,60);
draw_A(340,750,60);
draw_S(372,750,60);
draw_E(410,750,60);

draw_O(480,750,60);
draw_P(515,750,60);
draw_E(555,750,60);
draw_N(595,750,60);

draw_T(650,750,60);
draw_H(690,750,60);
draw_E(730,750,60);

draw_T(790,750,60);
draw_E(830,750,60);
draw_R(865,750,60);
draw_M(905,750,60);
draw_I(945,750,60);
draw_N(985,750,60);
draw_A(1025,750,60);
draw_L(1065,750,60);
gfx_flush();
}
Пример #3
0
void destroy(double astr[][5], double shots[][5], int score[])
{
// This will break down the asteriods when they are hit with a shot
 int i, j, k, l;
 for (i=0; i<32; i++) {
        for (j=0; j<30; j++) {
		if(shots[j][3]!=0){   //keeps from running following statements with nonfired shots
			//line below checks to see if shot overlaps with asteroid
			if(astr[i][0]+astr[i][3]>=shots[j][0]-shots[j][3] && astr[i][0]-astr[i][3] <= shots[j][0]+shots[j][3] && astr[i][1]+astr[i][3]>=shots[j][1]-shots[i][3] && astr[i][1]- astr[i][3] <= shots[j][1]+shots[j][3]) {
        	                 
				if (astr[i][3]==40) {
                                	shots[j][3]=0;		//shot disappears 
					score[0]=score[0]+1;	//score increases
					asteroids_level2(astr, i);
                        	} else if (astr[i][3]==20) {
                                	score[0]=score[0]+2;	//score increases
					shots[j][3]=0;		//shot disappears
					asteroids_level3(astr, i);
                        	} else if (astr[i][3]<=10) {
                                	shots[i][3]=0;		//shot disappears
					score[0]=score[0]+3;
					astr[i][3]=0;		//asteroid radius set to zero so that it can go through asteroid()
                                	astr[i][4]=1;
				
				}
				gfx_flush();
			}
                }
        }
 }
}
Пример #4
0
int main () {
	int x, y, dx, dy, radius = 100;
	double pi, i = 0.07;
	char c;

	pi = M_PI;

	gfx_open(500,500,"Rotating Animation Emily");

	printf("To speed up display press f key; to slow down display press s key.\n");

	while (1) {
			drawPerson();

			x = radius*cos(i) + 250;
			y = radius*sin(i) + 150;
			gfx_color(0, 0, 255);
			gfx_circle(x, y, 20); //ball 1 (blue)
		
			x = radius*cos(i+1.5) + 250;
			y = radius*sin(i+1.5) + 150;
			gfx_color(0, 255, 0);
			gfx_circle(x, y, 20); //ball 2 (green)

			x = radius*cos(i+3.) + 250;
			y = radius*sin(i+3.) + 150;
			gfx_color(255, 0, 0);
			gfx_circle(x, y, 20); //ball 3 (red)
			

			gfx_flush();
			usleep(10000);
			gfx_clear();
			

			if (gfx_event_waiting()) {
				c = gfx_wait();
				if (c =='s') { //slows down juggling
					i-=0.1;
				} else if (c =='f') { //speeds  juggling
					i+=0.1;
				} else if (c =='q') {
					break;
				}
			}

			i+= 0.01;
		}

	
	

	return 0;
}
Пример #5
0
static void gfxconsole_putc(char c)
{
    static enum { NORMAL, ESCAPE } state = NORMAL;
    static uint32_t p_num = 0;

    switch (state) {
    case NORMAL:
    {
        if(c == '\n' || c == '\r') {
            gfxconsole.x = 0;
            gfxconsole.y++;
        } else if (c == 0x1b) {
            p_num = 0;
            state = ESCAPE;
        } else {
            font_draw_char(gfxconsole.surface, c, gfxconsole.x * FONT_X, gfxconsole.y * FONT_Y, gfxconsole.front_color);
            gfxconsole.x++;
        }
        break;
    }

    case ESCAPE:
    {
        if (c >= '0' && c <= '9') {
            p_num = (p_num * 10) + (c - '0');
        } else if (c == 'D') {
            if (p_num <= gfxconsole.x)
                gfxconsole.x -= p_num;
            state = NORMAL;
        } else if (c == '[') {
            // eat this character
        } else {
            font_draw_char(gfxconsole.surface, c, gfxconsole.x * FONT_X, gfxconsole.y * FONT_Y, gfxconsole.front_color);
            gfxconsole.x++;
            state = NORMAL;
        }
        break;
    }
    }

    if(gfxconsole.x >= gfxconsole.columns) {
        gfxconsole.x = 0;
        gfxconsole.y++;
    }
    if(gfxconsole.y >= gfxconsole.rows) {
        // scroll up
        gfx_copyrect(gfxconsole.surface, 0, FONT_Y, gfxconsole.surface->width, gfxconsole.surface->height - FONT_Y - gfxconsole.extray, 0, 0);
        gfxconsole.y--;
        gfx_fillrect(gfxconsole.surface, 0, gfxconsole.surface->height - FONT_Y - gfxconsole.extray, gfxconsole.surface->width, FONT_Y, gfxconsole.back_color);
        gfx_flush(gfxconsole.surface);
    }
}
Пример #6
0
int main() {

	int width = 400; 
	int height = 550;
    int gameLoop = 1;
    int highScore = 0;
    
    gfx_open(width, height, "Flappy Bird");
    
    //create two pipes to be recycled
    Pipe* leadPipe = (Pipe*)malloc(sizeof(Pipe));
    Pipe* trailPipe = (Pipe*)malloc(sizeof(Pipe));
    
    while (gameLoop) {
    
        //initialize each pipe
        initializePipe(leadPipe, width, height);
        initializePipe(trailPipe, width, height);
    
        //set background color
        gfx_clear_color(85, 203, 217);
        gfx_clear();
        
        //present game home screen
    
        char c;
        int flap = 0;
        double birdX = 150, birdY = 275, birdR = 12, degrees = 0;
        while (1) {
            gfx_clear();
            if(gfx_event_waiting()){
                if(gfx_wait()==' ') break;
            }
            presentHomeScreen(width, height);
            stationaryBird(&birdY,degrees);
            flap = drawBird(birdX, birdY, birdR, flap);
            gfx_flush();
            usleep(50000);
            degrees+=(2*M_PI)/20;
        }
    
        //begin animation
        int score = startGame(leadPipe, trailPipe, width, height);
        highScore = endGame(score, highScore, width, height);
        char d;
	
    }
 
	return 0; 
}
Пример #7
0
int main(void) {
	

	gfx_open(400,400,"Bounce"); 
	int stillGoing = 1; 
	float dt = 0.01;
	float xpos =rand() %400+1;  
	float ypos =rand() %400+1; 
        float xvel =(double)rand()/RAND_MAX * 10.0 - 5.0; 
	float yvel =(double)rand()/RAND_MAX * 10.0 - 5.0; 
	float RIGHT_EDGE = 400; 
	float LEFT_EDGE = 0; 
	float TOP = 0; 
	float BOTTOM = 400; 

	
	
	while(stillGoing){
		xpos += xvel; 
		ypos += yvel; 
			
		if(xpos <= LEFT_EDGE || xpos >= RIGHT_EDGE) xvel *=-1; 
		if(ypos <= TOP || ypos >= BOTTOM) yvel *= -1; 
		gfx_clear(); 
		drawPoly(30,xpos,ypos); 
		gfx_flush(); 
		usleep(10000); 

		
		if(gfx_event_waiting()){
			char c = gfx_wait(); 
			if(c==1){
				xpos = gfx_xpos(); 		
				ypos = gfx_ypos(); 
			        xvel =(double)rand()/RAND_MAX * 10.0 - 5.0; 
				yvel =(double)rand()/RAND_MAX * 10.0 - 5.0;
			}
			else if (c=='q' || c=='Q'){
				break; 
			}

		}

	}	


	return 0; 

}
Пример #8
0
void death(double astr[][5], double shots[][5], double *x, double *y, int score[])
{
 int i;
 
 gfx_clear();
 gfx_color(255, 0, 0);
 for(i=0; i<10; i++){
 	gfx_flush();
	gfx_color(255, 0, 0);
	drawship(350, 350, 0, 0);	//redraws ship and pauses to allow user time to recover
 	usleep(100000);
 	gfx_color(255, 255, 255);
	drawship(350, 350, 0, 0);
	usleep(100000);
 	
 }
 gfx_flush();
 *x=350;
 *y=350;
 score[1]=score[1]-1;	//subtracts a life 
 initialize(astr);	//resets astroids and shots
 initialize(shots);

}
Пример #9
0
char gfx_wait()
{
	XEvent event;

	gfx_flush();

	while(1) {
		XNextEvent(gfx_display,&event);

		if(event.type==KeyPress) {
			saved_xpos = event.xkey.x;
			saved_ypos = event.xkey.y;
			return XLookupKeysym(&event.xkey,0);
		} else if(event.type==ButtonPress) {
			saved_xpos = event.xkey.x;
			saved_ypos = event.xkey.y;
			return event.xbutton.button;
		}
	}
}
Пример #10
0
//begin main function
int main (void) 
{		
	int xsize = 800, ysize = 800 ;
	gfx_open( xsize, ysize, "Test Graph of Function triangle_waveform" ) ;

	int stillgoing = 1;

	while (stillgoing) {
		gfx_clear() ;
		gfx_color(255, 255, 255) ;	//axis is white		
		draw_axes( xsize, ysize) ;
		gfx_color(150, 0, 255) ;
		plot_triangle(xsize, ysize, -10., 10, .1) ;
		gfx_flush() ;

		char c = gfx_wait() ;
		if (c == 'q') stillgoing = 0 ;
	}
	return 0 ;
}	//end main		
Пример #11
0
/**
 * @brief  Refresh the display
 */
void text_update(void)
{
	struct display_info info;
	display_get_info(&info);

	/* get the display's surface */
	gfx_surface *surface = gfx_create_surface_from_display(&info);

	struct text_line *line;
	list_for_every_entry(&text_list, line, struct text_line, node) {
		const char *c;
		int x = line->x;
		for (c = line->str; *c; c++) {
			font_draw_char(surface, *c, x, line->y, TEXT_COLOR);
			x += FONT_X;
		}
	}

	gfx_flush(surface);

	gfx_surface_destroy(surface);
}
Пример #12
0
void move_shots(double shots[][5])
{
 int i, j;
 for(i=0; i<30; i++){
        if(shots[i][3]!=0){
                shots[i][0]=shots[i][0]+6*cos(shots[i][2]+PI/2);  //shots fired at angle ship is at
                shots[i][1]=shots[i][1]-6*sin(shots[i][2]+PI/2);
                if(shots[i][0]>=700){
                        shots[i][3]=0;
                } else if(shots[i][0]<=0){
                        shots[i][3]=0;
                } else if(shots[i][1]>=700){     //this kills shots when they leave the screen
                        shots[i][3]=0;
                } else if(shots[i][1]<=0){
                        shots[i][3]=0;
                }
                gfx_color(0,255,0);
                gfx_circle(shots[i][0], shots[i][1], shots[i][3]);
        	gfx_color(255,255, 255);
	}
 }
 gfx_flush();
}
Пример #13
0
void dmsg_update(void)
{
	gfx_point2d_t pos;
	gfx_rect_t    rect;
	
//	if (do_scroll == 0) {
		pos.x = dmsg_pos_x;
		pos.y = dmsg_pos_y;
		rect.x = 0;
		rect.y = 0;
		rect.width = dmsg_buff_width;
		rect.height = dmsg_buff_height;
		gfx_bitblt(dmsg_buff_id, &rect, &pos);
//	}
/*	else {
	//	if (dmsg_cursor_y > 0) {
			pos.x = dmsg_pos_x;
			pos.y = dmsg_pos_y;
			rect.x = 0;
			rect.y = dmsg_cursor_y + 8;
			rect.width = dmsg_buff_width;
			rect.height = dmsg_buff_height - dmsg_cursor_y;
			gfx_bitblt(dmsg_buff_id, &rect, &pos);
	//	}
		
		if (dmsg_cursor_y > 0) {
			pos.y = dmsg_pos_y + dmsg_cursor_y;
			rect.y = 0;
			rect.height = dmsg_cursor_y;
			gfx_bitblt(dmsg_buff_id, &rect, &pos);
		}
	}
*/
	gfx_flush();
	gfx_paint();
}
Пример #14
0
int main()
{
	int i;
	gfx_rect_t rect;
	uint32_t color;
	uint16_t fbuff[320*240];
	key_data_t keys, no_keys;

	// setup function pointers
	dprintf               = FUNC(0x04);
	gfx_init              = FUNC(0x38);
	gfx_set_framebuffer   = FUNC(0x90);
	gfx_set_display_screen= FUNC(0x54);
	gfx_set_cammmode      = FUNC(0x8c);
	gfx_set_colorrop      = FUNC(0x3c);
	gfx_set_fgcolor       = FUNC(0x44);
	gfx_get_fgcolor       = FUNC(0x48);
	gfx_fillrect          = FUNC(0xc4);
	gfx_enable_feature    = FUNC(0x7c);
	gfx_flush             = FUNC(0xc);
	gfx_paint             = FUNC(0x10);
	get_time              = FUNC(0x124);
	get_keys              = FUNC(0x100);

//	dprintf("Hello World!\n");
	gfx_init(fbuff, sizeof(fbuff));

	rect.x = 0;
	rect.y = 0;
	rect.width = 320;
	rect.height = 240;

	gfx_set_framebuffer(320, 240);
	gfx_set_display_screen(&rect);//320, 240);

	color = MAKE_RGB(255,0,0);
	gfx_enable_feature(3);
	gfx_set_fgcolor(&color);
	gfx_set_colorrop(COLOR_ROP_NOP);
	gfx_fillrect(&rect);


	rect.x = 30;
	rect.y = 30;
	rect.width = 260;
	rect.height = 180;

	color = MAKE_RGB(0,255,0);
	gfx_set_fgcolor(&color);
	gfx_set_colorrop(COLOR_ROP_NOP);
	gfx_fillrect(&rect);

	rect.x = 60;
	rect.y = 60;
	rect.width = 200;
	rect.height = 120;

	color = MAKE_RGB(0,0,255);
	gfx_set_fgcolor(&color);
	gfx_set_colorrop(COLOR_ROP_NOP);
	gfx_fillrect(&rect);
/*
	// is it used at all ?
	for (i=0; i<320; i++) fbuff[(100*320)+i] = 0;
*/
	gfx_set_colorrop(COLOR_ROP_NOP);
	gfx_flush();
	gfx_paint();


	get_keys(&no_keys);
//	no_keys.key2 &= ~0x5ff0;
	while (1) {
		get_keys(&keys);
//		keys.key2 &= ~0x5ff0;
		if (keys.key2 != no_keys.key2) break;
	}

	return 0;
}
Пример #15
0
int main(void)			// we will be constructing a symbolic typewriter using a basic graphics library
{
	int mousePosX;		// mouse point position in x and y directions
	int mousePosY;

	int screenX = 900;	// screen resolution in pixels
	int screenY = 900;

	float x1;		// position 1
	float y1;

	float x2;		// position 2
	float y2; 

	float radians;		// need radians and radius when dealing with polar coordinated
	float radius;

	float pi = atan(1)*4;	// pi constant
	
	int min = 0;		// minimum number of degrees
	int c = 0;		// counter for for loops
	int randomDegrees = 0;	// random integer degree
	int polygon = 0;	// place for number of polygon sides

	char user;		// this will be the value of the user input 

	srand(time(NULL));	// random integer seed

	// begin symbolic typewriter

	gfx_open(screenX, screenY, "Symbolic Typewriter");

	while( 1 )
	{
		user = gfx_wait();		// waiting for a user-given symbol

		switch( user )
		{	
			case 1:			// mouse click, we will print a blue square outline
			{
				gfx_color(0, 0, 255);		// changing color to blue

				radius = 25;

				mousePosX = gfx_xpos();		// storing the current mouse position
				mousePosY = gfx_ypos();

				x1 = mousePosX + radius;	// upper right point
				y1 = mousePosY + radius;

				x2 = mousePosX - radius;	// upper left point
				y2 = mousePosY + radius;

				gfx_line((int)x1, (int)y1, (int)x2, (int)y2);	// top line		

				x1 = mousePosX + radius;	// upper right point
				y1 = mousePosY + radius;

				x2 = mousePosX + radius;       	// lower right point
				y2 = mousePosY - radius;

				gfx_line((int)x1, (int)y1, (int)x2, (int)y2);  	// right line

				x1 = mousePosX + radius;       	// lower right point
				y1 = mousePosY - radius;

				x2 = mousePosX - radius;       	// lower left point
				y2 = mousePosY - radius;

				gfx_line((int)x1, (int)y1, (int)x2, (int)y2); 	// lower line

				x1 = mousePosX - radius;       	// lower left point
				y1 = mousePosY - radius;

				x2 = mousePosX - radius;       	// upper left point
				y2 = mousePosY + radius;

				gfx_line((int)x1, (int)y1, (int)x2, (int)y2);	// left line
			
				gfx_flush();		// actually draw the square
			
				break;
			}

			case 't':		// display a green triangle outline	
			{
				gfx_color(0, 255, 0);		// changing color to green

				radius = 25;

                                mousePosX = gfx_xpos();		// storing the current mouse position
                                mousePosY = gfx_ypos();

                                x1 = mousePosX;			// upper point
                                y1 = mousePosY - radius;

                                x2 = mousePosX + radius;	// lower right point
                                y2 = mousePosY + radius;

                                gfx_line((int)x1, (int)y1, (int)x2, (int)y2);   // right line

                                x1 = mousePosX + radius;	// lower right point
                                y1 = mousePosY + radius;

                                x2 = mousePosX - radius;      	// lower left point
                                y2 = mousePosY + radius;

                                gfx_line((int)x1, (int)y1, (int)x2, (int)y2);   // bottom line
			
				x1 = mousePosX - radius;	// lower left point
                                y1 = mousePosY + radius;

                                x2 = mousePosX;             	// upper point
                                y2 = mousePosY - radius;

                                gfx_line((int)x1, (int)y1, (int)x2, (int)y2);   // left line

				gfx_flush();
			
				break;
			}

			case 'c':		// display a white circle outline
			{
				gfx_color(255, 255, 255);	// change the color to white
			
				radius = 25;			// circle radius of 5 pixels

				mousePosX = gfx_xpos();
				mousePosY = gfx_ypos();

				x2 = mousePosX + radius;		// determine the first point
				y2 = mousePosY;
			
				for( c = 0; c <= 360; c++ )		// go through an entire circle (convert to radians)
				{
					x1 = x2;			// assign the last point to be the first point for the next line
					y1 = y2;
		
					x2 = mousePosX + (cos(c*pi/180)*radius);
					y2 = mousePosY + (sin(c*pi/180)*radius);

					gfx_line((int)x1, (int)y1, (int)x2, (int)y2);
				}

				gfx_flush();

				break;
			}	

			case '3': 
			case '4': 
			case '5': 
			case '6': 
			case '7': 
			case '8': 
			case '9':				// print a polygon with the alotted number of sides
			{
				switch ( user )			// find the integer number of sides
				{
					case '3':
					{
						polygon = 3;
						min = 80;	// setting the minimum degrees between each point
						break;		// the angle must be between this min and 360/sides
					}
					case '4':
					{
						polygon = 4;
						min = 65;
						break;
					}
					case '5':
					{
						polygon = 5;
						min = 62;
						break;
					}
					case '6':
					{
						polygon = 6;
						min = 55;
						break;
					}
					case '7':
					{
						polygon = 7;
						min = 50;
						break;
					}
					case '8':
					{
						polygon = 8;
						min = 45;
						break;
					}
					case '9':
					{
						polygon = 9;
						min = 39;
						break;
					}
				}
	
				gfx_color(150, 0, 150);		// change the color to purple

				radius = 50;
				randomDegrees = 0;

				mousePosX = gfx_xpos();
				mousePosY = gfx_ypos();

				x2 = mousePosX + radius;		// determine the first point
				y2 = mousePosY;

				for( c = 1; c < polygon; c++ )		// making only the specified number of points
				{
					x1 = x2;			// assign the last point to be the first point for the next line
					y1 = y2; 
					
					randomDegrees = randomDegrees + (min + (rand() % ((360 / polygon)-min+2)));	// random integer degree limit

					// the degrees added are in the range of min to max, where the max is dependent on the number of sides

					x2 = mousePosX + (cos(randomDegrees*pi/180)*radius);
					y2 = mousePosY + (sin(randomDegrees*pi/180)*radius);

					gfx_line((int)x1, (int)y1, (int)x2, (int)y2);
				}
				
				x1 = x2;			// for the last point we need to make sure it returns to the original point
				y1 = y2;

				x2 = mousePosX + radius;
				y2 = mousePosY;
	
				gfx_line((int)x1, (int)y1, (int)x2, (int)y2);
			
				gfx_flush();

				break;
			}			

			case ' ':		// clear the graphics window
			{
				gfx_clear();
			
				break;
			}

			case 'q':		// quit the graphics window		
			{
				break;
			}
		}

		if( user == 'q' )		// quitting actual while loop
		{
			break;
		}
	}
}
Пример #16
0
int main (void)
{
    // Declare all of the variables that will be used in the function
    char c;
    int xsize=400, ysize=400, j;
    float pi=3.14159, rClock, xcc, ycc, rDot, yDotNeg, yDotPos, xDotNeg, xDotPos, bhPos, shPos, bhVel=-2*pi/60, shVel=bhVel/12, i, di=0.01, k, dk=2*pi/3;

    // Initializes the positions of the big and small hands of the clock
    bhPos = pi/2;
    shPos = pi/2;

    // From here to the first gfx command, all of the size sensitive variables are initialized
    xcc = xsize/2;
    ycc = ysize/2;

    if (xsize <= ysize)
    {
        rClock = xsize/2;
        rDot = xsize/20;
    }
    else
    {
        rClock = ysize/2;
        rDot = ysize/20;
    }

    yDotNeg = ycc + rClock-20;
    yDotPos = ycc - rClock+20;
    xDotNeg = xcc - rClock+20;
    xDotPos = xcc + rClock-20;

    //creates screen size and caption
    gfx_open(xsize, ysize, "Clock - 's'- switch direction, 'q'- quit");

    //While loop that generates the clock
    while (1)
    {
        for (i=0; i<=2*pi; i+=di)
        {
            gfx_color(255, 255, 255);
            gfx_line(xcc + rClock*cos(i),  ycc + rClock*sin(i),    xcc + rClock*cos(i+di),  ycc + rClock*sin(i+di));
        }

        for (k=0; k<=2*pi; k+=dk)
        {
            gfx_color(0, 100, 200);
            gfx_line(xcc + rDot*sin(k),  yDotNeg + rDot*-cos(k),    xcc + rDot*sin(k+dk),  yDotNeg + rDot*-cos(k+dk));
        }
        for (k=0; k<=2*pi; k+=dk)
        {
            gfx_color(0, 100, 200);
            gfx_line(xcc + rDot*sin(k),  yDotPos + rDot*cos(k),    xcc + rDot*sin(k+dk),  yDotPos + rDot*cos(k+dk));
        }
        for (k=0; k<=2*pi; k+=dk)
        {
            gfx_color(0, 100, 200);
            gfx_line(xDotNeg + rDot*cos(k),  ycc + rDot*sin(k),    xDotNeg + rDot*cos(k+dk),  ycc + rDot*sin(k+dk));
        }
        for (k=0; k<=2*pi; k+=dk)
        {
            gfx_color(0, 100, 200);
            gfx_line(xDotPos + rDot*-cos(k),  ycc + rDot*sin(k),    xDotPos + rDot*-cos(k+dk),  ycc + rDot*sin(k+dk));
        }

        for (k=0; k<=2*pi; k+=dk/4)
        {
            gfx_color(0, 100, 200);
            gfx_line(xcc + rClock*cos(k)*10/11,  ycc + rClock*sin(k)*10/11,    xcc + rClock*cos(k)*9/11,  ycc + rClock*sin(k)*9/11);
        }

        gfx_color(0, 200, 100);
        gfx_line(xcc,  ycc,    xcc + rClock*9/10 * cos(bhPos),  ycc + rClock*9/10 * -sin(bhPos));
        gfx_line(xcc,  ycc,    xcc + rClock*5/10 * cos(shPos),  ycc + rClock*5/10 * -sin(shPos));

        bhPos += bhVel;
        shPos += shVel;

        gfx_flush();
        usleep(300000);
        gfx_clear();

        j = gfx_event_waiting();
        if ( j==1 )
        {
            c = gfx_wait();
            switch (c)
            {

            case 's':
                bhVel = -bhVel;
                shVel = -shVel;
                break;

            case 'q':
                return 0;
            }
        }

    }

    return 0;
}
Пример #17
0
int main(){
	int xposS = 370;
	char c; //user input
	int xdist = 0, ydist =0;
	int dx = 1;
	int Bnum = 0;
	int posB[2][10] = {0};
	unsigned int i, j;

	gfx_open(SIZEX, SIZEY, "Space Invaders"); //open window
	initializeBullets(posB);
	
	while(true){
		gfx_clear(); //clear screen

		dispScore();

		uShooter(xposS);
		drawAliens(xdist, ydist);

		if(gfx_event_waiting()){ //if true
			c = gfx_wait(); //find choice
			if (c == 'b'){
				xposS-=10;
				if (xposS <= 0) xposS = 0;
			}else if (c == 'n'){
				xposS +=10;
				if (xposS >= SIZEX-30) xposS = SIZEX-30;
			}else if (c == ' '){
				for(i=0; i<10; i++){
					if(posB[0][i] == -1){
						posB[0][i] = drawBullet(xposS);
						posB[1][i] = YPOS;
					}
				}
			}else if (c == 'q') return 0;		
			else continue;
			
		}
		
		xdist+=dx;

		if(xdist>=370 || xdist <=-100){
			dx*=-1;
		}
		if(xdist == 370 || xdist ==-100){
			ydist +=5;
		}
		if(ydist == 225) return 0; //change lives num	

		
		for(j=0; j<10; j++){
			if(posB[0][j] != -1){
				moveBullet(posB, j);	
			}
			checkBullet(posB,j);
		}



		usleep(25000);
		gfx_flush();
	}
}
Пример #18
0
void moveBullet(int posB[2][10], int j){
	int temp = posB[1][j]-3;
	gfx_line(posB[0][j], posB[1][j], posB[0][j], temp);
	posB[1][j] = temp;
	gfx_flush();
}
Пример #19
0
int main()
{
    int i,ic; //variables for incrementing in for loops
    int lives=5, level=1; //initialize lives and level
    int fgx=12, fgy=11, *frogx=&fgx, *frogy=&fgy; //initialize frog position
    int row=12,col=25,board[row][col]; //dimensions for board
    char play; //declare play character
    int x[19]= {5-width/4,width+5,10-width/4,15-width/4,width+10,5-width/2,1.2*width,10-width/2,15-width/2,1.2*width,5-width,1.5*width,10-width,15-width,1.5*width,width+5,5-width,width+10,10-width/2}; //array of starting positions of moving objects

    //initialize board
    for(i=0; i<6; i++)
        for(ic=0; ic<col; ic++)
            board[i][ic]=0;
    for(i=6; i<row; i++)
        for(ic=0; ic<col; ic++)
            board[i][ic]=1;
    for(i=2; i<col; i+=4)
        board[0][i]=2;

    gfx_open(width,height,"Frogger"); //open graphics window

    play=welcome(); //begin game

    while(play!='q') { //while user wants to play the game and not quit
        background(level);
        draw_lives(lives);
        draw(col,board,level,x,frogx,frogy);
        drawfrog(*frogx,*frogy,play);
        gfx_flush();
        usleep(100000);
        /*
            for(i=0;i<row;i++){ //prints board in terminal
            	for(ic=0;ic<col;ic++)
            		printf("%d",board[i][ic]);
            	printf("\n");
            } //end for(i=0;i<row;i++)
            printf("\n");
        */
        if (gfx_event_waiting()) { //if user tries to move frog
            play = hopper(frogx,frogy,row,col); //move frog according to input if valid
        } //end if (gfx_event_waiting())

        switch(board[*frogy][*frogx]) {
        case 0: //frog dies in this location
            lives--; //lose a life
            *frogx=12;
            *frogy=11;
            if(lives==0) {
                play=blood(); //game over, play again or end
                lives=5;
                level=1;
            } //end if(lives==0)
            break;

        case 1: //frog can be in this location and game continues
            break;

        case 2: //frog made it to lilly pad
            level++; //level up
            *frogx=12;
            *frogy=11;
            if (level>5) {
                play=win();//you won!
                level = 1;
                lives = 5;
            } //end if (level>5)
            break;

        } //end switch(board[*frogx][*frogy])

    } //end while(play!='q')

} //end main
Пример #20
0
int update()
{
    if (get_active_screen() == NULL)
    {
        return 1;
    }

    timestamp_t current = {0};
    timestamp_set(&current);
    long dt = timestamp_diff(&current, &timer);
    if (dt > 0)
    {
        timer = current;
        screen_update(dt);
    }

    long fps_dt = timestamp_diff(&current, &fps_timer);
    LOGD("DT: %ld", fps_dt);
    if (fps_dt > 500)
    {
        fps = frames * 1000.0f / (float)fps_dt;
        fps_timer = current;
        frames = 0;
        LOGI("FPS: %.2f", fps);
    }
    else
    {
        ++frames;
    }

    char fps_str[32] = {0};
    sprintf(fps_str, "FPS: %.2f", fps);

    const rect_t fps_rect = { 8.0f, 8.0f, 256.0f, 32.0f };
    const rgba_t fps_color = { 1.0f, 0.0f, 0.0f, 0.8f };

    mat4f_t transform = {0};
    mat4_mult(&transform, &camera.proj, &camera.view);

    rect_t screen = { 0, 0, screen_size.x, screen_size.y };

    rgba_t color = {0.7f, 0.7f, 0.0f, 1.0f };

    gfx_set_target(gfx, "test_target", &screen);
    gfx_enable_depth_buffer(gfx, 1);

    gfx_clear(gfx);
    screen_render(gfx, &camera);
    gfx_set_shader(gfx, "text");
    gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform);
    draw_text(fps_str, &fps_rect, 0.0f, 4.9f, &fps_color);
    gfx_flush(gfx);

    static int take_screenshot = 0;
    if (take_screenshot && frames == 0)
    {
        take_screenshot = 0;

        image_t* img = NULL;
        if (gfx_take_screenshot(gfx, &img) == 0)
        {
            image_save_to_png(img, "screenshot.png");
            image_free(img);
        }
    }

    gfx_set_target(gfx, NULL, &screen);
    gfx_enable_depth_buffer(gfx, 0);
    gfx_clear(gfx);

    int32_t sampler = 0;
    rect_t uv = { 0, screen.height/buffer_size.y, screen.width/buffer_size.x, -screen.height/buffer_size.y };

    gfx_set_shader(gfx, "postprocess");
    gfx_set_uniform_mat4f(gfx, "uMVP", 1, &transform);
    gfx_set_uniform_1i(gfx, "uTex", 1, &sampler);
    gfx_set_texture(gfx, "test_texture", sampler);
    gfx_render_textured_rect(gfx, &screen, 1.0f, &uv);
    gfx_set_texture(gfx, NULL, sampler);

    gfx_flush(gfx);

    return 0;
}
int main()
{
	// Print instructions for user
	printf("Asteroid!\nTry to collect as many colored circles as you can.\nThe game is simple. Use the arrow keys to navigate your rocket.\nUp accelerates\nDown brakes immediately\nLeft and Right turn your rocket.\n\nHave fun!!\n");	

	// Define variables
	int xSize=800, ySize=600;
	char c;
	int stillgoing=1;
	float xc=xSize/2, yc=ySize/2, *pxc=&xc, *pyc=&yc;
	float dr=.1;			// rotation increment
	int sign = 1;			// rotation sign
	int r = 15;			// box radius
	int i;				// box counter
	int j;				// triangle counter
	double rotatea=0;		// rotation angle of rocket
	float dx=0, dy=0;		// chane in position of rocket
	float dt=0;			// change in time for acceleration
	float accel=.07;		// acceleration of rocket
	srand(time(NULL));
	int rCir=0;			// radius of circle
	int xCir=xc,yCir=yc;		// position of circle's center
	int rC=255,gC=255,bC=255;	// circle color
	int cirCount=-1;		// number of circles collected(starts at -1 because initial circle is created at center, then random placement begins. Fisrt circle placed at center does not count towards total.
	int isaccel=0;
	double rotatet=rotatea;
	double yRotate=0, xRotate=0;
	float xB, yB;			//  position of fired shot

	gfx_open(xSize,ySize,"Rocketship!");
	
	startGame(xSize, ySize);
	while(stillgoing==1)
	{
		gfx_clear();
		drawAsteroid(xCir,yCir,rCir,rC,gC,bC);	
		drawRocket(xc,yc,rotatet,r);	// uses rotatet, because this will draw the rocket as turning when the left/right arrows are pressed

		scoreboard(cirCount);
		gfx_flush();
		usleep(2000);

		if(gfx_event_waiting()){
			c=gfx_wait();
			switch(c){
				case 'R':	// Accelerate
					dt+=.01;
					dx+=accel*dt;	// increases speed dx by increasing the time and adding to dx
					if(dx>.8) dx=.8;	// this caps dx and dy at 1. Thus the maximum speed is dx=dy=1
					dy=dx;
					isaccel=1;	// the rocket is currently accelerating
					break;
				case 'Q':	// Turn left
					rotatet-=dr;	// decreases angle of rotation
					break;
				case 'S':	// Turn right
//printf("ROTATET: %lf\n",rotatet);
					rotatet+=dr;	// increases angle of rotation
//printf("ROTATET: %lf\n",rotatet);
					break;
				case 'T':	// Brake
					dx=0;		// sets speed dx and dy to 0
					dy=0;
					rotatea=rotatet;
					yRotate=0;
					xRotate=0;
					break;
				case ' ':
					
					fire(rotatet, xc, yc, r);
					break;
				case 'q':	// Quit
					stillgoing=0;
					printf("\nYou collected %i circles!\n",cirCount);
					break;
				default:
					break;
			}
		}
		if(isaccel==1){
		printf("ROTATEA: %lf\n",rotatea);
			if(sin(rotatea)<sin(rotatet)){
				yRotate-=fabs(sin(rotatea+.1));
		printf("check1\n");
			}else if(sin(rotatea)>sin(rotatet)){
				yRotate+=fabs(sin(rotatea-.1));
		printf("check2\n");
			}//else direction of acceleration is equal to direction rocket is facing
			if(cos(rotatea)>cos(rotatet)){
				xRotate-=fabs(cos(rotatea+.1));
		printf("check3\n");
			}else if(cos(rotatea)<cos(rotatet)){
				xRotate+=fabs(cos(rotatea-.1));
		printf("check4\n");
			}
			if(xRotate!=0) rotatea=atan(yRotate/xRotate);
		printf("yRotate: %lf\nxRotate: %lf\nrotatea: %lf\nrotatet: %lf\n",yRotate,xRotate,rotatea,rotatet);
		}

		xc+=dx*cos(rotatea);	// implements x and y speed(dx and dy) by changing position(xc,yc) of rocket at varying rate
		yc+=dy*sin(rotatea);	// why i use rotatea, not rotatet: the rocket will only update the angle of movement, if the rocket is accelerating. This way, you can turn the rocket while it is moving in another direction
		isaccel=0;
		// Transports rocket from one side of screen to other
		wormhole(pxc,pyc,xSize,ySize);
		// Creates new circle if rocket comes too close
		if(sqrt(pow((xc-xCir),2)+pow((yc-yCir),2))<1.6*r+rCir){
			cirCount++;
			rCir=10+rand()%20;
			do{
				xCir=rand()%xSize;
				yCir=rand()%ySize;
				rC=100+rand()%155;
				gC=100+rand()%155;
				bC=100+rand()%155;
			}while(sqrt(pow((xc-xCir),2)+pow((yc-yCir),2))<50);
		}
	}
}
Пример #22
0
int startGame(Pipe* lead, Pipe* trail, int scrWidth, int scrHeight) {

	int loop = 1; 
    int score = 0;
    double birdX = 150, birdY = 275, birdR = 12, birdV = 0, t = .05;
    int flap = 0;
   //#1 - to see game over screen make this while (loop < 5) and uncomment #2
	while (loop) {
        //if bird touches the drawpipe loop = 2

		gfx_clear();
        
        
        //draw background
        drawBackground(scrWidth, scrHeight);
        
        //check for loss
        if ((lead->leadingX-3 <= birdX+16 && lead->trailingX+3 >= birdX-16) &&
            (lead->topHeight >= birdY-16 || lead->bottomHeight <= birdY-16+24)) 
            break;
        if (birdY-16+24 >= scrHeight)
            break;
        
        flap = drawBird(birdX, birdY, birdR, flap);
        updateBird(&birdY, &birdV, &t, birdY, birdV, t);

        if(gfx_event_waiting()){
            char c = gfx_wait();
            if(c == ' ') birdV = -40;
        }
		
        //draw leading pipe
		drawPipe(lead, scrWidth, scrHeight);
        updatePipe(lead);

        //increase the score upon passing through a pair of pipes
        if(lead->trailingX == birdX){
            score++;
        }

        if (lead->trailingX < scrWidth/2) {
            drawPipe(trail, scrWidth, scrHeight);
            updatePipe(trail);
        }
        if (lead->trailingX <= 0) {
            //swap the leader
            Pipe *temp = lead;
            lead = trail;
            trail = temp;
            initializePipe(trail, scrWidth, scrHeight);
        }
   
        //print the score on the top of the screen
        printScore(score, scrWidth);

		gfx_flush(); 
        usleep(10000);
        t+=.001;
		//loop++ #2  -- to see end screen uncomment this and above
	}

    return score;

}
Пример #23
0
int main () {
	char userInput; 
	int i, sideLength;
	double theta, dtheta, numberSides;
	double x, y;
	double x_new, y_new;

	gfx_open(500,500,"Symbol_Emily_Koh");

	//gfx_xpos(); gets x coordinates of mouse pointer
	//gfx_ypos(); gets y coordinates of mouse pointer

	while (1) {
		gfx_event_waiting();
			if (gfx_event_waiting() == True) {
				userInput = gfx_wait();
			}
		
		if (userInput == 1) {
			//if user clicks mouse button 1 then display blue square
			gfx_color(0, 0, 255); //dictates color as blue
			x = gfx_xpos();
			y = gfx_ypos();
			gfx_line(x-50, y-50, x-50, y+50);
			gfx_line(x-50, y-50, x+50, y-50);
			gfx_line(x+50, y-50, x+50, y+50);
			gfx_line(x+50, y+50, x-50, y+50);
		} else if (userInput == 't') {
			//if user types in t then display green triangle
			gfx_color(0, 255, 0); //dictates color as green
			x = gfx_xpos();
			y = gfx_ypos();
			gfx_line(x-50, y-50, x+50, y-50);
			gfx_line(x-50, y-50, x, y+50);
			gfx_line(x, y+50, x+50, y-50);
		} else if (userInput == 'c') {
			//if user types in c then display white circle
			gfx_color(255, 255, 255); //dictates color as white
			x = gfx_xpos();
			y = gfx_ypos();
			gfx_circle(x, y, 50); //circle centered at x, y, and with radius 50
		} else if (userInput >= '3' && userInput <= '9') {
			//if user types in numbers 3~9, display purple polygon with that many sides

			sideLength = 30;

			numberSides = userInput - '0'; //makes numberSides = number of polygon sides

			dtheta = (2*M_PI/numberSides); //calculate the angle at which line will rotate
			theta = 0;

 			gfx_color(171, 92, 223); //dictates color as purple
			x = gfx_xpos();
			y = gfx_ypos();

			x = x + (sideLength/2); //to center polygon, shift polygon by this x and the following y value
			y = y + (sideLength/(2*tan(M_PI/numberSides))); //apothem - perpendicular y distance

			for (i = 0; i < numberSides; i++) {
				theta += dtheta;
				x_new = x + sideLength*cos(theta);
				y_new = y - sideLength*sin(theta);
				gfx_line(x, y, x_new, y_new); 
				gfx_flush();
				x = x_new;
				y = y_new;
			} userInput = '0';
		} else if (userInput == 'q') {
			//if user types in q then quit program
			break;
		}
	}

	// gcc symbol.c gfx_mac.o -lX11 -lm -I/opt/X11/include/ -L/opt/X11/lib/ -o symbol

	return 0;
}
Пример #24
0
int main(void) {

  // Declare & Define Variables
  int xsize; // Window dimensions
  int ysize;
  char input; // For determining user input
  float curxpos; // Position (Location) of the shape
  float curypos;
  float newx;   // For drawing the circle
  float newy;
  float oldx;
  float oldy; 
  double deltat; // Change in time
  float vx; // Velocities in their respective directions
  float vy;
  int radius; // Radius of the figure
  float PI = 3.14159; // Constant PI
  float theta; // Angles
  char c; // Check for input
  float theta2; // Second theta for rotation

  radius = 30;
  xsize = 400;
  ysize = 400;
  curxpos = radius;
  curypos = ysize-radius;
  oldx = curxpos-radius;
  oldy = curypos;
  vx = 0;
  vy = 0;
  srand(time(NULL));
  deltat = 0.01;
  theta2 = 0;

  // Open a new window for drawing
  gfx_open(xsize, ysize, "Rotate");
  while(input != 'q') {
    gfx_clear();
    
    gfx_color(0,255,255);

    gfx_line(curxpos,curypos,curxpos+radius*cos(theta2),curypos+radius*sin(theta2));
    gfx_line(curxpos,curypos,curxpos-radius*cos(theta2),curypos-radius*sin(theta2));
    gfx_line(curxpos,curypos,curxpos+radius*cos(theta2),curypos-radius*sin(theta2));
    gfx_line(curxpos,curypos,curxpos-radius*cos(theta2),curypos+radius*sin(theta2));
  
    
      
    for (theta = 0; theta <= 2*PI; theta+=.01) {
      gfx_color(255,0,0);
       newx = cos(theta)*radius+curxpos;
       newy = sin(theta)*radius+curypos;
       gfx_line(oldx,oldy,newx,newy);
       oldx = newx;
       oldy = newy;
       c = gfx_event_waiting();

       if (c == 1) {
	 input = gfx_wait();
	 if (input == 1) {
	   vx += 1;
	   theta2 += PI/16;
	 }
	 if (input == 3) {
	   vx -= 1;
	   theta -= PI/16;
	 }
	 if (input =='1') {
	   gfx_color(0,255,0);
	 }
	 if (input == '2') {
	   gfx_color(0,0,255);
	 }
	 if (input == '3') {
	   gfx_color(255,0,0);
	 }
	 if (input == '4') {
	   gfx_color(255,255,255);
	 }
	 if (input == 'q') break; 
       }
    }

    if (newx >= xsize || newx <= radius) {
      vx = -vx;
    
    }
    curxpos += vx;
   
 if (vx > 0) {
    theta2 += PI/16;
    }
 if (vx < 0) {
   theta2 -= PI/16;
 }

 if (vx == 0) {
   theta2 = curxpos/curypos;
 }
    gfx_flush();
    usleep(deltat*1000000);
  }
  return 0;
}
int title_screen(const char *commands[100], int *f, double noteinfo[2][1000], char output[1000]){

int xsize=1250;
int ysize=1000;
int xpos;
int ypos;
int height=400;
int width=(xsize-50)/16;
int i,j;
char input[20];
char initial[1000];
char c;
gfx_open(xsize, ysize, "Digital Piano");
quit_button();
draw_title(100);
draw_name(50);
draw_name2(50);
draw_button(295,600,70,310);
draw_button(645,600,70,310);
button_label(60);
button_label2(60);

while (1){

	c=gfx_wait();
	xpos=gfx_xpos();
	ypos=gfx_ypos();
	//user clicks the quit button
	if (xpos>=1110 && xpos<=1210 && ypos>=850 && ypos<=890){
		return 0;
	}

	//user clicks free play button
	if (xpos>=295 && xpos<=605 && ypos>=600 && ypos<=670){
		gfx_clear();
		piano_graphic(commands, f);

	}
	//user clicks load file button
	if (xpos>=645 && xpos<=955 && ypos>=600 && ypos<=670){
		terminal_message();
		printf("Please enter the name of the file, including the extension.\nThe file content should follow the same format as the examples in lab 8:\n");
		scanf("%s", input);
		//scans file name into input
		FILE *music=fopen(input, "r");
		if ((music=fopen(input, "r")) == NULL){
			//returns error if file not found
			puts("File could not be opened");
			return 0;
		}

		else{
			//scans the file into output
			for (j=0; j<1000; j++){
			fscanf(music, "%c", &output[j]);
			if (output[j]=='X'){
				break;
			}
			}
			
		}

		piano2(noteinfo, output);
		//fork to play sound while lighting up keys
		if (fork()){
			system("play sound.wav");
		}
		else{
		gfx_clear();
		draw_piano(width, height);
		draw_arrow(50, f);
		gfx_color(255,255,255);
		draw_box();
		octave_label(30);
		quit_button();
		gfx_flush();
		key_animation(noteinfo, f);
		return 0;
		}
	
	}

}

}
Пример #26
0
int main (void)
{
	char c;
	int xsize=350, ysize=350, vseed, j;
	float x=175, y=175, vx, vy, xMouse, yMouse, dt=1, r=15, ypos, i, di=.1, pi=3.14159;
	
	gfx_open(xsize, ysize, "Bouncing Ball");
	gfx_color(0, 200, 100);
	
	srand(time(0));

	vseed = rand()%100;
	vx = cos((float)vseed/15.915);
	vy = sin((float)vseed/15.915);	
	
	while (1)
	{
		
		for (i=0; i<2*pi; i+=di)
		{
			gfx_line(r*cos(i)+x, -r*sin(i)+y, r*cos(i+di)+x, -r*sin(i+di)+y);
		}
		gfx_flush();
		usleep(dt*10000);
		gfx_clear();
		
		x = x+vx*dt;
		y = y+vy*dt;
		
		if ( x<=15 || x>=335 )
			vx = -vx;
		if ( y<=15 || y>=335 )
			vy = -vy;
		
		j = gfx_event_waiting();
		
		if (j)
		{
			c = gfx_wait();
			switch (c)
			{
				case 'q':
					return 0;
					
				case 1:
					xMouse = gfx_xpos();
					yMouse = gfx_ypos();
		
					x = xMouse;
					y = yMouse;
					vseed = rand()%100;
					vx = cos((float)vseed/15.915);
					vy = sin((float)vseed/15.915);
					
					break;
			}	
		}
			
	}
	
	return 0;
}