Debian Codegraph @

src/cdogs/particle.h

raw symbols SCIP
1 /*
2 C-Dogs SDL
3 A port of the legendary (and fun) action/arcade cdogs.
4 Copyright (c) 2014-2015, 2017-2019, 2021, 2024 Cong Xu
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 Redistributions of source code must retain the above copyright notice, this
11 list of conditions and the following disclaimer.
12 Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 POSSIBILITY OF SUCH DAMAGE.
27 */
28 #pragma once
29
30 #include <json/json.h>
31
32 #include "pic.h"
33 #include "thing.h"
34
35 typedef enum
36 {
37 PARTICLE_PIC,
38 PARTICLE_TEXT
39 } ParticleType;
40 ParticleType StrParticleType(const char *s);
41
42 typedef struct
43 {
44 char *Name;
45 ParticleType Type;
46 union
47 {
48 CPic Pic;
49 struct
50 {
51 char *Value;
52 color_t Mask;
53 } Text;
54 } u;
55 // -1 is infinite range
56 int RangeLow;
57 int RangeHigh;
58 float GravityFactor;
59 bool HitsWalls;
60 bool Bounces;
61 float BounceFriction;
62 bool WallBounces;
63 bool ZDarken; // darken as the particle falls to the ground
64 bool DrawBelow;
65 bool DrawAbove;
66 } ParticleClass;
67 typedef struct
68 {
69 CArray Classes; // of ParticleClass
70 CArray CustomClasses; // of ParticleClass
71 } ParticleClasses;
72 extern ParticleClasses gParticleClasses;
73
74 typedef struct
75 {
76 const ParticleClass *Class;
77 union
78 {
79 CPic Pic;
80 char *Text;
81 } u;
82 int ActorUID;
83 struct vec2 Pos;
84 float Z;
85 double Angle;
86 float DZ;
87 double Spin;
88 int Count;
89 int Range;
90 Thing thing;
91 bool isInUse;
92 } Particle;
93 extern CArray gParticles; // of Particle
94
95 typedef struct
96 {
97 const ParticleClass *Class;
98 int ActorUID;
99 struct vec2 Pos;
100 float Z;
101 struct vec2 Vel;
102 double Angle;
103 float DZ;
104 double Spin;
105 struct vec2 DrawScale;
106 color_t Mask;
107 char Text[128];
108 } AddParticle;
109
110 void ParticleClassesInit(ParticleClasses *classes, const char *filename);
111 void ParticleClassesLoadJSON(CArray *classes, json_t *root);
112 void ParticleClassesTerminate(ParticleClasses *classes);
113 void ParticleClassesClear(CArray *classes);
114 const ParticleClass *StrParticleClass(
115 const ParticleClasses *classes, const char *name);
116
117 void ParticlesInit(CArray *particles);
118 void ParticlesTerminate(CArray *particles);
119 void ParticlesUpdate(CArray *particles, const int ticks);
120
121 int ParticleAdd(CArray *particles, const AddParticle add);
122 void ParticleDestroy(CArray *particles, const int id);