aboutsummaryrefslogtreecommitdiff
path: root/src/MenuScene.cpp
blob: a7c2a75755d922c75135d1e9543b7afaafe4a700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <QApplication>

#include "ParallaxScrollerStatic.h"
#include "GraphicsButtonObject.h"
#include "GameView.h"

#include "AnimatingUiElement.h"

#include "MenuScene.h"

MenuScene::MenuScene(const QString &name, const QRectF &rect, GameView *parent)
    : GameScene(name, parent)
{
    setSceneRect(rect);

    QString appDir = qApp->applicationDirPath();

    m_background = new ParallaxScrollerStatic(this);
    m_background->setLayerWidth(rect.width());
    //m_background->addParallaxScrollItem(QString(appDir + "/gfx/bg/layer1.png"), QPointF(0,0), -2, 6);
    //m_background->addParallaxScrollItem(QString(appDir + "/gfx/bg/layer2.png"), QPointF(0,0), -1, 4);

    m_background->addParallaxScrollItem(QString(appDir + "/data/gfx/background/layer_three.png"), QPointF(0,0), -3, 8);
    m_background->addParallaxScrollItem(QString(appDir + "/data/gfx/background/layer_two.png"), QPointF(0,0), -2, 6);
    m_background->addParallaxScrollItem(QString(appDir + "/data/gfx/background/layer_one.png"), QPointF(0,0), -1, 4);

    initializeScene();
}

MenuScene::~MenuScene()
{
    delete m_background;
}

void MenuScene::updateLogic()
{
    advance();
    update();
}

void MenuScene::initializeScene()
{
    int yoff = 200;

    AnimatingUiElement *btn1 = new AnimatingUiElement("Play");

    btn1->setOffset(-btn1->boundingRect().width() / 2,
                    -btn1->boundingRect().height() / 2);
    btn1->setPos(sceneRect().width() / 2, yoff);
    addItem(btn1);

    AnimatingUiElement *btn2 = new AnimatingUiElement("Credits");
    btn2->setOffset(-btn2->boundingRect().width() / 2,
                    -btn2->boundingRect().height() / 2);
    btn2->setPos(sceneRect().width() / 2, btn1->pos().y() + btn1->boundingRect().height() + 20);
    addItem(btn2);

    AnimatingUiElement *btn3 = new AnimatingUiElement("Quit");
    btn3->setOffset(-btn3->boundingRect().width() / 2,
                    -btn3->boundingRect().height() / 2);
    btn3->setPos(sceneRect().width() / 2, btn2->pos().y() + btn2->boundingRect().height() + 20);
    addItem(btn3);

    connect(btn1, SIGNAL(clicked()), gameView(), SLOT(showLevelSelectionScene()));
    connect(btn2, SIGNAL(clicked()), gameView(), SLOT(showCreditsScene()));
    connect(btn3, SIGNAL(clicked()), qApp, SLOT(quit()));

    /*
    GraphicsButtonObject *btn1 = new GraphicsButtonObject("Play", 0, this);
    btn1->setPos(260, yoff);

    GraphicsButtonObject *btn2 = new GraphicsButtonObject("Credits", 0, this);
    btn2->setPos(260, btn1->pos().y() + btn1->boundingRect().bottom() + 20);

    GraphicsButtonObject *btn3 = new GraphicsButtonObject("Quit", 0, this);
    btn3->setPos(260, btn2->pos().y() + btn2->boundingRect().bottom() + 20);

    connect(btn1, SIGNAL(clicked()), gameView(), SLOT(showLevelSelectionScene()));
    connect(btn2, SIGNAL(clicked()), gameView(), SLOT(showCreditsScene()));
    connect(btn3, SIGNAL(clicked()), qApp, SLOT(quit()));
    */

    addTitle("prism");
}