Flappy-Bird_GX2/src/game/Background.cpp

78 lines
1.9 KiB
C++
Raw Normal View History

2016-10-05 16:03:29 +02:00
/****************************************************************************
* Copyright (C) 2015 Dimok
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include "Background.h"
#include "gui/GuiTrigger.h"
#include "gui/GuiController.h"
2019-11-24 14:21:45 +01:00
#include "resources/Resources.h"
2016-10-05 16:03:29 +02:00
/**
* Constructor for the GuiButton class.
*/
Background::Background(const char *picture, float scroll_speed) {
2020-07-05 13:34:13 +02:00
loc_x = 0.0f;
2016-10-05 16:03:29 +02:00
bgImg = Resources::GetImageData(picture);
bg = new GuiImage(bgImg);
bgs = new GuiImage(bgImg);
2020-07-05 13:34:13 +02:00
2016-10-05 16:03:29 +02:00
bg->setPosition(0, 0);
bgs->setPosition(-1280, 0);
2020-07-05 13:34:13 +02:00
speed = scroll_speed;
2016-10-05 16:03:29 +02:00
}
/**
* Destructor for the GuiButton class.
*/
2020-07-05 13:34:13 +02:00
Background::~Background() {
speed = 0.0f;
loc_x = 0.0f;
delete (bgImg);
delete (bg);
delete (bgs);
2016-10-05 16:03:29 +02:00
}
2020-07-05 13:34:13 +02:00
void Background::setScrollSpeed(float scroll_speed) {
speed = scroll_speed;
2016-10-05 16:03:29 +02:00
}
/**
* Draw the button on screen
*/
2020-07-05 13:34:13 +02:00
void Background::draw(CVideo *v) {
if (speed > 0.0f) {
loc_x -= speed;
if (loc_x < 0.0f) loc_x = 1280.0f;
2016-10-05 16:03:29 +02:00
2020-07-05 13:34:13 +02:00
bg->setPosition((int) loc_x, 0);
bgs->setPosition((int) loc_x - 1280, 0);
}
2016-10-05 16:03:29 +02:00
2020-07-05 13:34:13 +02:00
if (!this->isVisible())
return;
2016-10-05 16:03:29 +02:00
2020-07-05 13:34:13 +02:00
// draw images
bg->draw(v);
bgs->draw(v);
2016-10-05 16:03:29 +02:00
}
2020-07-05 13:34:13 +02:00
void Background::update(GuiController *c) {
2016-10-05 16:03:29 +02:00
}