pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src/backgrounds solidcolor_background.cxx


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/backgrounds solidcolor_background.cxx,NONE,1.1 solidcolor_background.hxx,NONE,1.1 starfield_background.cxx,NONE,1.1 starfield_background.hxx,NONE,1.1 surface_background.cxx,NONE,1.1 surface_background.hxx,NONE,1.1 surface_background_data.cxx,NONE,1.1 surface_background_data.hxx,NONE,1.1 thunderstorm_background.cxx,NONE,1.1 thunderstorm_background.hxx,NONE,1.1 thunderstorm_background_data.cxx,NONE,1.1 thunderstorm_background_data.hxx,NONE,1.1 Makefile.am,1.4,1.5 SolidColorBackground.cc,1.16,NONE SurfaceBackgroundData.cc,1.21,NONE ThunderstormBackgroundData.cc,1.15,NONE
Date: 12 Jun 2002 19:02:32 -0000

Update of /usr/local/cvsroot/Games/Pingus/src/backgrounds
In directory dark:/tmp/cvs-serv12643

Modified Files:
        Makefile.am 
Added Files:
        solidcolor_background.cxx solidcolor_background.hxx 
        starfield_background.cxx starfield_background.hxx 
        surface_background.cxx surface_background.hxx 
        surface_background_data.cxx surface_background_data.hxx 
        thunderstorm_background.cxx thunderstorm_background.hxx 
        thunderstorm_background_data.cxx 
        thunderstorm_background_data.hxx 
Removed Files:
        SolidColorBackground.cc SurfaceBackgroundData.cc 
        ThunderstormBackgroundData.cc 
Log Message:
The big rename...

--- NEW FILE: solidcolor_background.cxx ---
//  $Id: solidcolor_background.cxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <fstream>
#include <ClanLib/Display/Display/display.h>
#include "solidcolor_background.hxx"
#include "../xml_helper.hxx"

void
SolidColorBackgroundData:: write_xml(std::ofstream* xml)
{
  (*xml) << "<worldobj type=\"solidcolor-background\"></worldobj>" << std::endl;
}

SolidColorBackgroundData::SolidColorBackgroundData(xmlDocPtr doc, xmlNodePtr 
cur)
{
  cur = cur->children;
  while (cur != NULL)
    {
      if (xmlIsBlankNode(cur)) 
        {
          cur = cur->next;
          continue;
        }

      if (strcmp ((char*) cur->name, "color") == 0)
        {
          color = XMLhelper::parse_color (doc, cur);
        }
      else
        {
          std::cout << "SolidColorBackground: Unhandled tag: " << cur->name << 
std::endl;
        }
      cur = cur->next;
    }
}

WorldObj* 
SolidColorBackgroundData::create_WorldObj()
{
  return new SolidColorBackground (*this);
}

EditorObjLst 
SolidColorBackgroundData::create_EditorObj()
{
  EditorObjLst lst;
  lst.push_back (boost::shared_ptr<EditorObj>(new EditorSolidColorBackground 
(*this)));
  return lst;
}

SolidColorBackground::SolidColorBackground (const SolidColorBackgroundData& 
data)
  : SolidColorBackgroundData (data)
{
}

void
SolidColorBackground::draw_offset (int /*x_of*/, int /*y_of*/, float /*s*/)
{
  // FIXME: Probally fill_rect is better here, but slower?
  CL_Display::clear_display (color.red, color.green, color.blue, color.alpha);
}

/* EOF */



--- NEW FILE: solidcolor_background.hxx ---
//  $Id: solidcolor_background.hxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef SOLIDCOLORBACKGROUND_HH
#define SOLIDCOLORBACKGROUND_HH

#include "../string_converter.hxx"
#include "../color.hxx"
#include "../worldobj.hxx"
#include "../worldobj_data.hxx"
#include "../editor/rect_editorobj.hxx"
#include "../editor/editor_view.hxx"
#include "../boost/smart_ptr.hpp"

class _xmlDoc;  typedef _xmlDoc*  xmlDocPtr;
class _xmlNode; typedef _xmlNode* xmlNodePtr;

class SolidColorBackgroundData : public WorldObjData
{
public:
  Color color;

  // FIXME: Add z_pos handling here

  SolidColorBackgroundData() {}
  SolidColorBackgroundData(xmlDocPtr doc, xmlNodePtr cur);

  virtual ~SolidColorBackgroundData() {}

  /** Writte the content of this object formated as xml to the given
      stream */
  virtual void write_xml(std::ofstream* xml);

  WorldObj* create_WorldObj();
  EditorObjLst create_EditorObj();
};

