diff options
| author | Samu Laaksonen <laaksonen.sj@gmail.com> | 2012-12-10 23:47:03 +0200 |
|---|---|---|
| committer | Samu Laaksonen <laaksonen.sj@gmail.com> | 2012-12-10 23:47:03 +0200 |
| commit | ad19e537066742e1a5f9bbb8c3549a47480a33c1 (patch) | |
| tree | 2f48c08f22bea31756f784495d3c50cd9736e889 /src/ActionScene.h | |
| parent | 9674c5ea91912d07f4726140ca2c88669c03f874 (diff) | |
| download | prism-ad19e537066742e1a5f9bbb8c3549a47480a33c1.tar.gz prism-ad19e537066742e1a5f9bbb8c3549a47480a33c1.zip | |
Box2d integration
Very crude and buggy
Needs to be much better
Diffstat (limited to 'src/ActionScene.h')
| -rw-r--r-- | src/ActionScene.h | 226 |
1 files changed, 123 insertions, 103 deletions
diff --git a/src/ActionScene.h b/src/ActionScene.h index 6460523..fa503a4 100644 --- a/src/ActionScene.h +++ b/src/ActionScene.h @@ -1,103 +1,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.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(); - -private: - - b2World* m_physicalWorld; - - 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 +#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
|
