Example #1
0
void
Spotlight::draw(DrawingContext& context)
{
  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);

  light->set_color(color);
  light->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
  light->set_angle(angle);
  light->draw(context, position, 0);

  //lightcone->set_angle(angle);
  //lightcone->draw(context, position, 0);

  context.set_target(DrawingContext::NORMAL);

  lights->set_angle(angle);
  lights->draw(context, position, 0);

  base->set_angle(angle);
  base->draw(context, position, 0);

  center->draw(context, position, 0);

  lightcone->set_angle(angle);
  lightcone->draw(context, position, LAYER_FOREGROUND1 + 10);

  context.pop_target();
}
Example #2
0
void
TileMap::draw(DrawingContext& context)
{
  // skip draw if current opacity is 0.0
  if (current_alpha == 0.0) return;

  context.push_transform();
  if(draw_target != DrawingContext::NORMAL) {
    context.push_target();
    context.set_target(draw_target);
  }

  if(drawing_effect != 0) context.set_drawing_effect(drawing_effect);

  if (editor_active) {
    if(current_alpha != 1.0) {
      context.set_alpha(current_alpha);
    }
  } else {
    context.set_alpha(current_alpha/2);
  }

  /* Force the translation to be an integer so that the tiles appear sharper.
   * For consistency (i.e., to avoid 1-pixel gaps), this needs to be done even
   * for solid tilemaps that are guaranteed to have speed 1.
   * FIXME Force integer translation for all graphics, not just tilemaps. */
  float trans_x = roundf(context.get_translation().x);
  float trans_y = roundf(context.get_translation().y);
  context.set_translation(Vector(int(trans_x * speed_x),
                                 int(trans_y * speed_y)));

  Rectf draw_rect = Rectf(context.get_translation(),
        context.get_translation() + Vector(SCREEN_WIDTH, SCREEN_HEIGHT));
  Rect t_draw_rect = get_tiles_overlapping(draw_rect);
  Vector start = get_tile_position(t_draw_rect.left, t_draw_rect.top);

  Vector pos;
  int tx, ty;

  for(pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
    for(pos.y = start.y, ty = t_draw_rect.top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) {
      int index = ty*width + tx;
      assert (index >= 0);
      assert (index < (width * height));

      if (tiles[index] == 0) continue;
      const Tile* tile = tileset->get(tiles[index]);
      assert(tile != 0);
      tile->draw(context, pos, z_pos);
    } /* for (pos y) */
  } /* for (pos x) */

  if(draw_target != DrawingContext::NORMAL) {
    context.pop_target();
  }
  context.pop_transform();
}
Example #3
0
void
Light::draw(DrawingContext& context)
{
  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);
  
  sprite->draw(context, Sector::current()->player->get_pos(), 0);
  
  context.pop_target();
}
Example #4
0
void
MrCandle::draw(DrawingContext& context) {
  BadGuy::draw(context);

  if (!frozen) {
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    candle_light->draw(context, bbox.get_middle(), 0);
    context.pop_target();
  }
}
Example #5
0
void
LiveFire::draw(DrawingContext& context)
{
  //Draw the Sprite.
  sprite->draw(context, get_pos(), LAYER_OBJECTS);
  //Draw the light
  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);
  lightsprite->draw(context, get_bbox().get_middle(), 0);
  context.pop_target();
}
Example #6
0
void
Lantern::draw(DrawingContext& context){
  //Draw the Sprite.
  MovingSprite::draw(context);
  //Let there be light.
  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);

  lightsprite->draw(context, bbox.get_middle(), 0);

  context.pop_target();
}
void
TreeWillOWisp::draw(DrawingContext& context)
{
  sprite->draw(context, get_pos(), layer);

  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);

  sprite->draw(context, get_pos(), layer);

  context.pop_target();
}
void
WillOWisp::draw(DrawingContext& context)
{
  sprite->draw(context, get_pos(), LAYER_OBJECTS);
  
  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);

  sprite->draw(context, get_pos(), LAYER_OBJECTS);
  
  context.pop_target();
}
Example #9
0
void
BonusBlock::draw(DrawingContext& context){
  // do the regular drawing first
  Block::draw(context);
  // then Draw the light if on.
  if(sprite->get_action() == "on") {
    Vector pos = get_pos() + (bbox.get_size().as_vector() - lightsprite->get_size()) / 2;
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    context.draw_surface(lightsprite, pos, 10);
    context.pop_target();
  }
}
Example #10
0
void
WillOWisp::draw(DrawingContext& context)
{
  sprite->draw(context, get_pos(), layer);

  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);

  sprite->draw(context, get_pos(), layer);
  lightsprite->draw(context, bbox.get_middle(), 0);

  context.pop_target();
}
Example #11
0
void
Light::draw(DrawingContext& context)
{
  context.push_target();
  context.set_target(DrawingContext::LIGHTMAP);

  sprite->set_color(color);
  sprite->set_blend(Blend(GL_SRC_ALPHA, GL_ONE));
  sprite->set_angle(90); // FIXME: color won't get applied for angle=0
  sprite->draw(context, position, 0);

  context.pop_target();
}
Example #12
0
void
Star::draw(DrawingContext& context){
  //Draw the Sprite.
  MovingSprite::draw(context);
  //Draw the light when dark
  context.get_light( get_bbox().get_middle(), &light );
  if (light.red + light.green + light.blue < 3.0){
    MovingSprite::draw(context);
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    lightsprite->draw(context, get_bbox().get_middle(), 0);
    context.pop_target();
  }
}
Example #13
0
void
Explosion::draw(DrawingContext& context)
{
  //Draw the Sprite.
  sprite->draw(context, get_pos(), LAYER_OBJECTS+40);
  //Explosions produce light (if ambient light is not maxed)
  context.get_light( get_bbox().get_middle(), &light);
  if (light.red + light.green + light.blue < 3.0){
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    lightsprite->draw(context, get_bbox().get_middle(), 0);
    context.pop_target();
  }
}
Example #14
0
void
Flower::draw(DrawingContext& context)
{
  //Draw the Sprite.
  sprite->draw(context, get_pos(), LAYER_OBJECTS, drawing_effect);
  //Draw the light when dark
  context.get_light( get_bbox().get_middle(), &light );
  if (light.red + light.green + light.blue < 3.0){
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    lightsprite->draw(context, get_bbox().get_middle(), 0);
    context.pop_target();
  }
}
Example #15
0
void
Kugelblitz::draw(DrawingContext& context)
{
  sprite->draw(context, get_pos(), layer);
  
  //Only draw light in dark areas
  context.get_light( get_bbox().get_middle(), &light );
  if (light.red + light.green < 2.0){
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    sprite->draw(context, get_pos(), layer);
    lightsprite->draw(context, get_bbox().get_middle(), 0);
    context.pop_target();
  }
}
Example #16
0
void
Ghostflame::draw(DrawingContext& context)
{
  //Draw the Sprite.
  sprite->draw(context, get_pos(), LAYER_OBJECTS);
  //Draw the light if dark
  context.get_light( bbox.get_middle(), &light );
  if (light.blue + light.red < 2.0){
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    sprite->draw(context, get_pos(), layer);
    lightsprite->draw(context, bbox.get_middle(), 0);
    context.pop_target();
  }
}
Example #17
0
void
IceCrusher::draw(DrawingContext& context)
{
  context.push_target();
  context.set_target(DrawingContext::NORMAL);
  sprite->draw(context, get_pos(), layer+2);
  if(!(state == CRUSHING) && sprite->has_action("whites"))
  {
    // draw icecrusher's eyes slightly behind
    lefteye->draw(context, get_pos()+eye_position(false), layer+1);
    righteye->draw(context, get_pos()+eye_position(true), layer+1);
    // draw the whites of icecrusher's eyes even further behind
    whites->draw(context, get_pos(), layer);
  }
  context.pop_target();
}
Example #18
0
void
Iceflame::draw(DrawingContext& context)
{
  context.push_target();
  //Rotate the Sprite (3 rotations per revolution)
  sprite->set_angle(angle * 360.0f / (2*M_PI) * 3);
  //Draw the Sprite.
  sprite->draw(context, get_pos(), LAYER_OBJECTS);
  //Draw the light if dark
  context.get_light( get_bbox().get_middle(), &light );
  if (light.blue + light.green < 2.0){
    context.set_target(DrawingContext::LIGHTMAP);
    lightsprite->draw(context, get_bbox().get_middle(), 0);
  }
  context.pop_target();
}
Example #19
0
void
GhostTree::draw(DrawingContext& context)
{
  BadGuy::draw(context);

  context.push_target();
  context.push_transform();
  context.set_target(DrawingContext::LIGHTMAP);
  if (mystate == STATE_SUCKING) {
    context.set_alpha(0.5 + fmodf(game_time, 0.5));
  } else {
    context.set_alpha(0.5);
  }
  glow_sprite->draw(context, get_pos(), layer);
  context.pop_transform();
  context.pop_target();
}
Example #20
0
void
PowerUp::draw(DrawingContext& context){
  //Draw the Sprite.
  sprite->draw(context, get_pos(), layer);
  //Draw light when dark for defaults
  context.get_light( bbox.get_middle(), &light );
  if (light.red + light.green + light.blue < 3.0){
    //Stars are brighter
    if (sprite_name == "images/powerups/star/star.sprite") {
      sprite->draw(context, get_pos(), layer);
    }
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    lightsprite->draw(context, bbox.get_middle(), 0);
    context.pop_target();
  }
}
Example #21
0
void
Bullet::draw(DrawingContext& context)
{
  //Draw the Sprite.
  sprite->draw(context, get_pos(), LAYER_OBJECTS);
  //Draw the light if fire and dark
  if(type == FIRE_BONUS){
    context.get_light( get_bbox().get_middle(), &light );
    if (light.red + light.green < 2.0){
      context.push_target();
      context.set_target(DrawingContext::LIGHTMAP);
      sprite->draw(context, get_pos(), LAYER_OBJECTS);
      lightsprite->draw(context, get_bbox().get_middle(), 0);
      context.pop_target();
    }
  }
}
Example #22
0
void
WeakBlock::draw(DrawingContext& context)
{
  //Draw the Sprite just in front of other objects
  sprite->draw(context, get_pos(), LAYER_OBJECTS + 10);
  //Draw the light if burning and dark
  if(linked && (state != STATE_NORMAL)){
    context.get_light( bbox.get_middle(), &light );
    if (light.red + light.green + light.blue < 3.0){
      context.push_target();
      context.set_target(DrawingContext::LIGHTMAP);
      sprite->draw(context, get_pos(), LAYER_OBJECTS + 10);
      lightsprite->draw(context, bbox.get_middle(), 0);
      context.pop_target();
    }
  }
}
Example #23
0
void
SpriteParticle::draw(DrawingContext& context)
{
  sprite->draw(context, position, drawing_layer);

  //Sparkles glow in the dark
  if(glow){
    context.get_light(position, &light );
    if (light.red + light.green + light.blue < 3.0){
      context.push_target();
      context.set_target(DrawingContext::LIGHTMAP);
      sprite->draw(context, position, drawing_layer);
      lightsprite->draw(context, position + Vector(12,12), 0);
      context.pop_target();
    }
  }

}
Example #24
0
void
Candle::draw(DrawingContext& context)
{
  // draw regular sprite
  sprite->draw(context, get_pos(), layer);

  // draw on lightmap
  if (burning) {
    //Vector pos = get_pos() + (bbox.get_size() - candle_light_1->get_size()) / 2;
    context.push_target();
    context.set_target(DrawingContext::LIGHTMAP);
    // draw approx. 1 in 10 frames darker. Makes the candle flicker
    if (gameRandom.rand(10) != 0 || !flicker) {
      //context.draw_surface(candle_light_1, pos, layer);
      candle_light_1->draw(context, get_bbox().get_middle(), 0);
    } else {
      //context.draw_surface(candle_light_2, pos, layer);
      candle_light_2->draw(context, get_bbox().get_middle(), 0);
    }
    context.pop_target();
  }
}
Example #25
0
void
TileMap::draw(DrawingContext& context)
{
  // skip draw if current opacity is 0.0
  if (current_alpha == 0.0) return;

  context.push_transform();
  if(draw_target != DrawingContext::NORMAL) {
    context.push_target();
    context.set_target(draw_target);
  }

  if(drawing_effect != 0) context.set_drawing_effect(drawing_effect);
  if(current_alpha != 1.0) context.set_alpha(current_alpha);

  /* Force the translation to be an integer so that the tiles appear sharper.
   * For consistency (i.e., to avoid 1-pixel gaps), this needs to be done even
   * for solid tilemaps that are guaranteed to have speed 1.
   * FIXME Force integer translation for all graphics, not just tilemaps. */
  float trans_x = roundf(context.get_translation().x);
  float trans_y = roundf(context.get_translation().y);
  context.set_translation(Vector(int(trans_x * speed_x),
                                 int(trans_y * speed_y)));

  Rectf draw_rect = Rectf(context.get_translation(),
        context.get_translation() + Vector(SCREEN_WIDTH, SCREEN_HEIGHT));
  Rect t_draw_rect = get_tiles_overlapping(draw_rect);

  // Make sure the tilemap is within draw view
  if (t_draw_rect.is_valid()) {
    Vector start = get_tile_position(t_draw_rect.left, t_draw_rect.top);

    Vector pos;
    int tx, ty;

    for(pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
      for(pos.y = start.y, ty = t_draw_rect.top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) {
        int index = ty*width + tx;
        assert (index >= 0);
        assert (index < (width * height));

        if (tiles[index] == 0) continue;
        const Tile* tile = tileset->get(tiles[index]);
        assert(tile != 0);

        tile->draw(context, pos, z_pos, current_tint);
      } /* for (pos y) */
    } /* for (pos x) */

    /* Make sure that tiles with images larger than 32x32 that overlap
     * the draw rect will be drawn, even if their tile position does
     * not fall within the draw rect. */
    static const int EXTENDING_TILES = 32;
    int ex_left = std::max(0, t_draw_rect.left-EXTENDING_TILES);
    int ex_top = std::max(0, t_draw_rect.top-EXTENDING_TILES);
    Vector ex_start = get_tile_position(ex_left, ex_top);

    for (pos.x = start.x, tx = t_draw_rect.left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
      for (pos.y = ex_start.y, ty = ex_top; ty < t_draw_rect.top; pos.y += 32, ++ty) {
        int index = ty*width + tx;
        assert (index >= 0);
        assert (index < (width * height));

        if (tiles[index] == 0) continue;
        const Tile* tile = tileset->get(tiles[index]);
        assert(tile != 0);

        SurfacePtr image = tile->get_current_image();
        if (image) {
          int h = image->get_height();
          if (h <= 32) continue;

          if (pos.y + h > start.y)
            tile->draw(context, pos, z_pos, current_tint);
        }
      }
    }

    for (pos.x = ex_start.x, tx = ex_left; tx < t_draw_rect.right; pos.x += 32, ++tx) {
      for(pos.y = ex_start.y, ty = ex_top; ty < t_draw_rect.bottom; pos.y += 32, ++ty) {
        int index = ty*width + tx;
        assert (index >= 0);
        assert (index < (width * height));

        if (tiles[index] == 0) continue;
        const Tile* tile = tileset->get(tiles[index]);
        assert(tile != 0);

        SurfacePtr image = tile->get_current_image();
        if (image) {
          int w = image->get_width();
          int h = image->get_height();
          if (w <= 32 && h <= 32) continue;

          if (pos.x + w > start.x && pos.y + h > start.y)
            tile->draw(context, pos, z_pos, current_tint);
        }
      }
    }
  }

  if(draw_target != DrawingContext::NORMAL) {
    context.pop_target();
  }
  context.pop_transform();
}