class SolidColorBackground : public WorldObj,
                             private SolidColorBackgroundData
{
public:
  SolidColorBackground (const SolidColorBackgroundData&);
  virtual ~SolidColorBackground () {}

  // FIXME: Make z_position editable
  float get_z_pos() const { return -10; }  
  void update (float /*delta*/) {}
  void draw_offset (int x_of, int y_of, float s = 1.0);
};


class EditorSolidColorBackground : public SolidColorBackgroundData,
                                   public RectEditorObj
{
private:
  CL_Vector pos;
public:
  EditorSolidColorBackground (const SolidColorBackgroundData& data)
    : SolidColorBackgroundData (data),
      pos (0.0f, 0.0f)
  {}
  void write_xml(std::ofstream* xml) { 
this->SolidColorBackgroundData::write_xml (xml); }

  /// Return the object width
  int get_width() { return 256; }
  /// Return the object height
  int get_height() { return 256; }

  boost::shared_ptr<EditorObj> duplicate() {
    return boost::shared_ptr<EditorObj>
      (new EditorSolidColorBackground 
(static_cast<SolidColorBackgroundData>(*this)));
  }

  float get_z_pos () { return pos.z; }

  CL_Vector get_upper_left_corner () { 
    return pos; 
  }

  void draw(EditorView * view)
  {
    view->draw_fillrect ((int)pos.x, (int)pos.y, (int)pos.x + 256, (int)pos.y + 
256, 
                         color.red, color.green, color.blue, color.alpha);
  }

  void set_position_offset(const CL_Vector& offset)
  {
    pos += offset;
  }  

  std::string status_line () { return "SolidColorBackground: " 
                                 + to_string (pos.x) + ", "
                                 + to_string (pos.y) + ", "
                                 + to_string (pos.z); }
};

#endif

/* EOF */


--- NEW FILE: starfield_background.cxx ---
//  $Id: starfield_background.cxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <fstream>
#include "../globals.hxx"
#include "../editor/sprite_editorobj.hxx"
#include "../world.hxx"
#include "../pingus_resource.hxx"
#include "../xml_helper.hxx"
#include "starfield_background.hxx"

StarfieldBackgroundData::StarfieldBackgroundData ()
  : small_stars_count (400),
    middle_stars_count (200),
    large_stars_count (100)
{
}

void 
StarfieldBackgroundData::write_xml(std::ofstream* xml)
{
  (*xml) << "<background type=\"starfield\">\n"
         << "  <small-stars count=\"" << small_stars_count << "\"/>\n"
         << "  <middle-stars count=\"" << middle_stars_count << "\"/>\n"
         << "  <large-stars count=\"" << large_stars_count << "\"/>\n"
         << "</background>\n"
         << std::endl;
}
 
StarfieldBackgroundData::StarfieldBackgroundData (xmlDocPtr /*doc*/, xmlNodePtr 
cur)
{
  small_stars_count = 100;
  middle_stars_count = 50;
  large_stars_count = 25;

  cur = cur->children;

    while (cur != NULL)
    {
      if (xmlIsBlankNode(cur)) 
        {
          cur = cur->next;
          continue;
        }
      
      if (strcmp((char*)cur->name, "small-stars") == 0)
        {
          char* count = (char*)xmlGetProp(cur, (xmlChar*)"count");
          if (count)
            {
              small_stars_count = StringConverter::to_int(count);
              free (count);
            }
        }
      else if (strcmp((char*)cur->name, "middle-stars") == 0)
        {
          char* count = (char*)xmlGetProp(cur, (xmlChar*)"count");
          if (count)
            {
              middle_stars_count = StringConverter::to_int(count);
              free (count);
            }     
        }
      else if (strcmp((char*)cur->name, "large-stars") == 0)
        {
          char* count = (char*)xmlGetProp(cur, (xmlChar*)"count");
          if (count)
            {
              large_stars_count = StringConverter::to_int(count);
              free (count);
            }     
        }
      else
        {
          std::cout << "StarfildBackgroundData:create: Unhandled tag: " << 
cur->name << std::endl;
        } 
      cur = cur->next;
    }
}

WorldObj* 
StarfieldBackgroundData::create_WorldObj()
{
  return new StarfieldBackground (*this);
}

EditorObjLst
StarfieldBackgroundData::create_EditorObj()
{
  EditorObjLst lst;
  lst.push_back (boost::shared_ptr<EditorObj> (new EditorStarfieldBackground 
(*this)));
  return lst;
}

/****************************/
/* StarfieldBackgroundStars */
/****************************/

CL_Surface StarfieldBackgroundStars::small_star;
CL_Surface StarfieldBackgroundStars::middle_star;
CL_Surface StarfieldBackgroundStars::large_star;
bool StarfieldBackgroundStars::is_init = false;

