summaryrefslogtreecommitdiffstats
path: root/mazescene.h
diff options
context:
space:
mode:
Diffstat (limited to 'mazescene.h')
-rw-r--r--mazescene.h70
1 files changed, 68 insertions, 2 deletions
diff --git a/mazescene.h b/mazescene.h
index f310082..46a850e 100644
--- a/mazescene.h
+++ b/mazescene.h
@@ -1,11 +1,15 @@
#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsView>
+#include <QLineEdit>
+#include <QPlainTextEdit>
#include <QPointF>
#include <QPushButton>
#include <QTime>
#include <QTimeLine>
+#include <QScriptEngine>
+
class MazeScene;
class View : public QGraphicsView
@@ -59,14 +63,43 @@ private:
int m_type;
};
-class Entity : public ProjectedItem
+class Entity : public QObject, public ProjectedItem
{
+ Q_OBJECT
public:
Entity(const QPointF &pos);
void updateTransform(const QPointF &cameraPos, qreal cameraRotation, qreal time);
+ QPointF pos() const { return m_pos; }
+
+ bool move(MazeScene *scene);
+
+public slots:
+ void turnTowards(qreal x, qreal y);
+ void turnLeft();
+ void turnRight();
+ void walk();
+ void stop();
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+private:
+ void updateImage();
+
private:
QPointF m_pos;
+ qreal m_angle;
+ bool m_walking;
+ bool m_walked;
+
+ qreal m_turnVelocity;
+ QPointF m_turnTarget;
+
+ bool m_useTurnTarget;
+
+ int m_animationIndex;
+ int m_angleIndex;
};
class MazeScene : public QGraphicsScene
@@ -79,6 +112,10 @@ public:
void addWall(const QPointF &a, const QPointF &b, int type);
void drawBackground(QPainter *painter, const QRectF &rect);
+ bool tryMove(QPointF &pos, const QPointF &delta, Entity *entity = 0) const;
+
+ QPointF cameraPosition() { return m_cameraPos; }
+
protected:
void keyPressEvent(QKeyEvent *event);
void keyReleaseEvent(QKeyEvent *event);
@@ -94,6 +131,9 @@ private slots:
void moveDoors(qreal value);
private:
+ bool blocked(const QPointF &pos, Entity *entity) const;
+ void updateTransforms();
+
QVector<WallItem *> m_walls;
QVector<WallItem *> m_doors;
QVector<QGraphicsItem *> m_floorTiles;
@@ -103,13 +143,39 @@ private:
QPointF m_cameraPos;
qreal m_cameraAngle;
qreal m_walkingVelocity;
+ qreal m_strafingVelocity;
qreal m_turningVelocity;
QTime m_time;
QTimeLine *m_doorAnimation;
long m_simulationTime;
long m_walkTime;
- bool m_dirty;
int m_width;
int m_height;
};
+
+class ScriptWidget : public QWidget
+{
+ Q_OBJECT
+public:
+ ScriptWidget(MazeScene *scene, Entity *entity);
+
+public slots:
+ void display(QScriptValue value);
+
+private slots:
+ void updateSource();
+ void setPreset(int preset);
+
+protected:
+ void timerEvent(QTimerEvent *event);
+
+private:
+ MazeScene *m_scene;
+ Entity *m_entity;
+ QScriptEngine *m_engine;
+ QPlainTextEdit *m_sourceEdit;
+ QLineEdit *m_statusView;
+ QString m_source;
+ QTime m_time;
+};