-converted remaining classes to GameObject
[supertux.git] / src / background.cpp
1 #include "background.h"
2
3 #include "globals.h"
4 #include "viewport.h"
5 #include "display_manager.h"
6
7 Background::Background(DisplayManager& displaymanager)
8 {
9   displaymanager.add_drawable(this, LAYER_BACKGROUND0);
10 }
11
12 Background::~Background()
13 {
14 }
15
16 void
17 Background::action(float)
18 {
19 }
20
21 void
22 Background::set_image(Surface* image, float speed)
23 {
24   bgtype = BACKGROUND_IMAGE;
25   this->image = image;
26   this->speed = speed;
27 }
28
29 void
30 Background::set_gradient(Color top, Color bottom)
31 {
32   bgtype = BACKGROUND_GRADIENT;
33   gradient_top = top;
34   gradient_bottom = bottom;
35 }
36
37 void
38 Background::draw(ViewPort& viewport, int )
39 {
40   if(bgtype == BACKGROUND_GRADIENT) {
41     drawgradient(gradient_top, gradient_bottom);
42   } else if(bgtype == BACKGROUND_IMAGE) {
43     int sx = int(-viewport.get_translation().x * float(speed/100.))
44       % image->w - image->w;
45     int sy = int(-viewport.get_translation().y * float(speed/100.))
46       % image->h - image->h;
47     for(int x = sx; x < screen->w; x += image->w)
48       for(int y = sy; y < screen->h; y += image->h)
49         image->draw(x, y);
50   }
51 }
52