StarfieldBackgroundStars::StarfieldBackgroundStars (Type type)
{
  init ();
 
  switch (type)
    {
    case SMALL_STAR:
      sur = small_star;
      break;
    case MIDDLE_STAR:
      sur = middle_star;
      break;
    case LARGE_STAR:
      sur = large_star;
      break;
    }
 
  x_pos = rand () % world->get_width ();
  y_pos = rand () % world->get_height ();
  
  x_add = rand () % 5 + 1.0;
  y_add = 0.0;
}

void
StarfieldBackgroundStars::init ()
{
  if (!is_init)
    {
      small_star  = PingusResource::load_surface ("Stars/small_star", "game");
      middle_star = PingusResource::load_surface ("Stars/middle_star", "game");
      large_star  = PingusResource::load_surface ("Stars/large_star", "game");
      is_init = true;
    }
}

void
StarfieldBackgroundStars::update(float /*delta*/)
{
  x_pos += x_add;
  y_pos += y_add;
  
  if (x_pos > world->get_width ())
    {
      x_pos = -32;
      y_pos = rand () % world->get_height ();
    }
}

void
StarfieldBackgroundStars::draw_offset(int x_of, int y_of, float /*s*/)
{
  sur.put_screen (int(x_pos + x_of), int(y_pos + y_of));
}

StarfieldBackground::StarfieldBackground (const StarfieldBackgroundData& data)
{
  small_stars_count  = data.small_stars_count;
  middle_stars_count = data.middle_stars_count;
  large_stars_count  = data.large_stars_count;

  for (int i=0; i < small_stars_count; i++)
    stars.push_back (StarfieldBackgroundStars 
(StarfieldBackgroundStars::SMALL_STAR));

  for (int i=0; i < middle_stars_count; i++)
    stars.push_back (StarfieldBackgroundStars 
(StarfieldBackgroundStars::MIDDLE_STAR));

  for (int i=0; i < large_stars_count; i++)
    stars.push_back (StarfieldBackgroundStars 
(StarfieldBackgroundStars::LARGE_STAR));
}

StarfieldBackground::~StarfieldBackground ()
{
  
}


///
void 
StarfieldBackground::update(float delta)
{
  for (std::vector<StarfieldBackgroundStars>::iterator i = stars.begin ();
       i != stars.end (); i++)
    {
      i->update (delta);
    }
}
///
void 
StarfieldBackground::draw_offset(int x_of, int y_of, float /*s*/)
{
  for (std::vector<StarfieldBackgroundStars>::iterator i = stars.begin ();
       i != stars.end (); i++)
    {
      i->draw_offset (x_of, y_of);
    }
}

/* EOF */


--- NEW FILE: starfield_background.hxx ---
//  $Id: starfield_background.hxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef STARFIELDBACKGROUND_HH
#define STARFIELDBACKGROUND_HH

#include "../string_converter.hxx"
#include "../worldobj.hxx"
#include "../worldobj_data.hxx"
#include "../boost/smart_ptr.hpp"

class _xmlDoc;  typedef _xmlDoc*  xmlDocPtr;
class _xmlNode; typedef _xmlNode* xmlNodePtr;

class StarfieldBackgroundData : public WorldObjData
{
public:
  int small_stars_count;
  int middle_stars_count;
  int large_stars_count;

  StarfieldBackgroundData ();
  StarfieldBackgroundData (xmlDocPtr /*doc*/, xmlNodePtr cur);
  virtual ~StarfieldBackgroundData () {}

  void write_xml(std::ofstream* xml);

  WorldObj* create_WorldObj();
  EditorObjLst create_EditorObj();
};

class StarfieldBackgroundStars : public WorldObj
{
private:
  static CL_Surface small_star;
  static CL_Surface middle_star;
  static CL_Surface large_star;
  static bool is_init;

  CL_Surface sur;

  float x_pos;
  float y_pos;

  float x_add;
  float y_add;

public:
  enum Type { SMALL_STAR, MIDDLE_STAR, LARGE_STAR };

  StarfieldBackgroundStars () {}
  StarfieldBackgroundStars (Type type);
  
  // Never used
  float get_z_pos() const { return -100; }

  void init ();
  void update(float delta);
  void draw_offset(int x_of, int y_of, float s = 1.0);  
};

class StarfieldBackground : public WorldObj,
                            private StarfieldBackgroundData
{
private:
  std::vector<StarfieldBackgroundStars> stars;

public:
  StarfieldBackground (const StarfieldBackgroundData&);
  ///

  virtual ~StarfieldBackground ();

  // FIXME: Make z_pos handling editable via xml
  float get_z_pos() const { return -10; }

  void update(float delta);
  void draw_offset(int x_of, int y_of, float s = 1.0);
};

