From: Matthias Braun Date: Thu, 20 May 2004 14:56:16 +0000 (+0000) Subject: forgot to add some files X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=8c96075b010d05e916f8d73a7ee472408b138694;p=supertux.git forgot to add some files SVN-Revision: 1279 --- diff --git a/src/background.cpp b/src/background.cpp new file mode 100644 index 000000000..3bbfe4137 --- /dev/null +++ b/src/background.cpp @@ -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 index 000000000..22334db94 --- /dev/null +++ b/src/background.h @@ -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 +