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/>.
|
|
|
|
****************************************************************************/
|
2020-04-27 13:06:59 +02:00
|
|
|
#include <coreinit/time.h>
|
2016-10-05 16:03:29 +02:00
|
|
|
#include "Pipe.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.
|
|
|
|
*/
|
|
|
|
|
2020-07-05 13:34:13 +02:00
|
|
|
Pipe::Pipe(float x) {
|
2016-10-05 16:03:29 +02:00
|
|
|
srand(OSGetTime());
|
2020-07-05 13:34:13 +02:00
|
|
|
loc_y = rand() % 250 - 125;
|
2016-10-05 16:03:29 +02:00
|
|
|
loc_x = x;
|
|
|
|
pipeBottomImg = Resources::GetImageData("pipe_down.png");
|
|
|
|
pipeTopImg = Resources::GetImageData("pipe_up.png");
|
|
|
|
pipebottom = new GuiImage(pipeBottomImg);
|
|
|
|
pipetop = new GuiImage(pipeTopImg);
|
|
|
|
|
|
|
|
pipebottom->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
|
|
|
|
pipetop->setAlignment(ALIGN_CENTER | ALIGN_CENTER);
|
|
|
|
|
2020-07-05 13:34:13 +02:00
|
|
|
pipebottom->setPosition((int) loc_x, -410 - loc_y);
|
|
|
|
pipetop->setPosition((int) loc_x, 410 - loc_y);
|
2016-10-05 16:03:29 +02:00
|
|
|
|
2020-07-05 13:34:13 +02:00
|
|
|
scroll_state = false;
|
2016-10-05 16:03:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the GuiButton class.
|
|
|
|
*/
|
2020-07-05 13:34:13 +02:00
|
|
|
Pipe::~Pipe() {
|
|
|
|
loc_x = 0.0f;
|
|
|
|
loc_y = 0.0f;
|
|
|
|
scroll_state = 0;
|
|
|
|
delete (pipetop);
|
|
|
|
delete (pipebottom);
|
|
|
|
delete (pipeTopImg);
|
|
|
|
delete (pipeBottomImg);
|
2016-10-05 16:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-07-05 13:34:13 +02:00
|
|
|
void Pipe::setPosX(float x) {
|
|
|
|
loc_x = x;
|
|
|
|
pipebottom->setPosition((int) loc_x, -410 - loc_y);
|
|
|
|
pipetop->setPosition((int) loc_x, 410 - loc_y);
|
2016-10-05 16:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-07-05 13:34:13 +02:00
|
|
|
void Pipe::setScroll(bool state) {
|
|
|
|
scroll_state = state;
|
2016-10-05 16:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-07-05 13:34:13 +02:00
|
|
|
int Pipe::checkCollision(GuiImage *check) {
|
|
|
|
if ((pipetop->getLeft() - pipetop->getWidth() / 4.0f) < (check->getLeft() + check->getWidth() / 2.0f) &&
|
|
|
|
(pipetop->getLeft() + pipetop->getWidth() / 2) > (check->getLeft() - check->getWidth() / 2.0f)) { //How can that thing work? No, really...
|
|
|
|
poss_collision = 1;
|
|
|
|
if ((check->getTop() + check->getHeight() / 2.0f) > (pipetop->getTop() - 720.0f) || ((check->getTop() - check->getHeight() / 2.0f)) < pipebottom->getTop()) {
|
|
|
|
poss_collision = 0; //we already collided
|
2016-10-05 16:03:29 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2020-07-05 13:34:13 +02:00
|
|
|
} else if (poss_collision == 1) { //We just surpassed the problem
|
|
|
|
poss_collision = 0;
|
2016-10-05 16:03:29 +02:00
|
|
|
return -1; //Add point
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw the button on screen
|
|
|
|
*/
|
2020-07-05 13:34:13 +02:00
|
|
|
void Pipe::draw(CVideo *v) {
|
|
|
|
if (scroll_state == true) {
|
|
|
|
loc_x -= 1.5f;
|
|
|
|
if (loc_x < -640.0f) {
|
|
|
|
loc_x = 700.0f;
|
|
|
|
loc_y = rand() % 250 - 125;
|
2016-10-05 16:03:29 +02:00
|
|
|
}
|
2020-07-05 13:34:13 +02:00
|
|
|
pipebottom->setPosition((int) loc_x, -410 - loc_y);
|
|
|
|
pipetop->setPosition((int) loc_x, 410 - loc_y);
|
|
|
|
}
|
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
|
|
|
|
pipebottom->draw(v);
|
|
|
|
pipetop->draw(v);
|
2016-10-05 16:03:29 +02:00
|
|
|
}
|
|
|
|
|
2020-07-05 13:34:13 +02:00
|
|
|
void Pipe::update(GuiController *c) {
|
2016-10-05 16:03:29 +02:00
|
|
|
|
|
|
|
}
|