class EditorStarfieldBackground : public StarfieldBackgroundData,
                                  public SpriteEditorObj
{
private:
  CL_Vector pos;
public:
  EditorStarfieldBackground (const StarfieldBackgroundData& data)
    : StarfieldBackgroundData (data),
      SpriteEditorObj ("Stars/starfield_icon", "game", pos),
      pos (-64.0f, 0.0f)
  {}

  void write_xml(std::ofstream* xml) { this->StarfieldBackgroundData::write_xml 
(xml); }

  boost::shared_ptr<EditorObj> duplicate() {
    return boost::shared_ptr<EditorObj>
      (new EditorStarfieldBackground 
(static_cast<StarfieldBackgroundData>(*this)));
  }

  std::string status_line () { return "StarfieldBackground: " 
                                 + to_string (pos.x) + ", "
                                 + to_string (pos.y) + ", "
                                 + to_string (pos.z); }
};

#endif

/* EOF */


--- NEW FILE: surface_background.cxx ---
//  $Id: surface_background.cxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <cassert>

#include <ClanLib/Display/SurfaceProviders/canvas.h>
#include <ClanLib/Display/Display/display.h>
#include "../globals.hxx"
#include "../timer.hxx"
#include "../pingus_resource.hxx"
#include "../globals.hxx"
#include "../blitter.hxx"
#include "../caimagemanipulation/caimagemanipulation.h"

#include "surface_background.hxx"

SurfaceBackground::SurfaceBackground(const SurfaceBackgroundData& bg_data)
{
  Timer timer;

  if (verbose) {
    timer.start();
    std::cout << "Creating Background..." << std::flush;
  }
  
  surface_need_deletion = false;

  if (bg_data.color.alpha > 1.0) 
    std::cout << "Background: Warning dim larger than 1.0 are no longer 
supported" << std::endl;
  
  // Testing animatied backgrounds...
  /*std::cout << "Res: " << bg_data.desc.res_name << std::endl
    << "file: " << bg_data.desc.datafile << std::endl;*/

  if (background_manipulation_enabled && bg_data.color.alpha != 0.0
      && bg_data.color != Color (0, 0, 0, 1.0f)) // Workaround for a
                                                 // bug which caused
                                                 // all levels to have
                                                 // tho wrong
                                                 // background color
    {
      std::cout << "------ SurfaceBackground:: Manipulating background ------" 
<< std::endl;
      // FIXME: This is extremly buggy and it will crash, no idea why....
      CL_Surface source_surface = PingusResource::load_surface(bg_data.desc);
      
      CL_Canvas* canvas = Blitter::create_canvas(source_surface);
      /* FIXME: fill_rect doesn't work with RGB images
         FIXME: seems to work fine with indexed images
         FIXME: not tested with RGBA images
         FIXME: the bug might be in create_canvas() and not in fill_rect()
       */
      canvas->fill_rect(0, 0, 
                        canvas->get_width(), canvas->get_height(),
                        bg_data.color.red, bg_data.color.green, 
bg_data.color.blue, 
                        bg_data.color.alpha);
      
      // FIXME: Sat Jul 21 21:57:15 2001
      //std::cout << "BUG: Stuff removed because of linker error" << std::endl;
      bg_surface = CL_Surface (canvas, true);
    }
  else
    {
      bg_surface = PingusResource::load_surface(bg_data.desc);
    }

  //bg_surface = CAImageManipulation::changeHSV(bg_surface, 150, 100, 0);
  counter.set_size(bg_surface.get_num_frames());
  counter.set_speed(1.0);

  stretch_x = bg_data.stretch_x;
  stretch_y = bg_data.stretch_y;

  scroll_x = bg_data.scroll_x;
  scroll_y = bg_data.scroll_y;

  para_x = bg_data.para_x;
  para_y = bg_data.para_y;

  pos = bg_data.pos;

  scroll_ox = 0;
  scroll_oy = 0;

  if (verbose > 1)
    {
      std::cout << "Background: Stretch_X: " << stretch_x << std::endl;
      std::cout << "Background: Stretch_Y: " << stretch_y << std::endl;
    }
  
  if (verbose)
    std::cout << "done" << timer.stop()  << std::endl;
}

SurfaceBackground::~SurfaceBackground()
{
  /*
  std::cout << "Background:~Background" << std::endl;

  if (surface_need_deletion) {
    //std::cout << "Background: Deleting background surface" << std::endl;
    // FIXME: We are /not/ deleting the surface here cause that gives
    // a segfault if the next level is loaded, I have absolutly no
    // idea why. So we have a memory hole here
    //delete bg_surface;
  }
  */
}

