Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarParticle.hpp
blob: e3ab1ce361f63e57a6b18fe5858d9c2f78e876fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#pragma once

#include "StarJson.hpp"
#include "StarColor.hpp"
#include "StarBiMap.hpp"
#include "StarAnimation.hpp"
#include "StarAssetPath.hpp"

namespace Star {

struct Particle {
  enum class Type {
    // Variance is basically a null type, used only for varying other particles
    // by amounts.
    Variance,

    Ember,
    Textured,
    Animated,
    Streak,
    Text
  };
  static EnumMap<Type> const TypeNames;

  enum class DestructionAction {
    None,
    Image,
    Fade,
    Shrink
  };
  static EnumMap<DestructionAction> const DestructionActionNames;

  enum class Layer {
    Back,
    Middle,
    Front
  };
  static EnumMap<Layer> const LayerNames;

  Particle();
  // If particle is type Textured, then the image name is considered relative
  // to the given asset path
  explicit Particle(Json const& config, String const& assetsPath = "/");

  Json toJson() const;

  void translate(Vec2F const& pos);

  // Updates position, velocity, rotation, and timeToLive.
  void update(float dt, Vec2F const& wind = Vec2F());

  bool dead() const;

  // Apply random variance to this particle based on a "variance" particle that
  // contains the maximum amount of variance for each field.
  void applyVariance(Particle const& variance);

  // Stops particle and sets time to live to 0.0 (triggering destruction)
  void collide(Vec2F const& collisionPosition);
  // Immediately triggers destruction of particle with / without destruction
  // action
  void destroy(bool withDestruction);

  // Internally called by update() / collide() / destruct()
  void destructionUpdate();

  void initializeAnimation();

  Type type;

  // Defaults to 1.0, 1.0 will produce a reasonable size particle for whatever
  // the type is.
  float size;
  float baseSize; // track the original size for shrink destruction action

  // Used differently depending on the type of the particle.
  String string;
  AssetPath image;
  DirectivesGroup directives;

  Color color;
  Color light;
  float fade;
  bool fullbright;

  Vec2F position;
  Vec2F velocity;
  Vec2F finalVelocity;
  Vec2F approach;

  bool flippable;
  bool flip;

  float rotation;
  float angularVelocity;

  float length;

  DestructionAction destructionAction;
  AssetPath destructionImage;
  float destructionTime;
  bool destructionSet;

  float timeToLive;
  Layer layer;

  bool collidesForeground;
  bool collidesLiquid;
  bool underwaterOnly;

  bool ignoreWind;

  bool trail;

  Maybe<Animation> animation;
};

DataStream& operator<<(DataStream& ds, Particle const& particle);
DataStream& operator>>(DataStream& ds, Particle& particle);

typedef function<Particle()> ParticleVariantCreator;
ParticleVariantCreator makeParticleVariantCreator(Particle particle, Particle variance);

}