[Super-tux-commit] supertux/src background.cpp,NONE,1.1 background.h,NONE,1.1
Brought to you by:
wkendrick
From: Matze B. <mat...@us...> - 2004-05-20 14:56:27
|
Update of /cvsroot/super-tux/supertux/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27235 Added Files: background.cpp background.h Log Message: forgot to add some files --- NEW FILE: background.h --- #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 --- NEW FILE: background.cpp --- #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); } } |