pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/worldobjs starfield_background.cxx,NO


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/worldobjs starfield_background.cxx,NONE,1.1 starfield_background.hxx,NONE,1.1 starfield_background_stars.cxx,NONE,1.1 starfield_background_stars.hxx,NONE,1.1 surface_background.cxx,NONE,1.1 surface_background.hxx,NONE,1.1 Makefile.am,1.11,1.12 groundpiece.hxx,1.2,1.3
Date: 16 Sep 2002 20:52:24 -0000

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

Modified Files:
        Makefile.am groundpiece.hxx 
Added Files:
        starfield_background.cxx starfield_background.hxx 
        starfield_background_stars.cxx starfield_background_stars.hxx 
        surface_background.cxx surface_background.hxx 
Log Message:
splitted some more backgrounds


--- NEW FILE: starfield_background.cxx ---
//  $Id: starfield_background.cxx,v 1.1 2002/09/16 20:52:22 torangan 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 "../worldobjsdata/starfield_background_data.hxx"
#include "starfield_background.hxx"
#include "starfield_background_stars.hxx"

namespace WorldObjs {

StarfieldBackground::StarfieldBackground 
(WorldObjsData::StarfieldBackgroundData* data_)
  : data(new WorldObjsData::StarfieldBackgroundData(*data_))
{

  int i;

  for (i=0; i < data->small_stars_count; ++i)
    stars.push_back(new 
StarfieldBackgroundStars(StarfieldBackgroundStars::SMALL_STAR));

  for (i=0; i < data->middle_stars_count; ++i)
    stars.push_back(new 
StarfieldBackgroundStars(StarfieldBackgroundStars::MIDDLE_STAR));

  for (i=0; i < data->large_stars_count; ++i)
    stars.push_back(new 
StarfieldBackgroundStars(StarfieldBackgroundStars::LARGE_STAR));
}

StarfieldBackground::~StarfieldBackground ()
{
  delete data;
  for (unsigned int i = 0; i < stars.size(); ++i)
    delete stars[i];
}


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);
    }

  UNUSED_ARG(s);
}

} // namespace WorldObjs

/* EOF */

--- NEW FILE: starfield_background.hxx ---
//  $Id: starfield_background.hxx,v 1.1 2002/09/16 20:52:22 torangan 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 HEADER_PINGUS_WORLDOJBS_STARFIELD_BACKGROUND_HXX
#define HEADER_PINGUS_WORLDOBJS_STARFIELD_BACKGROUND_HXX

#include "../worldobj.hxx"

namespace WorldObjsData {
class StarfieldBackgroundData;
}

namespace WorldObjs {

class StarfieldBackgroundStars;

class StarfieldBackground : public WorldObj
{
private:
  WorldObjsData::StarfieldBackgroundData* const data;
  std::vector<StarfieldBackgroundStars*>        stars;

public:
  StarfieldBackground (WorldObjsData::StarfieldBackgroundData* data_);
 ~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);
  
private:
  StarfieldBackground (const StarfieldBackground&);
  StarfieldBackground operator= (const StarfieldBackground&);
};

} // namespace WorldObjs

#endif

/* EOF */

--- NEW FILE: starfield_background_stars.cxx ---
//  $Id: starfield_background_stars.cxx,v 1.1 2002/09/16 20:52:22 torangan 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 "../world.hxx"
#include "../pingus_resource.hxx"
#include "starfield_background_stars.hxx"

namespace WorldObjs { 

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();
    }
  UNUSED_ARG(delta);
}

void
StarfieldBackgroundStars::draw_offset (int x_of, int y_of, float s)
{
  sur.put_screen(static_cast<int>(x_pos + x_of), static_cast<int>(y_pos + 
y_of));
  UNUSED_ARG(s);
}

} // namespace WorldObjs

/* EOF */

--- NEW FILE: starfield_background_stars.hxx ---
//  $Id: starfield_background_stars.hxx,v 1.1 2002/09/16 20:52:22 torangan 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 HEADER_PINGUS_WORLDOBJS_STARFIELD_BACKGROUND_STARS_HXX
#define HEADER_PINGUS_WORLDOBJS_STARFIELD_BACKGROUND_STARS_HXX

