aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ActionScene.cpp135
-rw-r--r--src/ActionScene.h4
-rw-r--r--src/BarDisplay.cpp4
-rw-r--r--src/BarDisplay.h2
-rw-r--r--src/CircularDisplay.cpp21
-rw-r--r--src/CircularDisplay.h2
-rw-r--r--src/GameView.cpp2
-rw-r--r--src/src.pro3
8 files changed, 122 insertions, 51 deletions
diff --git a/src/ActionScene.cpp b/src/ActionScene.cpp
index 8799e3e..cdf1602 100644
--- a/src/ActionScene.cpp
+++ b/src/ActionScene.cpp
@@ -24,6 +24,7 @@
#include "objectgroup.h"
#include "mapobject.h"
#include "tile.h"
+#include "tilelayer.h"
#include "ActionScene.h"
@@ -33,17 +34,23 @@ using Tiled::OrthogonalRenderer;
using Tiled::Layer;
using Tiled::ObjectGroup;
using Tiled::Tile;
+using Tiled::TileLayer;
ActionScene::ActionScene(const QString &name, const QRectF &rect, GameView *parent)
: GameScene(name, parent)
{
setSceneRect(rect);
m_clearAlert = false;
- m_mapReader = new MapReader;
+ m_mapReader = new Tiled::MapReader;
m_map = 0;
m_mapRenderer = 0;
+ // start setting up the world here
+ //b2Vec2 gravity(0.0f, -10.0f);
+ //m_physicalWorld = new b2World(gravity);
+ //m_physicalWorld->SetAllowSleeping(true);
+
// initialize rand here
qsrand(QTime::currentTime().msec());
// TODO: implement some logic to randomize color bubbles given to player
@@ -59,7 +66,10 @@ ActionScene::~ActionScene()
if (m_mapReader)
delete m_mapReader;
if (m_mapRenderer)
- delete m_mapRenderer;
+ delete m_mapRenderer;
+
+ if(m_physicalWorld)
+ ;//delete m_physicalWorld;
}
void ActionScene::updateLogic()
@@ -103,6 +113,11 @@ void ActionScene::keyPressEvent(QKeyEvent *event)
}
}
+void ActionScene::drawBackground(QPainter *painter, const QRectF &rect)
+{
+
+}
+
void ActionScene::drawForeground(QPainter *painter, const QRectF &rect)
{
@@ -124,69 +139,103 @@ void ActionScene::loadMap(QString target)
return;
}
- m_mapRenderer = new OrthogonalRenderer(m_map);
+ m_mapRenderer = new Tiled::OrthogonalRenderer(m_map);
qDebug() << "size" << m_map->width() << "x" << m_map->height();
qDebug() << "layers" << m_map->layerCount();
for(int layer = 0; layer < m_map->layerCount(); layer++)
{
- QImage img(m_map->width() * m_map->tileWidth(),
- m_map->height() * m_map->tileHeight(),
- QImage::Format_ARGB32);
-
- QPainter painter(&img);
- m_mapRenderer->drawTileLayer(&painter, m_map->layerAt(layer)->asTileLayer());
-
- QPixmap mapPixmap = QPixmap::fromImage(img);
- m_mapPixmaps.append(mapPixmap);
-
- qDebug() << "hasAlpha" << mapPixmap.hasAlpha() << "\n"
- << "hasAlphaChannel" << mapPixmap.hasAlphaChannel();
-
- QGraphicsPixmapItem* mapPixmapItem = addPixmap(mapPixmap);
- mapPixmapItem->setPos(0, 0);
- mapPixmapItem->setShapeMode(QGraphicsPixmapItem::MaskShape);
-
QString type = m_map->layerAt(layer)->property("type");
if (type == "solid")
{
- mapPixmapItem->setData(ITEM_OBJECTNAME, QString("SolidGround"));
- mapPixmapItem->setZValue(1);
+ Tiled::TileLayer* solidTiles = NULL;
+ solidTiles = m_map->layerAt(layer)->asTileLayer();
+
+ for(int w = 0; w < solidTiles->width(); w++)
+ {
+ for (int h = 0; h < solidTiles->height(); h++)
+ {
+ Tiled::Cell cell;
+ cell = solidTiles->cellAt(w, h);
+
+ if(!cell.isEmpty())
+ {
+ QGraphicsPixmapItem *solidTile = new QGraphicsPixmapItem(0, this);
+ solidTile->setData(ITEM_OBJECTNAME, QString("SolidGround"));
+ solidTile->setPos(w * m_map->tileWidth(),
+ h * m_map->tileHeight());
+ solidTile->setZValue(1);
+ solidTile->setPixmap(cell.tile->image());
+ m_mapPixmapItems.append(solidTile);
+ }
+ }
+ }
}
- else if (type == "covering")
+ else
{
- mapPixmapItem->setData(ITEM_OBJECTNAME, QString("Covering"));
- mapPixmapItem->setZValue(2);
- }
+ QImage img(m_map->width() * m_map->tileWidth(),
+ m_map->height() * m_map->tileHeight(),
+ QImage::Format_ARGB32);
- mapPixmapItem->setPixmap(mapPixmap);
+ QPainter painter(&img);
+ m_mapRenderer->drawTileLayer(&painter, m_map->layerAt(layer)->asTileLayer());
- m_mapPixmapItems.append(mapPixmapItem);
- }
+ QPixmap mapPixmap = QPixmap::fromImage(img);
+ m_mapPixmaps.append(mapPixmap);
- ObjectGroup* fish = NULL;
+ qDebug() << "hasAlpha" << mapPixmap.hasAlpha() << "\n"
+ << "hasAlphaChannel" << mapPixmap.hasAlphaChannel();
- if(m_map->indexOfLayer("fish") >= 0)
- fish = m_map->layerAt(m_map->indexOfLayer("fish"))->asObjectGroup();
+ QGraphicsPixmapItem* mapPixmapItem = addPixmap(mapPixmap);
+ mapPixmapItem->setPos(0, 0);
+ mapPixmapItem->setShapeMode(QGraphicsPixmapItem::MaskShape);
- if(fish)
- {
- Q_FOREACH(Tiled::MapObject *obj, fish->objects())
- {
- Collectible *fish = new Collectible(0, this);
- fish->setData(ITEM_OBJECTNAME, QString("fish"));
- connect(fish, SIGNAL(removeMe()), this, SLOT(removeSprite()));
+ mapPixmapItem->setPixmap(mapPixmap);
+
+ if (type == "covering")
+ {
+ mapPixmapItem->setData(ITEM_OBJECTNAME, QString("Covering"));
+ mapPixmapItem->setZValue(2);
+ }
+ else if (type == "coveringBg")
+ {
+ mapPixmapItem->setData(ITEM_OBJECTNAME, QString("CoveringBg"));
+ mapPixmapItem->setZValue(-1);
+ }
+
+ m_mapPixmapItems.append(mapPixmapItem);
+ }
+ }
+
+ QVector<QString> colors;
+ colors.append("red"); colors.append("blue"); colors.append("green");
- fish->setPos((obj->x()) * m_map->tileWidth(),
- (obj->y() - 1) * m_map->tileHeight());
+ for (int i = 0; i < colors.size(); i++)
+ {
+ Tiled::ObjectGroup* color = NULL;
- fish->setZValue(2);
+ if(m_map->indexOfLayer(colors.at(i)) >= 0)
+ color = m_map->layerAt(m_map->indexOfLayer(colors.at(i)))->asObjectGroup();
- qDebug() << obj->position() << fish->pos();
+ if(color)
+ {
+ Q_FOREACH(Tiled::MapObject *obj, color->objects())
+ {
+ Collectible* colorbubble = new Collectible(0, this);
+ colorbubble->setData(ITEM_OBJECTNAME, QString(colors.at(i)));
+ connect(colorbubble, SIGNAL(removeMe()), this, SLOT(removeSprite()));
+ colorbubble->setPos((obj->x()) * m_map->tileWidth(),
+ (obj->y() - 1) * m_map->tileHeight());
+
+ colorbubble->setZValue(1);
+
+ qDebug() << obj->position() << colorbubble->pos();
+ }
}
}
+
m_clearAlert = false;
}
diff --git a/src/ActionScene.h b/src/ActionScene.h
index 6daa42a..bd40976 100644
--- a/src/ActionScene.h
+++ b/src/ActionScene.h
@@ -15,6 +15,8 @@
class QGraphicsPixmapItem;
class Hero;
+class b2World;
+
class ActionScene : public GameScene
{
Q_OBJECT
@@ -48,6 +50,8 @@ public:
private:
+ b2World* m_physicalWorld;
+
Tiled::Map *m_map;
Tiled::MapReader *m_mapReader;
Tiled::OrthogonalRenderer *m_mapRenderer;
diff --git a/src/BarDisplay.cpp b/src/BarDisplay.cpp
index db6136d..4b27b55 100644
--- a/src/BarDisplay.cpp
+++ b/src/BarDisplay.cpp
@@ -1,7 +1,7 @@
#include "BarDisplay.h"
-BarDisplay::BarDisplay() :
- QPixmap()
+BarDisplay::BarDisplay(int w, int h) :
+ QPixmap(w, h)
{
m_partCount = 4;
m_maxValue = 50;
diff --git a/src/BarDisplay.h b/src/BarDisplay.h
index c08f9c2..a06b9ef 100644
--- a/src/BarDisplay.h
+++ b/src/BarDisplay.h
@@ -6,7 +6,7 @@
class BarDisplay : public QPixmap
{
public:
- BarDisplay();
+ BarDisplay(int w = 250, int h = 40);
virtual ~BarDisplay();
void collected(int);
diff --git a/src/CircularDisplay.cpp b/src/CircularDisplay.cpp
index 2c723c3..438ebc0 100644
--- a/src/CircularDisplay.cpp
+++ b/src/CircularDisplay.cpp
@@ -1,7 +1,8 @@
+#include <QPainter>
#include "CircularDisplay.h"
-CircularDisplay::CircularDisplay() :
- QPixmap()
+CircularDisplay::CircularDisplay(int w, int h) :
+ QPixmap(w, h)
{
m_partCount = 5;
m_maxValue = 50;
@@ -9,6 +10,22 @@ CircularDisplay::CircularDisplay() :
m_value = 10;
m_activated = false;
+ fill(QColor(Qt::transparent));
+
+ QPainter p(this);
+ QPen pen(QColor(0, 0, 0, 255));
+ p.setPen(pen);
+
+ // draw base ellipse
+ p.drawEllipse(45, 45, 35, 35);
+
+ // draw "tick" lines
+ p.drawLine(45, 10, 45, 0); // 12 o'clock
+ p.drawLine(62.5, 27.5, 70, 20); // 1.5 o'clock
+ p.drawLine(80, 45, 90, 45); // 3 o'clock
+ p.drawLine(62.5, 62.5, 70, 70); // 4.5 o'clock
+ p.drawLine(45, 80, 80, 90); // 6 o'clock
+
/* TODO:
initialize this item with some kind of rounds graphics
that supports partitioning
diff --git a/src/CircularDisplay.h b/src/CircularDisplay.h
index 557ef14..a82d53b 100644
--- a/src/CircularDisplay.h
+++ b/src/CircularDisplay.h
@@ -6,7 +6,7 @@
class CircularDisplay : public QPixmap
{
public:
- CircularDisplay();
+ CircularDisplay(int w = 90, int h = 90);
virtual ~CircularDisplay();
void setDisplayColor(QColor col);
diff --git a/src/GameView.cpp b/src/GameView.cpp
index 3ba2631..d518f1f 100644
--- a/src/GameView.cpp
+++ b/src/GameView.cpp
@@ -39,7 +39,7 @@ GameView::GameView(QWidget *parent) :
m_gameTimer = new QTimer(this);
connect(m_gameTimer, SIGNAL(timeout()), this, SLOT(updateSceneLogic()));
- showScene(menuScene);
+ showScene(levelSelectionScene);
}
GameView *GameView::instance()
diff --git a/src/src.pro b/src/src.pro
index 397b1bc..bee809d 100644
--- a/src/src.pro
+++ b/src/src.pro
@@ -9,11 +9,12 @@ TEMPLATE = app
TARGET = prism
DEPENDPATH += .
INCLUDEPATH += . ../libtiled
+INCLUDEPATH += $${PWD}/../Box2D $${PWD}/..
INSTALLS += target
target.path = $${BINDIR}
unix:DESTDIR = ../bin
unix:LIBS += -L../lib -L/usr/local/lib -L/usr/lib -ltiled
-win32:LIBS += G:/Projects/Qt/platformer/platformer-build-desktop/lib/tiled.dll
+win32:LIBS += G:/Projects/Qt/prism/prism-build-desktop/lib/tiled.dll
OBJECTS_DIR = .obj