VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
Level.h
1 /*
2  * Copyright (C) 2014 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LEVEL_H
18 #define LEVEL_H
19 
20 #include <QMap>
21 #include <QQuickItem>
22 #include <QSet>
23 #include <limits>
24 #include <memory>
25 #include "Actor.h"
26 
27 class ParticleLayer;
29 class b2World;
30 
48 class Level : public QQuickItem {
49  Q_OBJECT
50 
64  Q_PROPERTY(bool fillCamera READ shouldFillCamera WRITE setFillCamera NOTIFY fillCameraChanged)
68  Q_PROPERTY(QString name READ getName WRITE setName NOTIFY nameChanged)
69  // TODO: Remove this property when then QML Loader bug is fixed.
73  Q_PROPERTY(QString fileName READ getFileName WRITE setFileName NOTIFY fileNameChanged)
77  Q_PROPERTY(QPointF gravity READ getGravity WRITE setGravity NOTIFY gravityChanged)
100  Q_PROPERTY(int particleLayer READ getParticleLayer WRITE setParticleLayer
106  Q_PROPERTY(float particleAlpha READ getParticleAlpha WRITE setParticleAlpha
124  Q_PROPERTY(Actor* portal READ getPortal)
125 
126 public:
130  explicit Level();
131  virtual ~Level();
132 
136  QRectF getCameraBoundary() const { return mCameraBoundary; }
141  void setCameraBoundary(const QRectF& value);
145  bool shouldFillCamera() const { return mFillCamera; }
150  void setFillCamera(bool value);
154  const QString& getName() const { return mName; }
159  void setName(const QString& value);
163  const QString& getFileName() const { return mFileName; }
168  void setFileName(const QString& value);
172  QPointF getGravity() const { return mGravity; }
177  void setGravity(const QPointF& value);
181  int getStartingNumPickups() const { return mStartingNumPickups; }
185  QPointF getParallaxOrigin() const { return mParallaxOrigin; }
190  void setParallaxOrigin(const QPointF& value);
194  QPointF getParallaxStrength() const { return mParallaxStrength; }
199  void setParallaxStrength(const QPointF& value);
203  int getParticleLayer() const { return mParticleLayer; }
208  void setParticleLayer(int value);
212  float getParticleAlpha() { return mParticleAlpha; }
217  void setParticleAlpha(float value);
221  const QList<ParticleLayer*>& getParticleLayers() const { return mParticleLayers; }
226  void setParticleLayers(const QList<ParticleLayer*>& value);
235  return (mCompletionThreshold >= 0) ? mCompletionThreshold : mStartingNumPickups;
236  }
241  void setCompletionThreshold(int value);
245  Actor* getPortal() const { return mPortal; }
246 
252  void addActor(Actor* actor);
257  const QSet<Actor*>& getActors(Actor::ActorType type) const;
261  b2World* getWorld() const { return mWorld.get(); }
262 
263 signals:
267  void cameraBoundaryChanged();
271  void fillCameraChanged();
275  void nameChanged();
279  void fileNameChanged();
283  void gravityChanged();
287  void parallaxOriginChanged();
295  void particleLayerChanged();
299  void particleAlphaChanged();
303  void particleLayersChanged();
308 
309 protected:
313  virtual void componentComplete() override;
314 
315 private:
316  void updateParticleRendererItemZ();
317 
318  QString mName;
319  QString mFileName;
320  std::unique_ptr<b2World> mWorld;
322  int mStartingNumPickups = 0;
323  int mCompletionThreshold = -1;
324  QPointF mGravity = QPointF(0.0f, 9.8f);
325  QPointF mParallaxOrigin = QPointF(0.0f, 0.0f);
326  QPointF mParallaxStrength = QPointF(1.0f, 0.0f);
327  int mParticleLayer = 0;
328  float mParticleAlpha = 1.0f;
329  float mParticleRadius = 0.05f;
330  float mParticleDensity = 1.2f;
331  float mParticleGravityScale = 0.4f;
332  QList<ParticleLayer*> mParticleLayers;
333  ParticleRendererItem* mParticleRendererItem = nullptr;
334  QRectF mCameraBoundary = QRectF(
335  QPointF(-std::numeric_limits<float>::max(), -std::numeric_limits<float>::max()),
336  QPointF(std::numeric_limits<float>::max(), std::numeric_limits<float>::max()));
337  bool mFillCamera = false;
338  Actor* mPortal = nullptr;
339 
340  static const float PARTICLE_RENDERER_LAYER_ZBIAS;
341 };
342 Q_DECLARE_METATYPE(Level*)
343 
344 #endif // LEVEL_H
b2World * getWorld() const
Returns the physics world (b2World) owned by this Level.
Definition: Level.h:261
int particleLayer
Z-depth that the particles rendered by ParticleRendererItem should be at.
Definition: Level.h:101
Actor portal
Helper property to find the Portal for this Level.
Definition: Level.h:124
QString fileName
Path to the file that this Level was loaded from.
Definition: Level.h:73
QPointF getGravity() const
Returns gravity.
Definition: Level.h:172
void parallaxOriginChanged()
Emitted when parallaxOrigin changes.
QRectF getCameraBoundary() const
Returns cameraBoundary.
Definition: Level.h:136
void setParticleLayers(const QList< ParticleLayer * > &value)
Sets particleLayers from a QList.
int startingNumPickups
Number of Actors with PickupLogics, representing the total number of objects that can be collected in...
Definition: Level.h:82
QPointF gravity
Strength of gravity.
Definition: Level.h:77
void parallaxStrengthChanged()
Emitted when parallaxStrength changes.
bool fillCamera
true if the Camera should be fixed to the cameraBoundary, and always view the extents of that region...
Definition: Level.h:64
float getParticleAlpha()
Returns particleAlpha.
Definition: Level.h:212
void setCameraBoundary(const QRectF &value)
Sets cameraBoundary.
void setParallaxOrigin(const QPointF &value)
Sets parallaxOrigin.
void setGravity(const QPointF &value)
Sets name.
Graphic which renders LiquidFun particles as blobs with a variety of effects.
Definition: ParticleRendererItem.h:112
void setParticleAlpha(float value)
Sets particleAlpha.
void setParticleLayer(int value)
Sets particleLayer.
QPointF parallaxStrength
Amount of offset Graphics under a ParallaxTransformItem will receive.
Definition: Level.h:94
int getStartingNumPickups() const
Returns startingNumPickups.
Definition: Level.h:181
const QString & getName() const
Returns name.
Definition: Level.h:154
QQmlListProperty< ParticleLayer > getParticleLayerListProperty()
Returns particleLayers as a QML mutable list.
Actor * getPortal() const
Returns portal.
Definition: Level.h:245
void particleLayerChanged()
Emitted when particleLayer changes.
void setCompletionThreshold(int value)
Sets completionThreshold.
QRectF cameraBoundary
Rectangular region in world coordinates outside of which the Camera must not display.
Definition: Level.h:55
QPointF parallaxOrigin
Location of the parallax origin.
Definition: Level.h:88
void gravityChanged()
Emitted when gravity changes.
void setFillCamera(bool value)
Sets fillCamera.
ActorType
Different categories of Actors, used to differentiate among them.
Definition: Actor.h:49
const QString & getFileName() const
Returns fileName.
Definition: Level.h:163
QQmlListProperty< ParticleLayer > particleLayers
QML mutable list of ParticleLayers, each representing a physically independent layer of LiquidFun par...
Definition: Level.h:114
void nameChanged()
Emitted when name changes.
void setName(const QString &value)
Sets name.
Representation of an in-game level.
Definition: Level.h:48
void particleLayersChanged()
Emitted when particleLayers changes.
const QList< ParticleLayer * > & getParticleLayers() const
Returns particleLayers as a QList.
Definition: Level.h:221
void completionThresholdChanged()
Emitted when completionThreshold changes.
QPointF getParallaxOrigin() const
Returns parallaxOrigin.
Definition: Level.h:185
void fillCameraChanged()
Emitted when fillCamera changes.
int completionThreshold
Points threshold for which the level can be considered "complete".
Definition: Level.h:120
virtual void componentComplete() override
Post-initialization of the Level after all child Actors have been created and set.
const QSet< Actor * > & getActors(Actor::ActorType type) const
Returns the set of actors in the level scene graph of the specified type.
void setParallaxStrength(const QPointF &value)
Sets parallaxStrength.
QString name
Name of this Level.
Definition: Level.h:68
Representation of an entity within the Game scene.
Definition: Actor.h:40
void fileNameChanged()
Emitted when fileName changes.
void addActor(Actor *actor)
Dynamically inserts the specified actor into the level-based scene graph, assuming it does not alread...
int getCompletionThreshold() const
Returns completionThreshold.
Definition: Level.h:234
void setFileName(const QString &value)
Sets fileName.
void cameraBoundaryChanged()
Emitted when cameraBoundary changes.
Wrapper around a b2ParticleSystem, which represents an independent layer of particles.
Definition: ParticleLayer.h:32
bool shouldFillCamera() const
Returns fillCamera.
Definition: Level.h:145
float particleAlpha
Overall transparency of the particles rendered by ParticleRendererItem, with 0.0f being completely tr...
Definition: Level.h:107
void particleAlphaChanged()
Emitted when particleAlpha changes.
QPointF getParallaxStrength() const
Returns parallaxStrength.
Definition: Level.h:194
int getParticleLayer() const
Returns particleLayer.
Definition: Level.h:203