Implemented Yoshi's Island-style flapping (based on Wansti's code) and force-activate...
[supertux.git] / src / object / background.cpp
index 2d6cc41..a353763 100644 (file)
 //  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 <config.h>
 
 #include "background.h"
-#include "app/globals.h"
 #include "camera.h"
 #include "video/drawing_context.h"
-#include "utils/lispwriter.h"
+#include "lisp/lisp.h"
+#include "lisp/writer.h"
+#include "object_factory.h"
+#include "resources.h"
+#include "main.h"
 
 Background::Background()
   : type(INVALID), layer(LAYER_BACKGROUND0), image(0)
 {
 }
 
-Background::Background(LispReader& reader)
+Background::Background(const lisp::Lisp& reader)
   : type(INVALID), layer(LAYER_BACKGROUND0), image(0)
 {
-  reader.read_int("layer", layer);
-  if(reader.read_string("image", imagefile) 
-      && reader.read_float("speed", speed)) {
+  reader.get("layer", layer);
+  if(reader.get("image", imagefile) 
+      && reader.get("speed", speed)) {
     set_image(imagefile, speed);
+  } else {
+    std::vector <unsigned int> bkgd_top_color, bkgd_bottom_color;
+    if(reader.get_vector("top_color", bkgd_top_color) &&
+        reader.get_vector("bottom_color", bkgd_bottom_color))
+      set_gradient(Color(bkgd_top_color), Color(bkgd_bottom_color));
   }
-
-  std::vector <unsigned int> bkgd_top_color, bkgd_bottom_color;
-  if(reader.read_int_vector("top_color", bkgd_top_color) &&
-     reader.read_int_vector("bottom_color", bkgd_bottom_color))
-    set_gradient(Color(bkgd_top_color), Color(bkgd_bottom_color));
 }
 
 Background::~Background()
@@ -51,7 +53,7 @@ Background::~Background()
 }
 
 void
-Background::write(LispWriter& writer)
+Background::write(lisp::Writer& writer)
 {
   if(type == INVALID)
     return;
@@ -78,7 +80,7 @@ Background::write(LispWriter& writer)
 }
 
 void
-Background::action(float)
+Background::update(float)
 {
 }
 
@@ -101,7 +103,7 @@ Background::set_gradient(Color top, Color bottom)
   gradient_bottom = bottom;
 
   delete image;
-  image = new Surface(top, bottom, screen->w, screen->h);
+  image = new Surface(top, bottom, SCREEN_WIDTH, SCREEN_HEIGHT);
 }
 
 void
@@ -120,10 +122,11 @@ Background::draw(DrawingContext& context)
     int sy = int(-context.get_translation().y * speed) % image->h - image->h;
     context.push_transform();
     context.set_translation(Vector(0, 0));
-    for(int x = sx; x < screen->w; x += image->w)
-      for(int y = sy; y < screen->h; y += image->h)
+    for(int x = sx; x < SCREEN_WIDTH; x += image->w)
+      for(int y = sy; y < SCREEN_HEIGHT; y += image->h)
         context.draw_surface(image, Vector(x, y), layer);
     context.pop_transform();
   }
 }
 
+IMPLEMENT_FACTORY(Background, "background");