#include <ClanLib/Display/Display/surface.h>
#include "../worldobj.hxx"

namespace WorldObjs {

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);  

private:
  StarfieldBackgroundStars (const StarfieldBackgroundStars&);
  StarfieldBackgroundStars operator= (const StarfieldBackgroundStars&);
};

} // namespace WorldObjs

#endif

/* EOF */

--- NEW FILE: surface_background.cxx ---
//  $Id: surface_background.cxx,v 1.1 2002/09/16 20:52:22 torangan 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 <ClanLib/Display/SurfaceProviders/canvas.h>
#include <ClanLib/Display/Display/display.h>
#include "../graphic_context.hxx"
#include "../world.hxx"
#include "../timer.hxx"
#include "../pingus_resource.hxx"
#include "../globals.hxx"
#include "../blitter.hxx"
#include "../worldobjsdata/surface_background_data.hxx"
#include "surface_background.hxx"

namespace WorldObjs {

SurfaceBackground::SurfaceBackground (WorldObjsData::SurfaceBackgroundData* 
data_)
  : scroll_ox(0),
    scroll_oy(0),
    data(new WorldObjsData::SurfaceBackgroundData(*data_))

{
  Timer timer;

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

  if (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: " << data->desc.res_name << std::endl
    << "file: " << data->desc.datafile << std::endl;*/

  if (background_manipulation_enabled)
    {
      std::cout << "------ SurfaceBackground:: Manipulating background ------" 
<< std::endl;
      CL_Surface source_surface = PingusResource::load_surface(data->desc);
      
      CL_Canvas* canvas;

      // Scaling Code
      if (data->stretch_x && data->stretch_y)
        canvas = Blitter::scale_surface_to_canvas(source_surface, 
world->get_width(), world->get_height());
      else if (data->stretch_x && !data->stretch_y)
        canvas = Blitter::scale_surface_to_canvas(source_surface, 
world->get_width(), source_surface.get_height());
      else if (!data->stretch_x && data->stretch_y)
        canvas = Blitter::scale_surface_to_canvas(source_surface, 
source_surface.get_width(), world->get_height());
      else
        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()
      */
    
      if (data->color.alpha != 0.0 && data->color != Color(0, 0, 0, 1.0f))
        { // Workaround for a bug which caused all levels to have the
          // wrong background color
          canvas->fill_rect(0, 0, 
                            canvas->get_width(), canvas->get_height(),
                            data->color.red, data->color.green, 
data->color.blue, 
                            data->color.alpha);
        }
      
      bg_surface = CL_Surface(canvas, true);
      std::cout << "Surface: " << bg_surface.get_width() << " " << 
bg_surface.get_height() << std::endl;
    }
  else
    {
      bg_surface = PingusResource::load_surface(data->desc);
    }

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

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

SurfaceBackground::~SurfaceBackground ()
{
  delete data;
}

float
SurfaceBackground::get_z_pos () const
{
  return data->pos.z;
}

void
SurfaceBackground::update (float /*delta*/)
{
  counter++;

  scroll_ox += data->scroll_x;
  scroll_oy += data->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 (GraphicContext& gc)
{
  if (fast_mode) 
    {
      CL_Display::clear_display();
    } 
  else 
    {
      int x_of = static_cast<int>(gc.get_x_offset () + (gc.get_width ()/2));
      int y_of = static_cast<int>(gc.get_y_offset () + (gc.get_height ()/2));

      int start_x;
      int start_y;
      
      start_x = static_cast<int>((x_of * data->para_x) + scroll_ox);
      start_y = static_cast<int>((y_of * data->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 - static_cast<int>(bg_surface.get_height()))
        start_y += bg_surface.get_height();
      
      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); // FIXME: should use gc
            }
        }
    }
}

} // namespace WorldObjs

/* EOF */

--- NEW FILE: surface_background.hxx ---
//  $Id: surface_background.hxx,v 1.1 2002/09/16 20:52:22 torangan 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 HEADER_PINGUS_WORLDOBJS_SURFACE_BACKGROUND_HXX
#define HEADER_PINGUS_WORLDOBJS_SURFACE_BACKGROUND_HXX

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

namespace WorldObjsData {
class SurfaceBackgroundData;
}

namespace WorldObjs {

class SurfaceBackground : public WorldObj
{
private:
  GameCounter counter;

