int main(int argc, char **argv){
  awake_the_weaver(); // Initializing Weaver API
  
  camera *cam = new_camera(0.0, 0.0, 100.0, 100.0);
  circle *star   = new_circle(50.0, 50.0, 20.0);
  circle *planet = new_circle(90.0, 90.0,  5.0);
  rectangle *trash = new_rectangle(75.0, 50.0, 1.25, 2.5);
  rectangle *ufo   = new_rectangle(25.0, 50.0, 1.5,  1.5);
  film_fullcircle(cam, star, YELLOW);
  film_fullcircle(cam, planet, BLUE);
  film_rectangle(cam, trash, GREEN);
  film_fullrectangle(cam, ufo, WHITE);

  int camera_moved = 0;

  // Main loop
  for(;;){
    get_input();
    if(keyboard[ESC]){
      break;
    }
	if(keyboard[UP] || keyboard[DOWN] || keyboard[LEFT] || keyboard[RIGHT] ||
			keyboard[MINUS] || keyboard[PLUS] || keyboard[ENTER]){
		film_fullcircle(cam, star, BLACK);
		film_fullcircle(cam, planet, BLACK);
		film_rectangle(cam, trash, BLACK);
		film_fullrectangle(cam, ufo, BLACK);
		camera_moved = 1;
	}
	if(keyboard[UP])
		cam -> y -= 1.0;
	if(keyboard[DOWN])
		cam -> y += 1.0;
	if(keyboard[LEFT])
		cam -> x -= 1.0;
	if(keyboard[RIGHT])
		cam -> x += 1.0;
	if(keyboard[PLUS])
		zoom_camera(cam, 1.01);
	if(keyboard[MINUS])
		zoom_camera(cam, 0.99);
	if(keyboard[ENTER])
		center_camera(cam, 50.0, 50.0);

	film_fullcircle(cam, planet, BLACK);
	rotate_circle(planet, 50.0, 50.0, 0.01);
	film_fullcircle(cam, planet, BLUE);

	if(camera_moved){
		film_fullcircle(cam, star, YELLOW);
		film_rectangle(cam, trash, GREEN);
		film_fullrectangle(cam, ufo, WHITE);
		camera_moved = 0;
	}

    weaver_rest(10000000);
  }
  may_the_weaver_sleep();
  return 0;
}
示例#2
0
void copyleft(void){
  int width, height;
  surface *c = new_image("copyleft.png");
  width = c -> width;
  height = c -> height;
  fill_screen(BLACK);
  draw_surface(c, window, (window_width - width)/2, 
	       (window_height - height)/2);
  weaver_rest(1);
  sleep(1);
  destroy_surface(c);
  return;
}
示例#3
0
void intro(void){
  int i, sound = 0;
  time_t begin, now;
  float speed[6];
  circle *planet[6], *moon1;
  camera *cam = new_camera(0.0, 0.0, 800.0, 800.0);
  surface *dark_weaver = new_image("dark_weaver.png");
  surface *credits = new_image("credits.png");
  for(i = 0; i < 6; i ++){
    speed[i] = ((rand() % 20) + 10) / 1000.0;
    planet[i] = new_circle(450.0 + i*50, 450.0 + i*50, (rand() % 20) + 10.0);
  }
  moon1 = new_circle(planet[2] -> x + 40.0, planet[2] -> y + 40.0, 10.0);
  limit_camera(cam, window_width / 2 - 400, window_height / 2 - 400,
	       800, 800);
  begin = time(NULL);
  initialize_star();
  for(;;){
    now = time(NULL);
    if(now - begin > 3){
      draw_surface(dark_weaver, window, 
		   (window_width - dark_weaver -> width) / 2, 
		   (window_height - dark_weaver -> height) / 2);
      draw_surface(credits, window, (window_width - credits -> width) / 2, 0);
      if(sound == 0){
	sound = 1;
	play_sound("weaver.ogg");
      }
      if(now - begin > 5)
	break;
    }
    for(i = 0; i < 6; i ++)
      erase_fullcircle(cam, planet[i]);
    erase_fullcircle(cam, moon1);
    for(i = 0; i < 6; i ++)
      rotate_circle(planet[i], 400.0, 400.0, speed[i]);
    rotate_circle(moon1, planet[2] -> x, planet[2] -> y, speed[2]*10.0);
    film_fullcircle(cam, planet[0], 0x220000);
    film_fullcircle(cam, planet[1], 0x002200);
    film_fullcircle(cam, planet[2], 0x000022);
    film_fullcircle(cam, planet[3], 0x002222);
    film_fullcircle(cam, planet[4], 0x220022);
    film_fullcircle(cam, planet[5], 0x222222);
    film_fullcircle(cam, moon1, 0x444400);
    update_star();
    weaver_rest(10000000);
  }
  destroy_surface(dark_weaver);
  destroy_surface(credits);
  destroy_star();
}
示例#4
0
int main(int argc, char **argv){
  unsigned type = PLR_X_CPU;
  int key_pressed = 0;
  awake_the_weaver(); // Initializing Weaver API
  hide_cursor();
  copyleft();
  intro();
  surface *title = new_image("title.png");
  for(;;){
    int esc_pressed = 0;
    int x = (window_width - title -> width) / 2; 
    int y = (window_height - title -> height) / 2;
    fill_screen(BLACK); 
    draw_surface(title, window, x, y);
    draw_gametype(type % 4, x + 120, y + 60);
    key_pressed = 0;
    for(;;){
      get_input();
      if(keyboard[ESC]){
	esc_pressed = 1;
	break;
      }
      if(keyboard[ENTER]){
	fill_screen(BLACK);
	flush();
	game(type % 4);
	break;
      }
      else if(keyboard[LEFT]){
	if(!key_pressed){
	  type --;
	  draw_gametype(type % 4, x + 120, y + 60);
	}
      }
      else if(keyboard[RIGHT]){
	if(!key_pressed){
	  type ++;
	  draw_gametype(type % 4, x + 120, y + 60);
	}
      }
      key_pressed = keyboard[ANY];
      weaver_rest(10000000);
    }
    if(esc_pressed)
      break;
  }
  destroy_surface(title);
  may_the_weaver_sleep();
  return 0;
}
示例#5
0
int game(int type){
  int game_over = 0;
  {
    surface *background = new_image("background.png");
    apply_texture(background, window);
    destroy_surface(background);
  }
  initialize_cameras();initialize_star();initialize_ships(2);initialize_dust();
  initialize_shot();initialize_ai();
  play_music("music.ogg");
  draw_tank(0, (window_width / 2 - 421), window_height / 2 - 150);
  draw_tank(1, window_width / 2 + 401, window_height / 2 - 150);
    // Main loop
  for(;;){
    int i;
    get_input();
    if(keyboard[ESC] || game_over){
      break;
    }
    
    for(i = 0; i < 2; i ++)
      if(ship[i].status == DEAD){
	struct timeval now;
	gettimeofday(&now, NULL);
	if((int) (now.tv_sec - ship[i].time.tv_sec) > 2)
	  game_over = 1;
      }



    erase_ships();    
    erase_shot();     
    
    if(type != CPU_X_CPU){ // Rotation: 10 Propulse: 20 Fire: 20 Hyper: 180 
      int my_ship;
      // Player 1 moves
      if(type == CPU_X_PLR){
	ai_play(0);
	my_ship = 1;
      }
      else if(type == PLR_X_CPU){
	my_ship = 0;
	ai_play(1);
      }
      else
	my_ship = 0;
      if(keyboard[LEFT])
	rotate_ship(my_ship, LEFT); 
      if(keyboard[RIGHT])
	rotate_ship(my_ship, RIGHT);
      if(keyboard[UP])
	propulse_ship(my_ship);
      if(keyboard[DOWN])
	ship_fire(my_ship);
      if(keyboard[RIGHT_CTRL])
	goto_hyperspace(my_ship);
    }
    else{
      ai_play(0);
      ai_play(1);
    }

    if(type == PLR_X_PLR){ 
      // Player 2 moves
      if(keyboard[A])
	rotate_ship(1, LEFT);
      if(keyboard[D])
	rotate_ship(1, RIGHT);
      if(keyboard[W])
	propulse_ship(1);
      if(keyboard[L])
	blow_up(1);
      if(keyboard[S])
	ship_fire(1);
      if(keyboard[LEFT_CTRL])
	goto_hyperspace(1);
    }
    
    update_star(); // 6
    update_ships(); // 2
    update_dust(); // 145
    update_shot(); // 16
    film_ships(); // Até 16
    film_dust(); // 20
    film_shot(); // Até 20
    weaver_rest(10000000);
  }
  stop_music();
  destroy_star();
  destroy_ships();
  destroy_cameras();
  destroy_dust();
  destroy_shot();
  clean_keyboard();
  return 0;
}
int main(int argc, char **argv){

  awake_the_weaver(); // Initializing Weaver API

  fill_screen(SCREEN_COLOR);

  // define the parametres
  circle ** many_circles;
  float ball_x, ball_y, radius;
  float *dx, *dy;
  int c_id;
  int num_circles = CIRCLE_NUMBER;
  if(argc > 1)
	  sscanf(argv[1], "%d", &num_circles);

  // alloc the memory
  many_circles = (circle *) malloc(num_circles* sizeof(circle*));
  dx = (float*)malloc(num_circles* sizeof(float));
  dy = (float*)malloc(num_circles* sizeof(float));

  // initialize the values
  for(c_id = 0; c_id < num_circles; c_id ++)
  {
	  radius = 50 + rand() % 50;
	  ball_x = window_width / 2;
	  ball_y = window_height / 2;
	  many_circles[c_id] = new_circle(ball_x, ball_y, radius);
	  unsigned int c_color = rand() % 3;
	  draw_circle(ball_x, ball_y, radius, c_color == 0?RED:c_color==1?GREEN:BLUE);
	  dx[c_id] = (rand() % 200 - 100) / 80.f;
	  dy[c_id] = (rand() % 200 - 100) / 80.f;
  }

  // Main loop
  for(;;){
    get_input();

    if(keyboard[ANY]){
      break;
    }
	
	// update status
	for(c_id = 0; c_id < num_circles; c_id ++)
	{
		draw_circle(many_circles[c_id] -> x, many_circles[c_id] -> y, many_circles[c_id] -> z, SCREEN_COLOR); // to erase

		ball_x = many_circles[c_id] -> x;
		ball_y = many_circles[c_id] -> y;
		radius = many_circles[c_id] -> z;

		ball_x += dx[c_id];
		ball_y += dy[c_id];
		if(ball_y < radius || ball_y > window_height - radius)
			dy[c_id]*= -1;
		if(ball_x < radius || ball_x > window_width - radius)
			dx[c_id]*= -1;

		many_circles[c_id] -> x	= ball_x;
		many_circles[c_id] -> y	= ball_y;
		unsigned int c_color = rand() % 3;
		draw_circle(many_circles[c_id] -> x, many_circles[c_id] -> y, many_circles[c_id] -> z, c_color == 0?RED:c_color==1?GREEN:BLUE); // to erase
	}
	weaver_rest(10000000);
  }

  free(many_circles);
  free(dx);
  free(dy);
  may_the_weaver_sleep();
  return 0;
}