aboutsummaryrefslogtreecommitdiff
path: root/src/ActionScene.h
blob: fa503a459d330dfbce5ac0045a391a85238c7c71 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef ActionScene_H
#define ActionScene_H

#include <QObject>
#include <QRectF>
#include <QGraphicsRectItem>

#include "GameScene.h"
#include "Sprite.h"

#include "map.h"
#include "mapreader.h"
#include "orthogonalrenderer.h"

#include "Box2D/Common/b2Math.h"

class QGraphicsPixmapItem;
class Hero;
class HeadsUpDisplay;

class b2World;

class ActionScene : public GameScene
{
    Q_OBJECT

public:
    explicit ActionScene(const QString &name, const QRectF &rect, GameView *parent = 0);
    virtual ~ActionScene();

    void updateLogic();
    void keyPressEvent(QKeyEvent *event);

    /**
      * TODO: Bind in-game background parallax-scroller to this
      */
    void drawBackground(QPainter *painter, const QRectF &rect);

    /**
      * Used to draw HUD, TODO: implementation
      */
    void drawForeground(QPainter *painter, const QRectF &rect);

    /**
      * Loads level from target location.
      */
    void loadMap(QString target);

    /**
      * Unloads map, releasing its resources from memory
      */
    void unloadMap();

    /**
      * Build wall objects
      * @param &rect holds size of wall
      * @param &pos holds position of wall
      */
    void addBlock(const QRectF &rect, const QPointF &pos, QGraphicsPixmapItem* tile);

    /**
      * calls addWall(const QRectF &rect, const QPointF &pos);
      * used as convenience method
      */
    void addBlock(qreal w, qreal h, qreal x, qreal y, QGraphicsPixmapItem* tile);

    /**
      * Builds walls that surround the level.
      * @param &v1
      * @param &v2
      */
    void addEdge(const b2Vec2 &v1, const b2Vec2 &v2);

private:

    b2World* m_world;

    Tiled::Map *m_map;
    Tiled::MapReader *m_mapReader;
    Tiled::OrthogonalRenderer *m_mapRenderer;

    //! Level name used for records.
    QString m_levelName;

    //! Levelscore used for records.
    int m_levelScore;

    //! Map layers are drawn to these pixmaps
    QVector<QPixmap> m_mapPixmaps;

    //! Items for map layers
    QVector<QGraphicsPixmapItem*> m_mapPixmapItems;

    //! What portion of the map to draw
    QSize m_mapWindow;

    //! Background pixmap
    QPixmap m_bgPixmap;
    QGraphicsPixmapItem *m_bgPixmapItem;

    //! What portion of the bg pixmap to draw
    QRectF m_bgWindow;

    //! Pointer for forwarding commands to main character
    Hero* m_hero;

    //! Stops graphics rendering while scene is cleared.
    bool m_clearAlert;

    //! This item contais all hud elements, rendered in drawForeground
    HeadsUpDisplay* m_hud;

signals:
    void gameOver();

public slots:
    /**
   * Removes a sprite from the scene
   */
    void removeSprite();
};

#endif // ActionScene_H