forgot to add some files
authorMatthias Braun <matze@braunis.de>
Thu, 20 May 2004 14:56:16 +0000 (14:56 +0000)
committerMatthias Braun <matze@braunis.de>
Thu, 20 May 2004 14:56:16 +0000 (14:56 +0000)
SVN-Revision: 1279

src/background.cpp [new file with mode: 0644]
src/background.h [new file with mode: 0644]

diff --git a/src/background.cpp b/src/background.cpp
new file mode 100644 (file)
index 0000000..3bbfe41
--- /dev/null
@@ -0,0 +1,52 @@
+#include "background.h"
+
+#include "globals.h"
+#include "viewport.h"
+#include "display_manager.h"
+
+Background::Background(DisplayManager& displaymanager)
+{
+  displaymanager.add_drawable(this, LAYER_BACKGROUND0);
+}
+
+Background::~Background()
+{
+}
+
+void
+Background::action(float)
+{
+}
+
+void
+Background::set_image(Surface* image, float speed)
+{
+  bgtype = BACKGROUND_IMAGE;
+  this->image = image;
+  this->speed = speed;
+}
+
+void
+Background::set_gradient(Color top, Color bottom)
+{
+  bgtype = BACKGROUND_GRADIENT;
+  gradient_top = top;
+  gradient_bottom = bottom;
+}
+
+void
+Background::draw(ViewPort& viewport, int )
+{
+  if(bgtype == BACKGROUND_GRADIENT) {
+    drawgradient(gradient_top, gradient_bottom);
+  } else if(bgtype == BACKGROUND_IMAGE) {
+    int sx = int(-viewport.get_translation().x * float(speed/100.))
+      % image->w - image->w;
+    int sy = int(-viewport.get_translation().y * float(speed/100.))
+      % image->h - image->h;
+    for(int x = sx; x < screen->w; x += image->w)
+      for(int y = sy; y < screen->h; y += image->h)
+        image->draw(x, y);
+  }
+}
+
diff --git a/src/background.h b/src/background.h
new file mode 100644 (file)
index 0000000..22334db
--- /dev/null
@@ -0,0 +1,40 @@
+#ifndef __BACKGROUND_H__
+#define __BACKGROUND_H__
+
+#include "texture.h"
+#include "game_object.h"
+#include "drawable.h"
+
+enum {
+  BACKGROUND_GRADIENT,
+  BACKGROUND_IMAGE
+};
+
+class DisplayManager;
+
+class Background : public _GameObject, public Drawable
+{
+public:
+  Background(DisplayManager& displaymanager);
+  virtual ~Background();
+
+  void set_image(Surface* image, float bkgd_speed);
+
+  void set_gradient(Color top, Color bottom);
+
+  virtual std::string type() const
+  { return "Background"; }
+
+  virtual void action(float elapsed_time);
+
+  virtual void draw(ViewPort& viewport, int layer);
+
+private:
+  int bgtype;
+  float speed;
+  Surface* image;
+  Color gradient_top, gradient_bottom;
+};
+
+#endif
+