VoltAir
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Groups Pages
PickupLogic.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 PICKUPLOGIC_H
18 #define PICKUPLOGIC_H
19 
20 #include <Engine/Logic.h>
21 #include <Engine/audio/SoundEffectInstance.h>
22 
23 class Actor;
24 class Body;
25 
38 class PickupLogic : public Logic {
39  Q_OBJECT
43  Q_PROPERTY(int pickupValue READ getPickupValue WRITE setPickupValue NOTIFY pickupValueChanged)
53  Q_PROPERTY(QString pickupSound READ getPickupSound WRITE setPickupSound
55 
56 public:
60  int getPickupValue() const { return mPickupValue; }
65  void setPickupValue(int value);
69  bool allowsNonPlayerPickup() const { return mAllowNonPlayerPickup; }
74  void setAllowNonPlayerPickup(bool value);
78  const QString& getPickupSound() const { return mPickupSound; }
83  void setPickupSound(const QString& value);
84 
90  Q_INVOKABLE void reset();
91 
95  virtual void init() override;
96 
97 signals:
101  void pickupValueChanged();
109  void pickupSoundChanged();
114  void collected(Actor* otherActor);
115 
116 private slots:
117  void onPickupContacted(Body* otherBody, QPointF normal);
118 
119 private:
120  int mPickupValue = 1;
121  bool mAllowNonPlayerPickup = false;
122  QString mPickupSound;
123  SoundEffectInstance mPickupSoundInstance;
124  bool mPickedUp = false;
125 };
126 Q_DECLARE_METATYPE(PickupLogic*)
127 
128 #endif // PICKUPLOGIC_H
Q_INVOKABLE void reset()
Makes actor collectable again.
void setPickupValue(int value)
Sets pickupValue.
void pickupSoundChanged()
Emitted when pickupSound changes.
Defines a behavior that, when added to an Actor, makes it "collectable".
Definition: PickupLogic.h:38
An instance of a sound effect.
Definition: SoundEffectInstance.h:36
A QObject container for a Box2D b2Body.
Definition: Body.h:57
void setPickupSound(const QString &value)
Sets pickupSound.
virtual void init() override
Checks that the PickupLogic has an actor with a Body.
bool allowsNonPlayerPickup() const
Returns allowNonPlayerPickup.
Definition: PickupLogic.h:69
int pickupValue
Number of points awarded to Actor::PlayerActor's for collection.
Definition: PickupLogic.h:43
void allowNonPlayerPickupChanged()
Emitted when allowNonPlayerPickup changes.
void setAllowNonPlayerPickup(bool value)
Sets allowNonPlayerPickup.
int getPickupValue() const
Returns pickupValue.
Definition: PickupLogic.h:60
Non-visual entities in the QML item tree that define behavior for their parent Actor.
Definition: Logic.h:31
void pickupValueChanged()
Emitted when pickupValue changes.
const QString & getPickupSound() const
Returns pickupSound.
Definition: PickupLogic.h:78
void collected(Actor *otherActor)
Emitted when actor is collected.
bool allowNonPlayerPickup
true if non-sensor Bodys whose parent Actor is not a Actor::PlayerActor can collect actor...
Definition: PickupLogic.h:49
QString pickupSound
Name of sound asset to play once upon collection.
Definition: PickupLogic.h:54
Representation of an entity within the Game scene.
Definition: Actor.h:40