/*
void
SurfaceBackground::load (SurfaceBackgroundData bg_data)
{
  surface_need_deletion = false;

  if (bg_data.color.alpha > 1.0) 
    std::cout << "Background: Warning dim larger than 1.0 are no longer 
supported" << std::endl;
  
  // Testing animatied backgrounds...
  std::cout << "Res: " << bg_data.desc.res_name << std::endl
            << "file: " << bg_data.desc.datafile << std::endl;

  if (bg_data.desc.res_name == "none")
    {
      std::cout << "Background: No surface set..." << std::endl;
      bg_surface = 0;
    }
  else
    {
      if (background_manipulation_enabled)
        {
          // FIXME: This is extremly buggy and it will crash, no idea why....
          CL_Surface* source_surface = 
PingusResource::load_surface(bg_data.desc);

          CL_Canvas* canvas = new CL_Canvas(source_surface->get_width(),
                                            source_surface->get_height());/// 
Blitter::create_canvas(source_surface);
          source_surface->put_target(0, 0, 0, canvas);
          canvas->fill_rect(0, 0, canvas->get_width(), canvas->get_height(),
                            bg_data.color.red, bg_data.color.green, 
bg_data.color.blue, 
                            bg_data.color.alpha);
          bg_surface = CL_Surface::create(canvas, true);
        }
      else
        {
          bg_surface = PingusResource::load_surface(bg_data.desc);
        }
    }

  if (bg_surface) 
    {
      //bg_surface = CAImageManipulation::changeHSV(bg_surface, 150, 100, 0);

      counter.set_size(bg_surface->get_num_frames());
      counter.set_speed(1.0);
    }

  stretch_x = bg_data.stretch_x;
  stretch_y = bg_data.stretch_y;

  scroll_x = bg_data.scroll_x;
  scroll_y = bg_data.scroll_y;

  para_x = bg_data.para_x;
  para_y = bg_data.para_y;

  scroll_ox = 0;
  scroll_oy = 0;

  if (verbose > 1)
    {
      std::cout << "Background: Stretch_X: " << stretch_x << std::endl;
      std::cout << "Background: Stretch_Y: " << stretch_y << std::endl;
    }
}
*/
void
SurfaceBackground::update(float /*delta*/)
{
  counter++;

  scroll_ox += scroll_x;
  scroll_oy += scroll_y;
  
  if (scroll_ox > bg_surface.get_width()) 
    {
      scroll_ox -= bg_surface.get_width();
    } 
  else if (-scroll_ox > bg_surface.get_width()) 
    {
      scroll_ox += bg_surface.get_width();
    }
  
  if (scroll_oy > bg_surface.get_height()) 
    {
      scroll_oy -= bg_surface.get_height();
    } 
  else if (-scroll_oy > bg_surface.get_height()) 
    {
      scroll_oy += bg_surface.get_height();
    }
}

void
SurfaceBackground::draw_offset(int x_of, int y_of, float s)
{
  if (fast_mode) 
    {
      CL_Display::clear_display();
    } 
  else 
    {
      int start_x;
      int start_y;
      
      start_x = int((x_of * para_x) + scroll_ox);
      start_y = int((y_of * para_y) + scroll_oy);
      
      if (start_x >= 0)
        start_x = start_x - bg_surface.get_width();
      
      if (start_y >= 0) 
        start_y -= bg_surface.get_height();
      else if (start_y < 0 - int(bg_surface.get_height()))
        start_y += bg_surface.get_height();
      
      if (s == 1.0) 
        {
          for(int y = start_y; 
              y < CL_Display::get_height(); 
              y += bg_surface.get_height()) 
            {
              for(int x = start_x;
                  x < CL_Display::get_width(); 
                  x += bg_surface.get_width())
                {
                  bg_surface.put_screen(x, y, counter);
                }
            }
        }
      else 
        {
          std::cout << "SurfaceBackground: Zooming not supported: " << s << 
std::endl;
          for(int y=(y_of/2); y < CL_Display::get_height(); y += 
(int)(bg_surface.get_height() * s)) {
            for(int x = start_x; x < CL_Display::get_width(); x += 
(int)(bg_surface.get_width() * s)) {
              bg_surface.put_screen(x, y, s, s);
            }
          }
        }
    }
}

/* EOF */

--- NEW FILE: surface_background.hxx ---
//  $Id: surface_background.hxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef SURFACEBACKGROUND_HH
#define SURFACEBACKGROUND_HH

#include "../worldobj.hxx"
#include "../anim_counter.hxx"
#include "../game_counter.hxx"
#include "surface_background_data.hxx"

