int main()
{
	int i, off=0, on=1, lports[]=LIGHT_PORTS, pcnt, w=40, m=5;
	float s;
	graphics_open(320,240);
	for(i=0;i<256;i+=5) {
		graphics_fill(i,i,i);
		graphics_update();
	}
	SplashBG(320, 240);
	msleep(1000);
	graphics_close();
	pcnt=NPORTS(lports);
	for(i=8;i<16;i++) { // change the digital ports to output
		set_digital_output(i,1);
	}
	srand(time(NULL)); // prime random number generation
	while(1) { 
		table_lights(lports,pcnt,off); // shut off table lights
		setup(); // team setup (light calibration w/time out option)
		// setup done, including any time outs so proceed with judge's setup
		//get_shelf_positions(); // display orange/yellow block set up for judges - 2014
		get_bgal_pod_positions(); // display left-right positions for Botgal & pod - 2015
		set_a_button_text("QUIT");	set_b_button_text("-"); set_c_button_text("-");
		graphics_close();  // close any open graphics
		graphics_open(3*w,62);	
		display_clear();
		display_printf(0,0,"************** BOTBALL 2015 **************");
		display_printf(0,1,"               LIGHTS ON IN");
		display_printf(0,2,"******************************************");
		display_printf(0,9,"      Press QUIT to stop count down");
		if (countdown_sd(5,1,BLUE,YELLOW,m,w)) continue;
		s=seconds();
		// 2015
		table_lights(lports,pcnt,on); // on for 115 seconds	
		display_printf(0,1,"     GAME CLOCK - LIGHTS ON TILL 5");
		if (countdown(120,11,GREEN,BLUE,m,w)) continue;
		// end 2015
		/*
		// 2014	
		table_lights(lports,pcnt,on); // on for 15 seconds	
		display_printf(0,1,"     GAME CLOCK - LIGHTS ON TILL 105");
		if (countdown(120,106,GREEN,BLUE,m,w)) continue;
		table_lights(lports,pcnt,off); // of for 100 seconds	
		display_printf(0,1,"      GAME CLOCK - LIGHTS OFF TILL 5");
		if (countdown(105,11,LTBLUE,RED,m,w)) continue;
		// end 2014
		*/
		if (countdown(10,6,LTORANGE,BLUE,m,w)) continue;
		display_printf(0,1,"     GAME CLOCK - LIGHTS BLINK TILL 0");
		i=5+(seconds()-s);
		if (blinkdown(5,0,RED,YELLOW,m,w,lports,pcnt)) continue;
		display_printf(0,1,"            GAME CLOCK - %d          ",i);
		display_printf(0,9,"          ***** GAME OVER! *****     ");
		table_lights(lports,pcnt,off); // shut off table lights
		msleep(5000); // pause display
	}
	return 0;
}
Example #2
0
/**
*@brief Initialized Main window
*/
void Init_Graphics(
    char *windowName,
    int viewWidth,
    int viewHeight,
    int renderWidth,
    int renderHeight,
    float bgcolor[4])
{
    bool quit = false;


    if(SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        printf("Unable to initilaize SDL sys: %s",SDL_GetError());
        graphics_close();
        return;
    } else {
        printf("SDL Init Success\n");
    }

    window = SDL_CreateWindow(windowName,SDL_WINDOWPOS_UNDEFINED,
                              SDL_WINDOWPOS_UNDEFINED,
                              renderWidth, renderHeight,
                              SDL_WINDOW_SHOWN);
    if(!window)
    {
        fprintf(stdout,"Window creation failed: %s",SDL_GetError());
        graphics_close();
        return;
    }
    buffer = SDL_GetWindowSurface(window);

    renderer = SDL_CreateRenderer(window,-1,SDL_RENDERER_ACCELERATED
                                  | SDL_RENDERER_TARGETTEXTURE);
    if (!renderer)
    {
        printf("failed to create renderer: %s",SDL_GetError());
        graphics_close();
        return;
    } else {
        printf("SDL Renderer Success\n");
    }
    if(TTF_Init() == -1)
    {
        printf("Failed to init TTF");
        graphics_close();
        return;
    }

}
void graphics_initialize(char *windowName, int viewWidth, int viewHeight, int renderWidth, int renderHeight, int fullscreen)
{
    Uint32 flags = 0;
    if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
    {
        slog("Unable to initilaize SDL system: %s",SDL_GetError());
        return;
    }
    atexit(SDL_Quit);
    if (fullscreen)
    {
        if (renderWidth == 0)
        {
            flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
        }
        else
        {
            flags |= SDL_WINDOW_FULLSCREEN;
        }
    }
    graphicsMainWindow = SDL_CreateWindow(windowName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, renderWidth, renderHeight, flags);
    if (!graphicsMainWindow)
    {
        slog("failed to create main window: %s",SDL_GetError());
        graphics_close();
        return;
    }
    
    graphicsRenderer = SDL_CreateRenderer(graphicsMainWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE);
    if (!graphicsRenderer)
    {
        slog("failed to create renderer: %s",SDL_GetError());
        graphics_close();
        return;
    }
    
    SDL_RenderClear(graphicsRenderer);
    SDL_RenderPresent(graphicsRenderer);
	//sets a hint with normal priority, this specifically sets the scaling quality to be linear, this is supported by OpenGL and Direct3D
    SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
    //sets a device independent resolution for rendering
	SDL_RenderSetLogicalSize(graphicsRenderer, renderWidth, renderHeight);
    
    atexit(graphics_close);
    slog("graphics initialized\n");
}
void blinking_light() {
	while(BCHK); // debounce
	graphics_close(); // close any existing window
	graphics_open(45,45);
	graphics_fill(WHITE);
	while(!(BCHK)) {
		graphics_circle_fill(24, 24, 20, GRAY);
		graphics_circle_fill(24, 24, 8, YELLOW);
		graphics_line(6, 24, 42, 24, YELLOW);  // horizontal
		graphics_line(24, 6, 24, 42, YELLOW);  // vertical
		graphics_line(12, 12, 36, 36, YELLOW); // forward slash
		graphics_line(12, 36, 36, 12, YELLOW); // back slash
		graphics_update(); 
		msleep(250);
		if(BCHK) break;
		graphics_circle_fill(24, 24, 20, GRAY);
		graphics_update();
		msleep(250);
	}
	graphics_close();
}
Example #5
0
int main(int argc, char *argv[])
{
	if(!graphics_open(640, 480)) return 0;
	
	while(1) {
		usleep(1);
		graphics_rectangle(0, 0, 30, 30, 255, 0, 0);
		graphics_update();
	}
	
	graphics_close();
	
	return 0;
}
Example #6
0
/**
*@brief Main game loop
*/
void Loop()
{
	int quit = 0;
	do
	{
		SDL_PollEvent(mainEvent);
		handleInput(game->gameState);	
		quit = game->gameState();
			

		}
	while(!quit && mainEvent->type != SDL_QUIT);
	graphics_close();
	exit(0);
	delete mainEvent;
	return;
}
void get_bgal_pod_positions()
{
	// screen size (scols,srows), box size (bxcols,bxcols), separator m pixels
	// random block positions p1, p2 set by function picks
	int srows=120,scols=160, bpos, ppos;
	graphics_close(); // close any existing graphics window
	display_clear();  // prep screen
	set_a_button_text("COUNTDOWN");	set_b_button_text("-"); set_c_button_text("-");
	graphics_open(scols,srows);
	graphics_fill(WHITE);
	bpos=rand()%2;
	if (bpos==0) ppos=1;
	else ppos=0;	
	// draw field
	graphics_rectangle(3,3,157,117,BLACK);        // outline
	graphics_rectangle(3,3,70,50,BLACK);          // quads
	graphics_rectangle(90,3,157,50,BLACK);
	graphics_rectangle(3,70,70,117,BLACK);
	graphics_rectangle(90,70,157,117,BLACK);
	graphics_rectangle_fill(70,3,90,50,LTBROWN);         // mesa
	graphics_rectangle(70,3,90,50,BLACK);
	graphics_rectangle_fill(70,70,90,117,LTBROWN);
	graphics_rectangle(70,70,90,117,BLACK); 
	graphics_rectangle_fill(72,50,88,70,LTGRAY);  // caldera
	graphics_rectangle(72,50,88,70,BLACK);
	graphics_rectangle_fill(20,3,25,50,TEAL);     // lines
	graphics_rectangle_fill(135,3,140,50,TEAL);
	graphics_rectangle_fill(20,70,25,117,PINK);
	graphics_rectangle_fill(135,70,140,117,PINK);	
	if (bpos==0) { 
		draw_bg(73,13,0.2);
		graphics_rectangle_fill(74,87,86,102,GREEN);
	}
	else {
		draw_bg(73,82,0.2);
		graphics_rectangle_fill(74,18,86,32,GREEN);
	}
	graphics_update();
	
	display_printf(2,0,"Set Botgal and Botpod ");
	
	while(a_button()==0);
	while(a_button()==1); // debounce
}
Example #8
0
int main()
{
	camera_open();
	camera_update();
	graphics_open(get_camera_width(), get_camera_height());
	
	while(!get_key_state('Q'))
	{
		camera_update();
		graphics_blit_enc(get_camera_frame(), BGR, 0, 0, get_camera_width(), get_camera_height());
		graphics_circle_fill(get_camera_width() / 2, get_camera_height() / 2, get_camera_height() / 20, 255, 0, 0);
		graphics_update();
	}
	
	camera_close();
	graphics_close();
	
	return 0;
}
Example #9
0
int main(int argc, char ** argv)
{
	graphics_open(100,100);

	int x, j;
	for (j = 0; j < 10; ++j)
	{
		for (x = 0; x < 100; ++x)
		{
			graphics_clear();
			graphics_circle_fill(x, 50, 5, 255, 0, 0);
			graphics_update();
			msleep(10);
		}
	}

	graphics_close();

	return 0;
}
int main(int argc, char** argv)
{
  if(!depth_open())
  {
    printf("Unable to open libkipr_link_depth_sensor\n");
    return 1;
  }

  int depth_image_height = -1;
  int depth_image_width = -1;

  int mouse_x;
  int mouse_y;

  int last_max_depth = 6000 /* mm */;
  int max_depth;

  if(set_depth_camera_resolution(DEPTH_CAMERA_RESOLUTION_640_480) == 0)
  {
    printf("Failed to set the depth camera resolution to 640 x 480\n");
    return 1;
  }
  
#ifdef CAMERA_IS_UPSIDE_DOWN
  if(set_depth_camera_orientation(DEPTH_CAMERA_ORIENTATION_UPSIDE_DOWN) == 0)
  {
    printf("Failed to set the depth camera orientation\n");
    return 1;
  }
#endif

  printf("Press 'Q' to stop\n");

  while(!get_key_state('Q'))
  {
    if(depth_update())
    {
      if(depth_image_height == -1)
      {
        // initialize the graphics output
        depth_image_height = depth_image_get_height();
        depth_image_width = depth_image_get_width();

        graphics_open(depth_image_width, depth_image_height);
      }

      get_mouse_position(&mouse_x, &mouse_y);
      max_depth = 0;

      // display depth image
      for(int y = 0; y < depth_image_height; y++)
      {
        for(int x = 0; x < depth_image_width; x++)
        {
          int depth = get_depth_value(x, y);

          // save max depth
          if(depth > max_depth)
          {
            max_depth = depth;
          }

          // color invalid depth pixel red
          if((depth != INVALID_COORDINATE) && last_max_depth)
          {
            int r;
            int g;
            int b;

            HSVtoRGB(360*0xFF*depth/last_max_depth, &r, &g, &b);

            graphics_pixel(x, y, r, g, b);
          }
          else
          {
            graphics_pixel(x, y, 0xFF, 0xFF, 0xFF);
          }

          #ifdef SHOW_DEPTH_UNDER_MOUSE
            if(mouse_x == x && mouse_y == y)
            {
              console_clear();
              if(depth != INVALID_COORDINATE)
              {
                printf("(%d, %d): Depth: %d mm; World coordinate: (%d, %d, %d)\n", x, y, depth, get_world_x(x, y), get_world_y(x, y), get_world_z(x, y));
              }
              else
              {
                printf("(%d, %d): No information available\n", x, y);
              }
            }
          #endif
        }
      }

      last_max_depth = max_depth;

      graphics_update();
    }
    else
    {
      printf("No depth image received yet\n");
      msleep(2000);
    }
  }

  graphics_close();
  depth_close();

  return 0;
}
Example #11
0
int main(int argc, char *argv[])
{	
	char input = 0;
	char save_name[50];


	//Prepare engine
	Engine *engine = prepare_game(save_name);

	GoF_Screen *screen = screen_create(0, 0, 30, 30, 20);
	Graphics g;
	graphics_init(&g, 800, 900, "The Game of Life!");

	input = 0;
	while(input != 'k')
	{
		screen_draw(screen, &g, engine);
		input = graphics_event(&g);

		if(input == 1)
			engine_add_entity(engine, entity_create(g.last_x/screen->entity_length, g.last_y/screen->entity_length));
		else if(input == 3)
			engine_remove_entity(engine, g.last_x/screen->entity_length, g.last_y/screen->entity_length);
	}

	//Input
	input = 0;
	int sens = 5;

	//Main game loop
	while(input != 'q')
	{	
		//Draw on screen
		screen_draw(screen, &g, engine);

		//Update Engine
		engine_update(engine);
		
		//Process input
		while(graphics_check_event(&g))
		{
			input = graphics_event(&g);
			switch(input)
			{
				case 'p':
					engine->ups++;
					break;
				case 'm':
					if(engine->ups > 1)
						engine->ups--;
					break;
				case '.':
					sens++;
					break;
				case ',':
					if(sens > 1)
						sens--;
					break;
				case UP_ARROW:
					screen->y -= sens;
					break;
				case DOWN_ARROW:
					screen->y += sens;
					break;
				case LEFT_ARROW:
					screen->x -= sens;
					break;
				case RIGHT_ARROW:
					screen->x += sens;
					break;
			}
		}

		//Sleep
		usleep((1000/engine->ups) * 1000);
	}

	//Close graphics
	graphics_close(&g);

	//Save game
	printf("Saving game...\n");
	engine_save(engine, save_name);

	//Free mem
	engine_free(engine);
	screen_free(screen);

	return 0;
}