Пример #1
0
// converts a dead person in black particles
void Person::burn()
{
  GamePlay *gameplay = GAMEPLAY;
  BITMAP *sprite = prepare_sprite();
  int x, y, u, v;

  gameplay->get_level()->to_screen(m_pos, x, y);

  x = x-TILE_W/2;
  y = y-TILE_H+1;

  for (v=0; v<sprite->h; ++v)
    for (u=0; u<sprite->w; ++u) {
      int color, ou;

      if (m_right)
	color = getpixel(sprite, ou=u, v);
      else
	color = getpixel(sprite, ou=sprite->w-1-u, v);

      if (color != bitmap_mask_color(sprite))
	gameplay->add_particle
	  (new PixelParticle(vector2d((m_pos.x*TILE_W - TILE_W/2 + ou) / TILE_W,
				      (m_pos.y*TILE_H - TILE_H+1 + v) / TILE_H),
			     vector2d(0, rand_range(-2.0, -0.1)),
			     vector2d(rand_range(0.5, 4.0), 0),
			     rand_range(BPS/4, BPS*3/4),
			     makecol(0, 0, 0),
			     makecol(0, 0, 0)));

    }
}
Пример #2
0
struct sprite* create_sprite(struct image* image, int w, int h)
{
    struct sprite* sprite = (struct sprite*)malloc(sizeof(struct sprite));
    if (sprite != NULL && prepare_sprite(sprite, image, w, h) == -1) {
        free(sprite);
        return NULL;
    }
    return sprite;
}
void
Sprite2DView::next_image(int i)
{
  if (directory.size() > 1)
  {
    if (new_sprite)
    {
      sprite = new_sprite;
      sprite.set_alpha(1.0f);
      new_sprite = Sprite();
      offset = 0;
      display_time = 0;
    }

    index = static_cast<unsigned int>(index + i) % directory.size();

    std::vector<Pathname> dir;

    if (shuffle)
      dir = shuffle_directory;
    else
      dir = directory;
      
    bool retry = false;

    do 
    {
      try 
      {
        new_sprite = Sprite(dir[index]);
        retry = false;
      } 
      catch(std::exception& e) 
      {
        // FIXME: won't work in combination with shuffle
        std::cout << "Error: " << e.what() << std::endl;
        std::cout << "Removing '" << directory[index] << "' from the list" << std::endl;
        directory.erase(directory.begin() + index);
        index = static_cast<unsigned int>(index) % directory.size();
        retry = true;
      }
    } 
    while (retry);

    ignore_delta = true;
    fadein = 0.0f;
    prepare_sprite(new_sprite);
    ConsoleLog << index << ": " << directory[index] << std::endl;
  }

  SpriteManager::current()->cleanup();
  SurfaceManager::current()->cleanup();
}