  CL_Surface bg_surface;
  
  /** The horizontal scrolling speed in pixels per tick */
  float scroll_ox;

  /** The vertical scrolling speed in pixels per tick */
  float scroll_oy;

  WorldObjsData::SurfaceBackgroundData* const data;
  
public:
  SurfaceBackground (WorldObjsData::SurfaceBackgroundData* data_);
 ~SurfaceBackground ();

  float get_z_pos () const;

  void update (float delta);
  void draw (GraphicContext& gc);
  
private:
  SurfaceBackground (const SurfaceBackground&);
  SurfaceBackground operator= (const SurfaceBackground&);
};

} // namespace WorldObjs

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobjs/Makefile.am,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- Makefile.am 16 Sep 2002 19:18:56 -0000      1.11
+++ Makefile.am 16 Sep 2002 20:52:22 -0000      1.12
@@ -20,22 +20,25 @@
 noinst_LIBRARIES = libpingus_worldobjs.a
 
 libpingus_worldobjs_a_SOURCES = \
-       bumper.cxx                 bumper.hxx        \
-        conveyor_belt.cxx          conveyor_belt.hxx \
-       fake_exit.cxx              fake_exit.hxx     \
-       guillotine.cxx             guillotine.hxx    \
-        groundpiece.hxx            groundpiece.cxx   \
-       hammer.cxx                 hammer.hxx        \
-        ice_block.cxx              ice_block.hxx     \
-        info_box.cxx               info_box.hxx      \
-       laser_exit.cxx             laser_exit.hxx    \
-       smasher.cxx                smasher.hxx       \
-       solid_color_background.cxx solid_color_background.hxx \
-       spike.cxx                  spike.hxx         \
-        switch_door.cxx            switch_door.hxx   \
-        teleporter.cxx             teleporter.hxx    \
-        worldobj_group.hxx         worldobj_group.cxx \
-        rain_generator.hxx         rain_generator.cxx \
-        snow_generator.hxx         snow_generator.cxx
+       bumper.cxx                     bumper.hxx        \
+        conveyor_belt.cxx              conveyor_belt.hxx \
+       fake_exit.cxx                  fake_exit.hxx     \
+       guillotine.cxx                 guillotine.hxx    \
+        groundpiece.hxx                groundpiece.cxx   \
+       hammer.cxx                     hammer.hxx        \
+        ice_block.cxx                  ice_block.hxx     \
+        info_box.cxx                   info_box.hxx      \
+       laser_exit.cxx                 laser_exit.hxx    \
+       smasher.cxx                    smasher.hxx       \
+       solid_color_background.cxx     solid_color_background.hxx \
+       spike.cxx                      spike.hxx         \
+       starfield_background.cxx       starfield_background.hxx \
+       starfield_background_stars.cxx starfield_background_stars.hxx \
+       surface_background.cxx         surface_background.hxx \
+        switch_door.cxx                switch_door.hxx   \
+        teleporter.cxx                 teleporter.hxx    \
+        worldobj_group.hxx             worldobj_group.cxx\
+        rain_generator.hxx             rain_generator.cxx \
+        snow_generator.hxx             snow_generator.cxx 
 
 ## EOF ##

Index: groundpiece.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/worldobjs/groundpiece.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- groundpiece.hxx     16 Sep 2002 20:31:09 -0000      1.2
+++ groundpiece.hxx     16 Sep 2002 20:52:22 -0000      1.3
@@ -39,7 +39,7 @@
 
   float get_z_pos () const { return 0; }
 
-  void draw(GraphicContext& gc) {}
+  void draw(GraphicContext&) {}
   void on_startup();
   bool purge_after_startup() { return true; }
 private:





reply via email to

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