Exemplo n.º 1
0
void redraw(unsigned int* framePointer)
{
	drawAliens();
	drawHUD();
	drawBullets(0x00FF0000);
	draw_bunker(0x0000FF00);
	draw_tank(0x0000FF00);
	drawAliens();
	drawHUD();
	drawBullets(0x00FF0000);
	draw_bunker(0x0000FF00);
	draw_tank(0x0000FF00);
}
Exemplo n.º 2
0
void render_tanks()
{
    for (int i=0; i<Players.count; i++) {
        struct player *cur_pl = dyn_arr_get(&Players, i);
        if (cur_pl->state != PS_DEAD)
            draw_tank( cur_pl == loc_player ? COL_W : COL_Y,
                dx, dy, cur_pl->pos.x, cur_pl->pos.y, 0);
    }
}
Exemplo n.º 3
0
void space(void) {
	byte c;
	byte move_left, move_right;
	char delay_count;
	byte do_exit;

	move_left = 0;
	move_right = 0;
	shot_y = 0;
	shot_x = 0;
	inv_shot_y = 0;
	inv_shot_x = 0;
	do_exit = 0;

	clrbuf();
	init_game();

	delay_count = 0;
	do {
		clrbuf();
		draw_invaders();
		draw_tank(tank_pos);
		
		// tank shot
		tank_shot();

		// invader shot
		invaders_shot();

		buf2screen();

		// delay invader movement
		if (++delay_count >= 5 - ((char)inv_pos_y / 3)) {
			delay_count = 0;
			move_invaders();
		}

		// delay
		if (inv_count < 14)
			delay_ms((14 - inv_count));

		// read keyboard
		c = io_read(129);
		if (c == 0xe0) {
			c = io_read(129);
			if (c == 0x6b) { // left down
				move_left = 1;
			} else if (c == 0x74) { // right down
				move_right = 1;
			} else if (c == 0x6b + 0x80) { // left up
				move_left = 0;
			} else if (c == 0x74 + 0x80) { // right up
				move_right = 0;
			}
		} else if (c == 0x29) { // shoot
			if (shot_y == 0) {
				shot_x = (tank_pos + 1) * 2 + 1;
				shot_y = 90;
			}
		}
		else if (c == 0x76) { // escape
			do_exit = 1;
		}

		// move tank
		if (move_left) {
			if (tank_pos > 0)
				tank_pos -= 1;
		} else if (move_right) {
			if (tank_pos < 76)
				tank_pos += 1;
		}

	} while (!do_exit);
}
Exemplo n.º 4
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;
}
Exemplo n.º 5
0
Sint16 draw_world (Sint16 zoom)
{
	Sint16 x, y, wx, wy, gtype, hud_bottom;
	Sint16 max_x, max_y;

	SDL_Rect src;
	SDL_Rect dst;
	
	src.x = 0;
	src.y = 0;
	src.w = TILE_WIDTH;
	src.h = TILE_WIDTH;
	
	struct tank *tank;
	
	/* check limits */
	if (world_up_x < 0) world_up_x = 0;
	if (world_up_y < 0) world_up_y = 0;
	if (world_up_x > world_width - 1) world_up_x = world_width - 1;
	if (world_up_y > world_height - 1) world_up_y = world_height - 1;
	
	if (zoom == 1)
	{
		hud_bottom = 4;		/* tile height of HUD */
	}
	else
	{
		hud_bottom = 2;		/* tile height of HUD */
	}
	
	max_x = world_up_x + (screen_width / (TILE_WIDTH * zoom));
	max_y = world_up_y + (screen_height / (TILE_WIDTH * zoom)) - hud_bottom;
	
	if (max_x >= world_width) max_x = world_width - 1;
	if (max_y >= world_height) max_y = world_height - 1;
	
	boxRGBA (screen, 0, 0, screen_width - 1, screen_height - 1, 238, 231, 38, 255);
	SDL_UpdateRect (screen, 0, 0, 0, 0);
	
	y = 0;
	for (wy = world_up_y; wy < max_y; wy++)
	{
		x = 0;
		for (wx = world_up_x; wx < max_x; wx++)
		{
			dst.x = x;
			dst.y = y;
			dst.w = TILE_WIDTH;
			dst.h = TILE_WIDTH;
			
			gtype = world[wy][wx];
			
			if (zoom == 1)
			{
				if (SDL_BlitSurface (ground[gtype], &src, screen, &dst) != 0)
				{
					printf("SDL_BlitSurface on world tile failed: %s\n", SDL_GetError());
				}
			}
			else
			{
				if (SDL_BlitSurface (ground[gtype], &src, screen, &dst) != 0)
				{
					printf("SDL_BlitSurface on world tile failed: %s\n", SDL_GetError());
				}
				
				dst.x = x + TILE_WIDTH;
				
				if (SDL_BlitSurface (ground[gtype], &src, screen, &dst) != 0)
				{
					printf("SDL_BlitSurface on world tile failed: %s\n", SDL_GetError());
				}
				
				dst.y = y + TILE_WIDTH;
					
				if (SDL_BlitSurface (ground[gtype], &src, screen, &dst) != 0)
				{
					printf("SDL_BlitSurface on world tile failed: %s\n", SDL_GetError());
				}
				
				dst.x = x;
				
				if (SDL_BlitSurface (ground[gtype], &src, screen, &dst) != 0)
				{
					printf("SDL_BlitSurface on world tile failed: %s\n", SDL_GetError());
				}
			}
			
			x += (TILE_WIDTH * zoom);
		}
		y += (TILE_WIDTH * zoom);
	}
	
	/* draw units zoomed in 1x */
	
	for (wy = world_up_y; wy < max_y; wy++)
	{
		for (wx = world_up_x; wx < max_x; wx++)
		{
			if (unit[wy][wx].type == TANK)
			{
				printf ("TANK: %i / %i\n", wx, wy);
				tank = (struct tank *) unit[wy][wx].data;
				
				draw_tank (wx, wy, unit[wy][wx].color, tank->aim_angle, TILE_WIDTH * zoom);
			}
		}
	}
	
	draw_unit_info (unit_info_wx, unit_info_wy, TILE_WIDTH * zoom);
	
	update_screen ();	
}