aboutsummaryrefslogtreecommitdiff
path: root/src/MenuScene.cpp
blob: 1deaa6671c6f4ea7df4af4257b6e000804edcbd9 (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
#include <QApplication>

#include "ParallaxScrollerStatic.h"
#include "GraphicsButtonObject.h"
#include "GameView.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);

    initializeScene();
}

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

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

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

    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("Platformer");
}