void
InfoBox::draw(DrawingContext& context)
{
  float x1 = 200;
  float y1 = 100;
  float width = 400;
  float height = 200;

  context.draw_filled_rect(Vector(x1, y1), Vector(width, height),
      Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-1);

  float y = y1;
  for(size_t i = firstline; i < lines.size(); ++i) {
    if(y >= y1 + height) break;

    lines[i]->draw(context, Vector(x1, y), LAYER_GUI);
    y += lines[i]->get_height();

    // draw the scrolling arrows
    if (arrow_scrollup && firstline > 0)
      context.draw_surface(arrow_scrollup,
      Vector( x1 + width  - arrow_scrollup->get_width(),  // top-right corner of box
              y1), LAYER_GUI);

    if (arrow_scrolldown && firstline < lines.size()-1)
      context.draw_surface(arrow_scrolldown,
      Vector( x1 + width  - arrow_scrolldown->get_width(),  // bottom-light corner of box
              y1 + height - arrow_scrolldown->get_height()),
              LAYER_GUI);
  }
}
void
Background::draw(DrawingContext& context)
{
  if(image.get() == NULL)
    return;
    
  int w = (int) image->get_width();
  int h = (int) image->get_height();
  int sx = int(pos.x-context.get_translation().x * speed) % w - w;
  int sy = int(pos.y-context.get_translation().y * speed_y) % h - h;
  int center_image_py = int(pos.y-context.get_translation().y * speed_y);
  int bottom_image_py = int(pos.y-context.get_translation().y * speed_y) + h;
  context.push_transform();
  context.set_translation(Vector(0, 0));
  for(int x = sx; x < SCREEN_WIDTH; x += w) {
    for(int y = sy; y < SCREEN_HEIGHT; y += h) {
      if (image_top.get() != NULL && (y < center_image_py)) {
        context.draw_surface(image_top.get(), Vector(x, y), layer);
        continue;
      } 
      if (image_bottom.get() != NULL && (y >= bottom_image_py)) {
        context.draw_surface(image_bottom.get(), Vector(x, y), layer);
        continue;
      }
      context.draw_surface(image.get(), Vector(x, y), layer);
    }
  }
  context.pop_transform();
}
void
Tile::draw(DrawingContext& context, const Vector& pos, int z_pos) const
{
  if(images.size() > 1) {
    size_t frame = size_t(game_time * anim_fps) % images.size();
    context.draw_surface(images[frame], pos, z_pos);
  } else if (images.size() == 1) {
    context.draw_surface(images[0], pos, z_pos);
  }
}
Exemple #4
0
void
Console::draw(DrawingContext& context)
{
  if (m_height == 0)
    return;

  int layer = LAYER_GUI + 1;

  context.push_transform();
  context.set_alpha(m_alpha);
  context.draw_surface(m_background2,
                       Vector(SCREEN_WIDTH/2 - m_background->get_width()/2 - m_background->get_width() + m_backgroundOffset,
                              m_height - m_background->get_height()),
                       layer);
  context.draw_surface(m_background2,
                       Vector(SCREEN_WIDTH/2 - m_background->get_width()/2 + m_backgroundOffset,
                              m_height - m_background->get_height()),
                       layer);
  for (int x = (SCREEN_WIDTH/2 - m_background->get_width()/2
                - (static_cast<int>(ceilf((float)SCREEN_WIDTH /
                                          (float)m_background->get_width()) - 1) * m_background->get_width()));
       x < SCREEN_WIDTH;
       x += m_background->get_width())
  {
    context.draw_surface(m_background, Vector(x, m_height - m_background->get_height()), layer);
  }
  m_backgroundOffset+=10;
  if (m_backgroundOffset > (int)m_background->get_width()) m_backgroundOffset -= (int)m_background->get_width();

  int lineNo = 0;

  if (m_focused) {
    lineNo++;
    float py = m_height-4-1 * m_font->get_height();
    context.draw_text(m_font, "> "+m_inputBuffer, Vector(4, py), ALIGN_LEFT, layer);
    if (SDL_GetTicks() % 1000 < 750) {
      int cursor_px = 2 + m_inputBufferPosition;
      context.draw_text(m_font, "_", Vector(4 + (cursor_px * m_font->get_text_width("X")), py), ALIGN_LEFT, layer);
    }
  }

  int skipLines = -m_offset;
  for (std::list<std::string>::iterator i = m_buffer.m_lines.begin(); i != m_buffer.m_lines.end(); i++)
  {
    if (skipLines-- > 0) continue;
    lineNo++;
    float py = m_height - 4 - lineNo * m_font->get_height();
    if (py < -m_font->get_height()) break;
    context.draw_text(m_font, *i, Vector(4, py), ALIGN_LEFT, layer);
  }
  context.pop_transform();
}
void ParticleSystem::draw(DrawingContext& context)
{
  float scrollx = context.get_translation().x;
  float scrolly = context.get_translation().y;

  context.push_transform();
  context.set_translation(Vector(max_particle_size,max_particle_size));

  std::vector<Particle*>::iterator i;
  for(i = particles.begin(); i != particles.end(); ++i) {
    Particle* particle = *i;

    // remap x,y coordinates onto screencoordinates
    Vector pos;

    pos.x = fmodf(particle->pos.x - scrollx, virtual_width);
    if(pos.x < 0) pos.x += virtual_width;

    pos.y = fmodf(particle->pos.y - scrolly, virtual_height);
    if(pos.y < 0) pos.y += virtual_height;

    //if(pos.x > virtual_width) pos.x -= virtual_width;
    //if(pos.y > virtual_height) pos.y -= virtual_height;

    context.draw_surface(particle->texture, pos, particle->angle, Color(1.0f, 1.0f, 1.0f), Blend(), z_pos);
  }

  context.pop_transform();
}
Exemple #6
0
void
ItemToggle::draw(DrawingContext& context, const Vector& pos, int menu_width, bool active) {
  context.draw_text(Resources::normal_font, text,
                    Vector(pos.x + 16, pos.y - (Resources::normal_font->get_height()/2)),
                    ALIGN_LEFT, LAYER_GUI, active ? ColorScheme::Menu::active_color : get_color());

  if(*toggled) {
    context.draw_surface(Resources::checkbox_checked,
                         Vector(pos.x + menu_width-16 - Resources::checkbox->get_width(), pos.y - 8),
                         LAYER_GUI + 1);
  } else {
    context.draw_surface(Resources::checkbox,
                         Vector(pos.x + menu_width-16 - Resources::checkbox->get_width(), pos.y - 8),
                         LAYER_GUI + 1);
  }
}
Exemple #7
0
void
ItemBack::draw(DrawingContext& context, Vector pos, int menu_width, bool active) {
  float text_width = Resources::normal_font->get_text_width(text);
  context.draw_text(Resources::normal_font, text,
                    Vector( pos.x + menu_width/2 , pos.y - int(Resources::normal_font->get_height()/2)),
                    ALIGN_CENTER, LAYER_GUI, active ? ColorScheme::Menu::active_color : get_color());
  context.draw_surface(Resources::back,
                       Vector(pos.x + menu_width/2 + text_width/2  + 16, pos.y - 8),
                       LAYER_GUI);
}
Exemple #8
0
void
ItemStringSelect::draw(DrawingContext& context, const Vector& pos, int menu_width, bool active) {
  float roff = Resources::arrow_left->get_width();
  float sel_width = Resources::normal_font->get_text_width(list[*selected]);
  // Draw left side
  context.draw_text(Resources::normal_font, text,
                    Vector(pos.x + 16, pos.y - int(Resources::normal_font->get_height()/2)),
                    ALIGN_LEFT, LAYER_GUI, active ? ColorScheme::Menu::active_color : get_color());

  // Draw right side
  context.draw_surface(Resources::arrow_left,
                       Vector(pos.x + menu_width - sel_width - 2*roff - 8, pos.y - 8),
                       LAYER_GUI);
  context.draw_surface(Resources::arrow_right,
                       Vector(pos.x + menu_width - roff - 8, pos.y - 8),
                       LAYER_GUI);
  context.draw_text(Resources::normal_font, list[*selected],
                    Vector(pos.x + menu_width - roff - 8, pos.y - int(Resources::normal_font->get_height()/2)),
                    ALIGN_RIGHT, LAYER_GUI, active ? ColorScheme::Menu::active_color : get_color());
}
Exemple #9
0
void
Tile::draw(DrawingContext& context, const Vector& pos, int z_pos) const
{
  if(draw_editor_images) {
    if(editor_images.size() > 1) {
      size_t frame = size_t(game_time * fps) % editor_images.size();
      context.draw_surface(editor_images[frame], pos, z_pos);
      return;
    } else if (editor_images.size() == 1) {
      context.draw_surface(editor_images[0], pos, z_pos);
      return;
    }
  }

  if(images.size() > 1) {
    size_t frame = size_t(game_time * fps) % images.size();
    context.draw_surface(images[frame], pos, z_pos);
  } else if (images.size() == 1) {
    context.draw_surface(images[0], pos, z_pos);
  }
}
void ParticleSystem_Interactive::draw(DrawingContext& context)
{
  context.push_transform();

  std::vector<Particle*>::iterator i;
  for(i = particles.begin(); i != particles.end(); ++i) {
    Particle* particle = *i;
    context.draw_surface(particle->texture, particle->pos, z_pos);
  }

  context.pop_transform();
}
void ParticleSystem_Interactive::draw(DrawingContext& context)
{
  if(!enabled)
    return;

  context.push_transform();

  for(auto& particle : particles) {
    context.draw_surface(particle->texture, particle->pos, z_pos);
  }

  context.pop_transform();
}
Exemple #12
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();
  }
}
Exemple #13
0
void
InfoBox::draw(DrawingContext& context)
{
  float x1 = SCREEN_WIDTH/2-200;
  float y1 = SCREEN_HEIGHT/2-200;
  float width = 400;
  float height = 200;

  context.draw_filled_rect(Vector(x1, y1), Vector(width, height),
                           Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-1);

  float y = y1;
  bool linesLeft = false;
  for(size_t i = firstline; i < lines.size(); ++i) {
    if(y >= y1 + height) {
      linesLeft = true;
      break;
    }

    lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
    y += lines[i]->get_height();
  }

  {
    // draw the scrolling arrows
    if (arrow_scrollup.get() && firstline > 0)
      context.draw_surface(arrow_scrollup,
                           Vector( x1 + width  - arrow_scrollup->get_width(),  // top-right corner of box
                                   y1), LAYER_GUI);

    if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
      context.draw_surface(arrow_scrolldown,
                           Vector( x1 + width  - arrow_scrolldown->get_width(),  // bottom-light corner of box
                                   y1 + height - arrow_scrolldown->get_height()),
                           LAYER_GUI);
  }
}
void
LayerIcon::draw(DrawingContext& context, Vector pos) {
  if (!is_valid()) return;

  ObjectIcon::draw(context,pos);
  int l = get_zpos();
  if (l != std::numeric_limits<int>::min()) {
    context.draw_text(Resources::small_font, std::to_string(l),
                      pos + Vector(16,16),
                      ALIGN_CENTER, LAYER_GUI, ColorScheme::Menu::default_color);
    if (is_tilemap) if (((TileMap*)layer)->editor_active) {
      context.draw_surface(selection, pos, LAYER_GUI - 1);
    }
  }
}
void
InfoBoxLine::draw(DrawingContext& context, const Vector& position, int layer)
{
  switch (lineType) {
    case IMAGE:
      context.draw_surface(image, Vector( (SCREEN_WIDTH - image->get_width()) / 2, position.y), layer);
      break;
    case NORMAL_LEFT:
      context.draw_text(font, text, Vector(position.x, position.y), LEFT_ALLIGN, layer);
      break;
    default:
      context.draw_text(font, text, Vector(SCREEN_WIDTH/2, position.y), CENTER_ALLIGN, layer);
      break;
  }
}
void
TextScroller::draw(DrawingContext& context)
{
  context.draw_surface(background.get(), Vector(0,0), 0);

  float y = SCREEN_HEIGHT - scroll;
  for(size_t i = 0; i < lines.size(); i++) {
    lines[i]->draw(context, Vector(LEFT_BORDER, y), LAYER_GUI);
    y += lines[i]->get_height();
  }

  if(y < 0 && !fading ) {
    fading = true;
    main_loop->exit_screen(new FadeOut(0.5));
  }
}
Exemple #17
0
void
InfoBoxLine::draw(DrawingContext& context, const Rectf& bbox, int layer)
{
  Vector position = bbox.p1;
  switch (lineType) {
    case IMAGE:
      context.draw_surface(image, Vector( (bbox.p1.x + bbox.p2.x - image->get_width()) / 2, position.y), layer);
      break;
    case NORMAL_LEFT:
      context.draw_text(font, text, Vector(position.x, position.y), ALIGN_LEFT, layer, color);
      break;
    default:
      context.draw_text(font, text, Vector((bbox.p1.x + bbox.p2.x) / 2, position.y), ALIGN_CENTER, layer, color);
      break;
  }
}
Exemple #18
0
void
Yeti::draw_hit_points(DrawingContext& context)
{
  if (hud_head)
  {
    context.push_transform();
    context.set_translation(Vector(0, 0));

    for (int i = 0; i < hit_points; ++i)
    {
      context.draw_surface(hud_head, Vector(BORDER_X + (i * hud_head->get_width()), BORDER_Y + 1), LAYER_FOREGROUND1);
    }

    context.pop_transform();
  }
}
Exemple #19
0
void
PlayerStatus::draw(DrawingContext& context)
{
  int player_id = 0;

  if ((displayed_coins == DISPLAYED_COINS_UNSET) ||
      (std::abs(displayed_coins - coins) > 100)) {
    displayed_coins = coins;
    displayed_coins_frame = 0;
  }
  if (++displayed_coins_frame > 2) {
    displayed_coins_frame = 0;
    if (displayed_coins < coins) displayed_coins++;
    if (displayed_coins > coins) displayed_coins--;
  }
  displayed_coins = std::min(std::max(displayed_coins, 0), MAX_COINS);

  std::stringstream ss;
  ss << displayed_coins;
  std::string coins_text = ss.str();

  context.push_transform();
  context.set_translation(Vector(0, 0));

  if (coin_surface)
  {
    context.draw_surface(coin_surface,
                         Vector(SCREEN_WIDTH - BORDER_X - coin_surface->get_width() - Resources::fixed_font->get_text_width(coins_text),
                                BORDER_Y + 1 + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
                         LAYER_HUD);
  }
  context.draw_text(Resources::fixed_font,
                    coins_text,
                    Vector(SCREEN_WIDTH - BORDER_X - Resources::fixed_font->get_text_width(coins_text),
                           BORDER_Y + (Resources::fixed_font->get_text_height(coins_text) + 5) * player_id),
                    ALIGN_LEFT,
                    LAYER_HUD,
                    PlayerStatus::text_color);

  context.pop_transform();
}
void
TileSet::draw_tile(DrawingContext& context, uint32_t id, const Vector& pos,
                   int z_pos, Color color) const
{
  if (id == 0) return;
  Tile* tile;
  if (id >= m_tiles.size()) {
    tile = NULL;
  } else {
    tile = m_tiles[id].get();
  }

  if (tile) {
    tile->load_images();
    tile->draw(context, pos, z_pos, color);
  } else if (Editor::is_active()) { // Draw a notile sign
    context.draw_surface(notile_surface, pos, 0, color, Blend(), z_pos);
    context.draw_text(Resources::small_font, std::to_string(id),
                      pos + Vector(16, 16), ALIGN_CENTER, z_pos, color);
  }
}
Exemple #21
0
void
TextScroller::draw(DrawingContext& context)
{
    context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
                             Color(0.6f, 0.7f, 0.8f, 0.5f), 0);
    context.draw_surface(background, Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0);

    float y = SCREEN_HEIGHT - scroll;
    for(size_t i = 0; i < lines.size(); i++) {
        if (y + lines[i]->get_height() >= 0 && SCREEN_HEIGHT - y >= 0) {
            lines[i]->draw(context, Rectf(LEFT_BORDER, y, SCREEN_WIDTH - 2*LEFT_BORDER, y), LAYER_GUI);
        }

        y += lines[i]->get_height();
    }

    if(y < 0 && !fading ) {
        fading = true;
        g_screen_manager->exit_screen(new FadeOut(0.5));
    }
}
Exemple #22
0
void
LevelTime::draw(DrawingContext& context)
{
  context.push_transform();
  context.set_translation(Vector(0, 0));

  if ((time_left > TIME_WARNING) || (int(game_time * 2.5) % 2)) {
    std::stringstream ss;
    ss << int(time_left);
    std::string time_text = ss.str();

    if (time_surface)
    {
      float all_width = time_surface->get_width() + Resources::normal_font->get_text_width(time_text);
      context.draw_surface(time_surface, Vector((SCREEN_WIDTH - all_width)/2, BORDER_Y + 1), LAYER_FOREGROUND1);
      context.draw_text(Resources::normal_font, time_text,
                        Vector((SCREEN_WIDTH - all_width)/2 + time_surface->get_width(), BORDER_Y),
                        ALIGN_LEFT, LAYER_FOREGROUND1, LevelTime::text_color);
    }
  }

  context.pop_transform();
}
void MouseCursor::draw(DrawingContext& context)
{
  if (m_state != MC_HIDE)
  {
    int x;
    int y;
    Uint8 ispressed = SDL_GetMouseState(&x, &y);

    Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(x, y);

    x = int(mouse_pos.x);
    y = int(mouse_pos.y);

    int tmp_state = m_state;
    if (ispressed & SDL_BUTTON(1) || ispressed & SDL_BUTTON(2))
    {
      tmp_state = MC_CLICK;
    }

    context.draw_surface(m_cursor[static_cast<int>(tmp_state)],
                         Vector(x - m_mid_x, y - m_mid_y),
                         LAYER_GUI + 100);
  }
}
Exemple #24
0
void
Menu::draw_item(DrawingContext& context, int index)
{
  float menu_height = get_height();
  float menu_width  = get_width();

  MenuItem& pitem = *(items[index]);

  Color text_color = ColorScheme::Menu::default_color;
  float x_pos       = pos.x;
  float y_pos       = pos.y + 24*index - menu_height/2 + 12;
  int text_width  = int(Resources::normal_font->get_text_width(pitem.text));
  int input_width = int(Resources::normal_font->get_text_width(pitem.input) + 10);
  int list_width = 0;

  float left  = pos.x - menu_width/2 + 16;
  float right = pos.x + menu_width/2 - 16;

  if(pitem.list.size() > 0) {
    list_width = (int) Resources::normal_font->get_text_width(pitem.list[pitem.selected]);
  }

  if (arrange_left)
    x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2;

  if(index == active_item)
  {
    text_color = ColorScheme::Menu::active_color;
  }

  if(active_item == index)
  {
    float blink = (sinf(real_time * M_PI * 1.0f)/2.0f + 0.5f) * 0.5f + 0.25f;
    context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10 - 2, y_pos - 12 - 2),
                                   Vector(pos.x + menu_width/2 - 10 + 2, y_pos + 12 + 2)),
                             Color(1.0f, 1.0f, 1.0f, blink),
                             14.0f,
                             LAYER_GUI-10);
    context.draw_filled_rect(Rectf(Vector(pos.x - menu_width/2 + 10, y_pos - 12),
                                   Vector(pos.x + menu_width/2 - 10, y_pos + 12)),
                             Color(1.0f, 1.0f, 1.0f, 0.5f),
                             12.0f,
                             LAYER_GUI-10);
  }

  switch (pitem.kind)
  {
    case MN_INACTIVE:
    {
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, ColorScheme::Menu::inactive_color);
      break;
    }

    case MN_HL:
    {
      // TODO
      float x = pos.x - menu_width/2;
      float y = y_pos - 12;
      /* Draw a horizontal line with a little 3d effect */
      context.draw_filled_rect(Vector(x, y + 6),
                               Vector(menu_width, 4),
                               Color(0.6f, 0.7f, 1.0f, 1.0f), LAYER_GUI);
      context.draw_filled_rect(Vector(x, y + 6),
                               Vector(menu_width, 2),
                               Color(1.0f, 1.0f, 1.0f, 1.0f), LAYER_GUI);
      break;
    }
    case MN_LABEL:
    {
      context.draw_text(Resources::big_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::big_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, ColorScheme::Menu::label_color);
      break;
    }
    case MN_TEXTFIELD:
    case MN_NUMFIELD:
    case MN_CONTROLFIELD:
    {
      if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
      {
        if(active_item == index)
          context.draw_text(Resources::normal_font,
                            pitem.get_input_with_symbol(true),
                            Vector(right, y_pos - int(Resources::normal_font->get_height()/2)),
                            ALIGN_RIGHT, LAYER_GUI, ColorScheme::Menu::field_color);
        else
          context.draw_text(Resources::normal_font,
                            pitem.get_input_with_symbol(false),
                            Vector(right, y_pos - int(Resources::normal_font->get_height()/2)),
                            ALIGN_RIGHT, LAYER_GUI, ColorScheme::Menu::field_color);
      }
      else
        context.draw_text(Resources::normal_font, pitem.input,
                          Vector(right, y_pos - int(Resources::normal_font->get_height()/2)),
                          ALIGN_RIGHT, LAYER_GUI, ColorScheme::Menu::field_color);

      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(left, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_LEFT, LAYER_GUI, text_color);
      break;
    }
    case MN_STRINGSELECT:
    {
      float roff = Resources::arrow_left->get_width();
      // Draw left side
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(left, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_LEFT, LAYER_GUI, text_color);

      // Draw right side
      context.draw_surface(Resources::arrow_left,
                           Vector(right - list_width - roff - roff, y_pos - 8),
                           LAYER_GUI);
      context.draw_surface(Resources::arrow_right,
                           Vector(right - roff, y_pos - 8),
                           LAYER_GUI);
      context.draw_text(Resources::normal_font, pitem.list[pitem.selected],
                        Vector(right - roff, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_RIGHT, LAYER_GUI, text_color);
      break;
    }
    case MN_BACK:
    {
      context.draw_text(Resources::Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, text_color);
      context.draw_surface(Resources::back,
                           Vector(x_pos + text_width/2  + 16, y_pos - 8),
                           LAYER_GUI);
      break;
    }

    case MN_TOGGLE:
    {
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x - menu_width/2 + 16, y_pos - (Resources::normal_font->get_height()/2)),
                        ALIGN_LEFT, LAYER_GUI, text_color);

      if(pitem.toggled)
        context.draw_surface(Resources::checkbox_checked,
                             Vector(x_pos + (menu_width/2-16) - Resources::checkbox->get_width(), y_pos - 8),
                             LAYER_GUI + 1);
      else
        context.draw_surface(Resources::checkbox,
                             Vector(x_pos + (menu_width/2-16) - Resources::checkbox->get_width(), y_pos - 8),
                             LAYER_GUI + 1);
      break;
    }
    case MN_ACTION:
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, text_color);
      break;

    case MN_GOTO:
      context.draw_text(Resources::normal_font, pitem.text,
                        Vector(pos.x, y_pos - int(Resources::normal_font->get_height()/2)),
                        ALIGN_CENTER, LAYER_GUI, text_color);
      break;
  }
}
Exemple #25
0
void
Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, SurfacePtr backdrop)
{
  // skip draw if stats were declared invalid
  if (!valid) return;

  // abort if we have no backdrop
  if (!backdrop) return;

  // no sense drawing stats if there are none
  if (total_coins + total_badguys + total_secrets == 0) return;

  int box_w = 220+110+110;
  int box_h = 30+20+20+20;
  int box_x = (int)((SCREEN_WIDTH - box_w) / 2);
  int box_y = (int)(SCREEN_HEIGHT / 2) - box_h;

  int bd_w = (int)backdrop->get_width();
  int bd_h = (int)backdrop->get_height();
  int bd_x = (int)((SCREEN_WIDTH - bd_w) / 2);
  int bd_y = box_y + (box_h / 2) - (bd_h / 2);

  int col1_x = box_x;
  int col2_x = col1_x+200;
  int col3_x = col2_x+130;

  int row1_y = box_y;
  int row2_y = row1_y+30;
  int row3_y = row2_y+20;
  int row4_y = row3_y+20;
  int row5_y = row4_y+20;

  context.push_transform();
  context.set_alpha(0.5);
  context.draw_surface(backdrop, Vector(bd_x, bd_y), LAYER_HUD);
  context.pop_transform();

  context.draw_text(Resources::normal_font, _("You"), Vector(col2_x, row1_y), ALIGN_LEFT, LAYER_HUD, Statistics::header_color);
  if (best_stats)
    context.draw_text(Resources::normal_font, _("Best"), Vector(col3_x, row1_y), ALIGN_LEFT, LAYER_HUD, Statistics::header_color);

  context.draw_text(Resources::normal_font, _("Coins"), Vector(col2_x-16, row3_y), ALIGN_RIGHT, LAYER_HUD, Statistics::header_color);
  context.draw_text(Resources::normal_font, coins_to_string(coins, total_coins), Vector(col2_x, row3_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  if (best_stats) {
    int coins_best = (best_stats->coins > coins) ? best_stats->coins : coins;
    int total_coins_best = (best_stats->total_coins > total_coins) ? best_stats->total_coins : total_coins;
    context.draw_text(Resources::normal_font, coins_to_string(coins_best, total_coins_best), Vector(col3_x, row3_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  }

  context.draw_text(Resources::normal_font, _("Badguys"), Vector(col2_x-16, row4_y), ALIGN_RIGHT, LAYER_HUD, Statistics::header_color);
  context.draw_text(Resources::normal_font, frags_to_string(badguys, total_badguys), Vector(col2_x, row4_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  if (best_stats) {
	int badguys_best = (best_stats->badguys > badguys) ? best_stats->badguys : badguys;
	int total_badguys_best = (best_stats->total_badguys > total_badguys) ? best_stats->total_badguys : total_badguys;
	context.draw_text(Resources::normal_font, frags_to_string(badguys_best, total_badguys_best), Vector(col3_x, row4_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  }

  context.draw_text(Resources::normal_font, _("Secrets"), Vector(col2_x-16, row5_y), ALIGN_RIGHT, LAYER_HUD, Statistics::header_color);
  context.draw_text(Resources::normal_font, secrets_to_string(secrets, total_secrets), Vector(col2_x, row5_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  if (best_stats) {
    int secrets_best = (best_stats->secrets > secrets) ? best_stats->secrets : secrets;
    int total_secrets_best = (best_stats->total_secrets > total_secrets) ? best_stats->total_secrets : total_secrets;
    context.draw_text(Resources::normal_font, secrets_to_string(secrets_best, total_secrets_best), Vector(col3_x, row5_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  }

  context.draw_text(Resources::normal_font, _("Time"), Vector(col2_x-16, row2_y), ALIGN_RIGHT, LAYER_HUD, Statistics::header_color);
  context.draw_text(Resources::normal_font, time_to_string(time), Vector(col2_x, row2_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  if (best_stats) {
    float time_best = (best_stats->time < time) ? best_stats->time : time;
    context.draw_text(Resources::normal_font, time_to_string(time_best), Vector(col3_x, row2_y), ALIGN_LEFT, LAYER_HUD, Statistics::text_color);
  }
}
void
Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, Surface* backdrop)
{
  // skip draw if level was never played
  // TODO: do we need this?
  if (coins == nv_coins) return;

  // skip draw if stats were declared invalid
  if (!valid) return;

  // abort if we have no backdrop
  if (!backdrop) return;

  int box_w = 220+110+110;
  int box_h = 30+20+20+20;
  int box_x = (int)((SCREEN_WIDTH - box_w) / 2);
  int box_y = (int)(SCREEN_HEIGHT / 2) - box_h;

  int bd_w = (int)backdrop->get_width();
  int bd_h = (int)backdrop->get_height();
  int bd_x = (int)((SCREEN_WIDTH - bd_w) / 2);
  int bd_y = box_y + (box_h / 2) - (bd_h / 2);

  int col1_x = box_x;
  int col2_x = col1_x+200;
  int col3_x = col2_x+130;

  int row1_y = box_y;
  int row2_y = row1_y+30;
  int row3_y = row2_y+20;
  int row4_y = row3_y+20;

  context.push_transform();
  context.set_alpha(0.5);
  context.draw_surface(backdrop, Vector(bd_x, bd_y), LAYER_GUI);
  context.pop_transform();

  char buf[129];
  context.draw_text(white_text, _("You"), Vector(col2_x, row1_y), LEFT_ALLIGN, LAYER_GUI);
  context.draw_text(white_text, _("Best"), Vector(col3_x, row1_y), LEFT_ALLIGN, LAYER_GUI);

  context.draw_text(white_text, _("Coins"), Vector(col2_x-16, row2_y), RIGHT_ALLIGN, LAYER_GUI);
  snprintf(buf, sizeof(buf), "%d/%d", std::min(coins, 999), std::min(total_coins, 999));
  context.draw_text(gold_text, buf, Vector(col2_x, row2_y), LEFT_ALLIGN, LAYER_GUI);
  if (best_stats && (best_stats->coins > coins)) {
    snprintf(buf, sizeof(buf), "%d/%d", std::min(best_stats->coins, 999), std::min(best_stats->total_coins, 999));
  }
  context.draw_text(gold_text, buf, Vector(col3_x, row2_y), LEFT_ALLIGN, LAYER_GUI);

  context.draw_text(white_text, _("Secrets"), Vector(col2_x-16, row4_y), RIGHT_ALLIGN, LAYER_GUI);
  snprintf(buf, sizeof(buf), "%d/%d", secrets, total_secrets);
  context.draw_text(gold_text, buf, Vector(col2_x, row4_y), LEFT_ALLIGN, LAYER_GUI);
  if (best_stats && (best_stats->secrets > secrets)) {
    snprintf(buf, sizeof(buf), "%d/%d", best_stats->secrets, best_stats->total_secrets);
  }
  context.draw_text(gold_text, buf, Vector(col3_x, row4_y), LEFT_ALLIGN, LAYER_GUI);

  context.draw_text(white_text, _("Time"), Vector(col2_x-16, row3_y), RIGHT_ALLIGN, LAYER_GUI);
  int csecs = (int)(time * 100);
  int mins = (int)(csecs / 6000);
  int secs = (csecs % 6000) / 100;
  snprintf(buf, sizeof(buf), "%02d:%02d", mins,secs);
  context.draw_text(gold_text, buf, Vector(col2_x, row3_y), LEFT_ALLIGN, LAYER_GUI);
  if (best_stats && (best_stats->time < time)) {
    int csecs = (int)(best_stats->time * 100);
    int mins = (int)(csecs / 6000);
    int secs = (csecs % 6000) / 100;
    snprintf(buf, sizeof(buf), "%02d:%02d", mins,secs);
  }
  context.draw_text(gold_text, buf, Vector(col3_x, row3_y), LEFT_ALLIGN, LAYER_GUI);
}
void
Player::draw(DrawingContext& context)
{
  if(!visible)
    return;

  TuxBodyParts* tux_body;
          
  if (player_status->bonus == GROWUP_BONUS)
    tux_body = big_tux;
  else if (player_status->bonus == FIRE_BONUS)
    tux_body = fire_tux;
  else if (player_status->bonus == ICE_BONUS)
    tux_body = ice_tux;
  else
    tux_body = small_tux;

  int layer = LAYER_OBJECTS + 1;

  /* Set Tux sprite action */
  if (backflipping)
    {
    if(dir == LEFT)
      tux_body->set_action("backflip-left");
    else // dir == RIGHT
      tux_body->set_action("backflip-right");
    }
  else if (duck && is_big())
    {
    if(dir == LEFT)
      tux_body->set_action("duck-left");
    else // dir == RIGHT
      tux_body->set_action("duck-right");
    }
  else if (skidding_timer.started() && !skidding_timer.check())
    {
    if(dir == LEFT)
      tux_body->set_action("skid-left");
    else // dir == RIGHT
      tux_body->set_action("skid-right");
    }
  else if (kick_timer.started() && !kick_timer.check())
    {
    if(dir == LEFT)
      tux_body->set_action("kick-left");
    else // dir == RIGHT
      tux_body->set_action("kick-right");
    }
  else if (butt_jump && is_big())
    {
    if(dir == LEFT)
      tux_body->set_action("buttjump-left");
    else // dir == RIGHT
      tux_body->set_action("buttjump-right");
    }
  else if (!on_ground())
    {
    if(dir == LEFT)
      tux_body->set_action("jump-left");
    else // dir == RIGHT
      tux_body->set_action("jump-right");
    }
  else
    {
    if (fabsf(physic.get_velocity_x()) < 1.0f) // standing
      {
      if(dir == LEFT)
        tux_body->set_action("stand-left");
      else // dir == RIGHT
        tux_body->set_action("stand-right");
      }
    else // moving
      {
      if(dir == LEFT)
        tux_body->set_action("walk-left");
      else // dir == RIGHT
        tux_body->set_action("walk-right");
      }
    }

  if(idle_timer.check())
    {
    if(is_big())
      {
      if(dir == LEFT)
        tux_body->head->set_action("idle-left", 1);
      else // dir == RIGHT
        tux_body->head->set_action("idle-right", 1);
      }

    }

  // Tux is holding something
  if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
      (shooting_timer.get_timeleft() > 0 && !shooting_timer.check()))
    {
    if (duck)
      {
      if(dir == LEFT)
        tux_body->arms->set_action("duck+grab-left");
      else // dir == RIGHT
        tux_body->arms->set_action("duck+grab-right");
      }
    else
      {
      if(dir == LEFT)
        tux_body->arms->set_action("grab-left");
      else // dir == RIGHT
        tux_body->arms->set_action("grab-right");
      }
    }

  /* Draw Tux */
  if(dying) {
    smalltux_gameover->draw(context, get_pos(), LAYER_FLOATINGOBJECTS + 1);
  } 
  else if ((growing_timer.get_timeleft() > 0) && (!duck)) {
      if (dir == RIGHT) {
        context.draw_surface(growingtux_right[int((growing_timer.get_timegone() *
                 GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
      } else {
        context.draw_surface(growingtux_left[int((growing_timer.get_timegone() *
                GROWING_FRAMES) / GROWING_TIME)], get_pos(), layer);
      }
    }
  else if (safe_timer.started() && size_t(game_time*40)%2)
    ;  // don't draw Tux
  else
    tux_body->draw(context, get_pos(), layer);

  // Draw blinking star overlay
  if (invincible_timer.started() &&
     (invincible_timer.get_timeleft() > TUX_INVINCIBLE_TIME_WARNING
      || size_t(game_time*20)%2)
     && !dying)
  {
    if (!is_big() || duck)
      smalltux_star->draw(context, get_pos(), layer + 5);
    else
      bigtux_star->draw(context, get_pos(), layer + 5);
  } 
}
Exemple #28
0
void
Background::draw_image(DrawingContext& context, const Vector& pos_)
{
  Sizef level(Sector::current()->get_width(), Sector::current()->get_height());
  Sizef screen(SCREEN_WIDTH, SCREEN_HEIGHT);
  Sizef parallax_image_size = (1.0f - speed) * screen + level * speed;
  Rectf cliprect = context.get_cliprect();

  int start_x = static_cast<int>(floorf((cliprect.get_left()  - (pos_.x - image->get_width() /2.0f)) / image->get_width()));
  int end_x   = static_cast<int>(ceilf((cliprect.get_right()  - (pos_.x + image->get_width() /2.0f)) / image->get_width()))+1;
  int start_y = static_cast<int>(floorf((cliprect.get_top()   - (pos_.y - image->get_height()/2.0f)) / image->get_height()));
  int end_y   = static_cast<int>(ceilf((cliprect.get_bottom() - (pos_.y + image->get_height()/2.0f)) / image->get_height()))+1;

  switch(alignment)
  {
    case LEFT_ALIGNMENT:
      for(int y = start_y; y < end_y; ++y)
      {
        Vector p(pos_.x - parallax_image_size.width / 2.0f,
                 pos_.y + y * image->get_height()  - image->get_height() / 2.0f);
        context.draw_surface(image, p, layer);
      }
      break;

    case RIGHT_ALIGNMENT:
      for(int y = start_y; y < end_y; ++y)
      {
        Vector p(pos_.x + parallax_image_size.width / 2.0f - image->get_width(),
                 pos_.y + y * image->get_height() - image->get_height() / 2.0f);
        context.draw_surface(image, p, layer);
      }
      break;

    case TOP_ALIGNMENT:
      for(int x = start_x; x < end_x; ++x)
      {
        Vector p(pos_.x + x * image->get_width() - image->get_width() / 2.0f,
                 pos_.y - parallax_image_size.height / 2.0f);
        context.draw_surface(image, p, layer);
      }
      break;

    case BOTTOM_ALIGNMENT:
      for(int x = start_x; x < end_x; ++x)
      {
        Vector p(pos_.x + x * image->get_width()  - image->get_width() / 2.0f,
                 pos_.y - image->get_height() + parallax_image_size.height / 2.0f);
        context.draw_surface(image, p, layer);
      }
      break;

    case NO_ALIGNMENT:
      for(int y = start_y; y < end_y; ++y)
        for(int x = start_x; x < end_x; ++x)
        {
          Vector p(pos_.x + x * image->get_width()  - image->get_width()/2,
                   pos_.y + y * image->get_height() - image->get_height()/2);

          if (image_top.get() != NULL && (y < 0))
          {
            context.draw_surface(image_top, p, layer);
          }
          else if (image_bottom.get() != NULL && (y > 0))
          {
            context.draw_surface(image_bottom, p, layer);
          }
          else
          {
            context.draw_surface(image, p, layer);
          }
        }
      break;
  }
}
void SpawnPointMarker::draw(DrawingContext& context) {
  context.draw_surface(surface, bbox.p1, LAYER_FOREGROUND1);
}
Exemple #30
0
void
Player::draw(DrawingContext& context)
{
  if(!visible)
    return;

  // if Tux is above camera, draw little "air arrow" to show where he is x-wise
  if (Sector::current() && Sector::current()->camera && (get_bbox().p2.y - 16 < Sector::current()->camera->get_translation().y)) {
    float px = get_pos().x + (get_bbox().p2.x - get_bbox().p1.x - airarrow.get()->get_width()) / 2;
    float py = Sector::current()->camera->get_translation().y;
    py += std::min(((py - (get_bbox().p2.y + 16)) / 4), 16.0f);
    context.draw_surface(airarrow, Vector(px, py), LAYER_HUD - 1);
  }

  // Show where Tux will land after using jump helper
  if (jump_helper_draw && Sector::current() && Sector::current()->camera) {
    float px = jump_helper_x + (get_bbox().p2.x - get_bbox().p1.x) / 2 - jumparrow.get()->get_width() / 2;
    float py = get_bbox().p2.y - jumparrow.get()->get_height();
    context.draw_surface(jumparrow, Vector(px, py), LAYER_HUD - 1);
  }

  std::string sa_prefix = "";
  std::string sa_postfix = "";

  if (player_status->bonus == GROWUP_BONUS)
    sa_prefix = "big";
  else if (player_status->bonus == FIRE_BONUS)
    sa_prefix = "fire";
  else if (player_status->bonus == ICE_BONUS)
    sa_prefix = "ice";
  else
    sa_prefix = "small";

  if(dir == LEFT)
    sa_postfix = "-left";
  else
    sa_postfix = "-right";

  /* Set Tux sprite action */
  if(dying) {
    sprite->set_action("gameover");
  }
  else if (growing) {
    sprite->set_action_continued("grow"+sa_postfix);
    // while growing, do not change action
    // do_duck() will take care of cancelling growing manually
    // update() will take care of cancelling when growing completed
  }
  else if (climbing) {
    sprite->set_action(sa_prefix+"-climbing"+sa_postfix);
  }
  else if (backflipping) {
    sprite->set_action(sa_prefix+"-backflip"+sa_postfix);
  }
  else if (duck && is_big()) {
    sprite->set_action(sa_prefix+"-duck"+sa_postfix);
  }
  else if (skidding_timer.started() && !skidding_timer.check()) {
    sprite->set_action(sa_prefix+"-skid"+sa_postfix);
  }
  else if (kick_timer.started() && !kick_timer.check()) {
    sprite->set_action(sa_prefix+"-kick"+sa_postfix);
  }
  else if ((wants_buttjump || does_buttjump) && is_big()) {
    sprite->set_action(sa_prefix+"-buttjump"+sa_postfix);
  }
  else if (!on_ground() || fall_mode != ON_GROUND) {
    if(physic.get_velocity_x() != 0 || fall_mode != ON_GROUND) {
        sprite->set_action(sa_prefix+"-jump"+sa_postfix);
    }
  }
  else {
    if (fabsf(physic.get_velocity_x()) < 1.0f) {
      // Determine which idle stage we're at
      if (sprite->get_action().find("-stand-") == std::string::npos && sprite->get_action().find("-idle-") == std::string::npos) {
        idle_stage = 0;
        idle_timer.start(IDLE_TIME[idle_stage]/1000.0f);

        sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
      }
      else if (idle_timer.check() || (IDLE_TIME[idle_stage] == 0 && sprite->animation_done())) {
        idle_stage++;
        if (idle_stage >= IDLE_STAGE_COUNT)
          idle_stage = 1;

        idle_timer.start(IDLE_TIME[idle_stage]/1000.0f);

        if (IDLE_TIME[idle_stage] == 0)
          sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix, 1);
        else
          sprite->set_action(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
      }
      else {
        sprite->set_action_continued(sa_prefix+("-" + IDLE_STAGES[idle_stage])+sa_postfix);
      }
    }
    else {
      sprite->set_action(sa_prefix+"-walk"+sa_postfix);
    }
  }

  /*
  // Tux is holding something
  if ((grabbed_object != 0 && physic.get_velocity_y() == 0) ||
  (shooting_timer.get_timeleft() > 0 && !shooting_timer.check())) {
  if (duck) {
  } else {
  }
  }
  */

  /* Draw Tux */
  if (safe_timer.started() && size_t(game_time*40)%2)
    ;  // don't draw Tux
  else {
    sprite->draw(context, get_pos(), LAYER_OBJECTS + 1);
  }

}