///
class SurfaceBackground : public WorldObj, 
                          private SurfaceBackgroundData
{
private:
  AnimCounter scroll;
  GameCounter counter;
  bool surface_need_deletion;
  CL_Surface bg_surface_raw;
  CL_Surface bg_surface;
  float scroll_ox, scroll_oy;
  int x1, x2, y1, y2;

public:
  SurfaceBackground(const SurfaceBackgroundData&);
  ///
  virtual ~SurfaceBackground();

  float get_z_pos() const { return pos.z; }

  ///
  void update(float delta);
  ///
  void draw_offset(int x_of, int y_of, float s = 1.0);
};

#endif

/* EOF */


--- NEW FILE: surface_background_data.cxx ---
//  $Id: surface_background_data.cxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <fstream>
#include "../xml_helper.hxx"
#include "../string_converter.hxx"
#include "surface_background.hxx"

SurfaceBackgroundData::SurfaceBackgroundData()
{
  scroll_x = 0.0;
  scroll_y = 0.0;
  para_x = 0.5;
  para_y = 0.5;
  stretch_x = false;
  stretch_y = false;
  pos = CL_Vector (0, 0, -150);
  color = Color (0,0,0,0);
}

SurfaceBackgroundData::~SurfaceBackgroundData()
{
}

void
SurfaceBackgroundData::write_xml(std::ofstream* xml)
{
  (*xml) << "<background type=\"surface\">\n";
  XMLhelper::write_desc_xml(xml, desc);
  
  (*xml)  << "  <color>\n"
          << "    <red>"   << color.red   << "</red>\n"
          << "    <green>" << color.green << "</green>\n"
          << "    <blue>"  << color.blue << "</blue>\n"
          << "    <alpha>" << color.alpha   << "</alpha>\n"
          << "  </color>\n"
          << "  <scroll-x>"  << scroll_x << "</scroll-x>\n"
          << "  <scroll-y>"  << scroll_y << "</scroll-y>\n"
          << "  <para-x>"    << para_x << "</para-x>\n"
          << "  <para-y>"    << para_y << "</para-y>\n"
          << "  <stretch-x>" << stretch_x << "</stretch-x>\n"
          << "  <stretch-y>" << stretch_y << "</stretch-y>\n";
  XMLhelper::write_vector_xml(xml, pos);
  (*xml)  << "</background>\n"
          << std::endl;
}

SurfaceBackgroundData::SurfaceBackgroundData(xmlDocPtr doc, xmlNodePtr cur)
{
  pos.z = -150;

  cur = cur->children;  
  while (cur != NULL)
    {
      if (xmlIsBlankNode(cur)) 
        {
          cur = cur->next;
          continue;
        }

      if (strcmp((char*)cur->name, "surface") == 0)
        {
          desc = XMLhelper::parse_surface(doc, cur);
        }
      else if (strcmp((char*)cur->name, "color") == 0)
        {
          color = XMLhelper::parse_color(doc, cur);
        }
      else if (strcmp((char*)cur->name, "para-x") == 0)
        {
          para_x = XMLhelper::parse_float(doc, cur);
        }
      else if (strcmp((char*)cur->name, "para-y") == 0)
        {
          para_y = XMLhelper::parse_float(doc, cur);
        }
      else if (strcmp((char*)cur->name, "scroll-x") == 0)
        {
          scroll_x = XMLhelper::parse_float(doc, cur);
        }
      else if (strcmp((char*)cur->name, "scroll-y") == 0)
        {
          scroll_y = XMLhelper::parse_float(doc, cur);
        }
      else if (strcmp((char*)cur->name, "stretch-x") == 0)
        {
          stretch_x = XMLhelper::parse_float(doc, cur);
        }
      else if (strcmp((char*)cur->name, "stretch-y") == 0)
        {
          stretch_y = XMLhelper::parse_float(doc, cur);
        }
      else if (strcmp((char*)cur->name, "position") == 0)
        {
          pos = XMLhelper::parse_vector(doc, cur);  
        }
      else
        {
          std::cout << "XMLPLF::parse_background(): Unhandled: " << cur->name 
<< std::endl;
        }
      cur = cur->next;
    }      
}

WorldObj* 
SurfaceBackgroundData::create_WorldObj()
{
  return new SurfaceBackground (*this);
}

EditorObjLst 
SurfaceBackgroundData::create_EditorObj()
{
  std::cout << "SurfaceBackgroundData::create_EditorObj(): not implemented" << 
std::endl;
  EditorObjLst lst;
  lst.push_back(boost::shared_ptr<EditorObj> (new EditorSurfaceBackground 
(*this)));
  return lst;
}


/* EOF */


--- NEW FILE: surface_background_data.hxx ---
//  $Id: surface_background_data.hxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef SURFACEBACKGROUNDDATA_HH
#define SURFACEBACKGROUNDDATA_HH

#include "../string_converter.hxx"
#include "../editor/sprite_editorobj.hxx"
#include "../worldobj_data.hxx"
#include "../color.hxx"
#include "../res_descriptor.hxx"
#include "../boost/smart_ptr.hpp"

class SurfaceBackground;
class _xmlDoc;  typedef _xmlDoc*  xmlDocPtr;
class _xmlNode; typedef _xmlNode* xmlNodePtr;

class SurfaceBackgroundData : public WorldObjData
{
public:
  ResDescriptor desc;
  float para_x;
  float para_y;

  /** Position of the background, only the z_pos is really used. */
  CL_Vector pos;

  /** The amount of pixel the background is scrolled each frame in x
      direction. */
  float scroll_x;

  /** The amount of pixel the background is scrolled each frame in x
      direction. */
  float scroll_y;

  /** fill_rect() components
      An fill_rect() can be drawn over the background, the following
      for components are passed to the fill_rect() call. */
  Color color;

  /// Stretch the background to the full screen size in x direction
  bool stretch_x;

  /// Stretch the background to the full screen size in x direction
  bool stretch_y;

  /// Init all fields with some usefull defaults values.
  SurfaceBackgroundData();
  
  /** Parse the xml snip and return a newly allocated
      SurfaceBackgroundData*, the user is responsible to delete the
      object */
  SurfaceBackgroundData(xmlDocPtr doc, xmlNodePtr cur);

  /// Empty destructor
  virtual ~SurfaceBackgroundData();

  /** Write the content of this object formated as xml to the given
      stream */
  void write_xml(std::ofstream* xml);
  
  WorldObj* create_WorldObj();
  EditorObjLst create_EditorObj();
};


class EditorSurfaceBackground : public SurfaceBackgroundData,
                                public SpriteEditorObj
{
private:
public:
  EditorSurfaceBackground (const SurfaceBackgroundData& data)
    : SurfaceBackgroundData (data),
      SpriteEditorObj (desc.res_name, desc.datafile, pos)
  {
    
  }

  void write_xml(std::ofstream* xml) { this->SurfaceBackgroundData::write_xml 
(xml); }

  boost::shared_ptr<EditorObj> duplicate() {
    return boost::shared_ptr<EditorObj>
      (new EditorSurfaceBackground (static_cast<SurfaceBackgroundData>(*this)));
  }

  std::string status_line () { return "SurfaceBackground: " 
                                 + to_string (pos.x) + ", "
                                 + to_string (pos.y) + ", "
                                 + to_string (pos.z); }
};

#endif

/* EOF */


--- NEW FILE: thunderstorm_background.cxx ---
//  $Id: thunderstorm_background.cxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "../pingus_resource.hxx"
#include "thunderstorm_background.hxx"

ThunderstormBackground::ThunderstormBackground()
{
  clouds_sur = PingusResource::load_surface("Textures/thunderstorm", 
"textures");
  // flash_sur.push_back(PingusResource::load_surface("flash1", 
"thunderstorm"));
  // flash_sur.push_back(PingusResource::load_surface("flash2", 
"thunderstorm"));
  x_pos = 0;
}

ThunderstormBackground::~ThunderstormBackground()
{
  
}

void
ThunderstormBackground::update(float /*delta*/)
{
  x_pos += 1;
  if (x_pos >= (int) clouds_sur.get_width())
    x_pos = 0;
}

void
ThunderstormBackground::draw_offset(int x_of, int y_of, float /*s*/)
{
  clouds_sur.put_screen(x_pos + x_of, y_of);
}

/* EOF */

--- NEW FILE: thunderstorm_background.hxx ---
//  $Id: thunderstorm_background.hxx,v 1.1 2002/06/12 19:02:30 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef THUNDERSTORMBACKGROUND_HH
#define THUNDERSTORMBACKGROUND_HH

#include <vector>
#include "../worldobj.hxx"
#include "thunderstorm_background_data.hxx"

class ThunderstormBackground : public WorldObj,
                               public ThunderstormBackgroundData
{
private:
  //SurfaceBackground* background;
  CL_Surface clouds_sur;
  std::vector<CL_Surface> flash_sur;
  int x_pos;
public:
  ///
  ThunderstormBackground();
  ///
  virtual ~ThunderstormBackground();
  ///

  float get_z_pos() const { return pos.z; }
  
  void update(float delta);
  void draw_offset(int x_of, int y_of, float s = 1.0);
};

#endif

/* EOF */

--- NEW FILE: thunderstorm_background_data.cxx ---
//  $Id: thunderstorm_background_data.cxx,v 1.1 2002/06/12 19:02:30 grumbel Exp 
$
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <fstream>
#include <iostream>
#include "../xml_helper.hxx"
#include "thunderstorm_background.hxx"

void
ThunderstormBackgroundData::write_xml(std::ofstream* xml)
{
  (*xml) << "<background type=\"thunderstorm\">\n"
         << "</background>" << std::endl;
}

ThunderstormBackgroundData::ThunderstormBackgroundData (xmlDocPtr doc, 
xmlNodePtr cur)
{
  cur = cur->children; 
  while (cur != NULL)
    {
      if (xmlIsBlankNode(cur)) {
        cur = cur->next;
        continue;
      }

      if (strcmp ((char*) cur->name, "position") == 0) {
        pos = XMLhelper::parse_vector (doc, cur);
      } else {
        std::cout << "ThunderstormBackgroundData::create(xmlDocPtr doc, 
xmlNodePtr cur) error" << std::endl;
      }
    }
}

WorldObj* 
ThunderstormBackgroundData::create_WorldObj()
{
  return new ThunderstormBackground ();
}

EditorObjLst 
ThunderstormBackgroundData::create_EditorObj()
{
  EditorObjLst lst;
  lst.push_back (boost::shared_ptr<EditorObj>(new EditorThunderstormBackground 
(*this)));
  return lst;
}

/* EOF */


--- NEW FILE: thunderstorm_background_data.hxx ---
//  $Id: thunderstorm_background_data.hxx,v 1.1 2002/06/12 19:02:30 grumbel Exp 
$
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
// 
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef THUNDERSTORMBACKGROUNDDATA_HH
#define THUNDERSTORMBACKGROUNDDATA_HH

#include "../worldobj_data.hxx"
#include "../editor/sprite_editorobj.hxx"
#include "../boost/smart_ptr.hpp"

class _xmlDoc;  typedef _xmlDoc*  xmlDocPtr;
class _xmlNode; typedef _xmlNode* xmlNodePtr;

class ThunderstormBackgroundData : public WorldObjData
{
public:
  CL_Vector pos;

  ThunderstormBackgroundData () {}
  ThunderstormBackgroundData (xmlDocPtr doc, xmlNodePtr cur);

  virtual ~ThunderstormBackgroundData() {}

  /** Writte the content of this object formated as xml to the given
      stream */
  virtual void write_xml(std::ofstream* xml);
  
  WorldObj* create_WorldObj();
  EditorObjLst create_EditorObj();
};

class EditorThunderstormBackground : public ThunderstormBackgroundData,
                                     public SpriteEditorObj
{
private:
public:
  EditorThunderstormBackground (const ThunderstormBackgroundData& data)
    : ThunderstormBackgroundData (data),
      SpriteEditorObj ("Stars/starfield_icon", "game", pos)
  {
    pos = CL_Vector(-128.0f, 0.0f);
  }

  void write_xml(std::ofstream* xml) { 
this->ThunderstormBackgroundData::write_xml (xml); }
  
  boost::shared_ptr<EditorObj> duplicate() {
    return boost::shared_ptr<EditorObj>
      (new EditorThunderstormBackground 
(static_cast<ThunderstormBackgroundData>(*this)));
  }
  
  std::string status_line () { return "ThunderstormBackground"; }
};

#endif

/* EOF */


Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/backgrounds/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- Makefile.am 12 Aug 2001 18:36:41 -0000      1.4
+++ Makefile.am 12 Jun 2002 19:02:30 -0000      1.5
@@ -17,11 +17,11 @@
 
 noinst_LIBRARIES = libpingus_backgrounds.a
 
-libpingus_backgrounds_a_SOURCES = ThunderstormBackground.cc     
ThunderstormBackground.hh     \
-                                  ThunderstormBackgroundData.cc 
ThunderstormBackgroundData.hh \
-                                  SurfaceBackground.cc          
SurfaceBackground.hh          \
-                                  SurfaceBackgroundData.cc      
SurfaceBackgroundData.hh      \
-                                  StarfieldBackground.cc        
StarfieldBackground.hh \
-                                  SolidColorBackground.cc       
SolidColorBackground.hh
+libpingus_backgrounds_a_SOURCES = thunderstorm_background.cxx     
thunderstorm_background.hxx     \
+                                  thunderstorm_background_data.cxx 
thunderstorm_background_data.hxx \
+                                  surface_background.cxx          
surface_background.hxx          \
+                                  surface_background_data.cxx      
surface_background_data.hxx      \
+                                  starfield_background.cxx        
starfield_background.hxx \
+                                  solidcolor_background.cxx       
solidcolor_background.hxx
 
 # EOF #

--- SolidColorBackground.cc DELETED ---

--- SurfaceBackgroundData.cc DELETED ---

--- ThunderstormBackgroundData.cc DELETED ---




reply via email to

[Prev in Thread] Current Thread [Next in Thread]